feat(ui): ribbon collapse-mode selector + start-page recent controls

Ribbon:
- A ▾ selector at the right of the tab row picks the tool-panel density —
  Auto (size to window), Full, Compact, or Collapsed. The choice is persisted.
  It hides itself when the tool row is already tight, giving the cramped tab
  row its space back.

Start page:
- The Recent Documents card is restyled to match the Supporters card
  (rounded corners, 20px padding, matching title + colours).
- Its scrollbar no longer sits on top of the row ✕ remove buttons (a gutter
  is reserved).
- A footer control sets how many recent files to keep: [-] an editable count
  [+] with the max shown. Typing applies on Enter; an over-max entry snaps to
  the max. The limit is persisted and enforced on load and on every open.
- The "Support on Patreon" heart is now the SVG icon instead of a font glyph.

Config:
- Add a shared `config::config_dir()` helper; the recent-files and status-bar
  stores now go through it instead of each re-deriving the path. New minus.svg
  icon for the stepper.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-06 01:06:01 +03:00
commit f4ed263425
13 changed files with 457 additions and 112 deletions

View file

@ -6,12 +6,17 @@
use super::OpenCADStudio;
use std::path::{Path, PathBuf};
/// Bounds and default for how many recent files are kept.
pub(super) const RECENT_MIN: usize = 5;
pub(super) const RECENT_MAX: usize = 100;
const RECENT_DEFAULT: usize = 20;
impl OpenCADStudio {
/// Record a freshly opened file at the top of the recents list.
pub(super) fn push_recent(&mut self, path: PathBuf) {
self.recent_files.retain(|r| r != &path);
self.recent_files.insert(0, path);
self.recent_files.truncate(20);
self.recent_files.truncate(self.recent_limit);
// Best-effort persist; silent on failure (read-only home, full disk).
let _ = save_recents(&self.recent_files);
}
@ -21,9 +26,19 @@ impl OpenCADStudio {
self.recent_files.retain(|r| r.as_path() != path);
let _ = save_recents(&self.recent_files);
}
/// Set how many recent files are kept, trim the current list to fit, and
/// persist both the new limit and the trimmed list.
pub(super) fn set_recent_limit(&mut self, limit: usize) {
self.recent_limit = limit.clamp(RECENT_MIN, RECENT_MAX);
self.recent_files.truncate(self.recent_limit);
save_recent_limit(self.recent_limit);
let _ = save_recents(&self.recent_files);
}
}
/// Rehydrate the recents list from disk. Call once at app boot.
/// Rehydrate the recents list from disk, trimmed to the saved limit. Call once
/// at app boot.
pub(super) fn load_recent_files() -> Vec<PathBuf> {
let Some(path) = recents_file_path() else {
return vec![];
@ -31,32 +46,38 @@ pub(super) fn load_recent_files() -> Vec<PathBuf> {
let Ok(body) = std::fs::read_to_string(path) else {
return vec![];
};
body.lines()
let mut list: Vec<PathBuf> = body
.lines()
.filter(|l| !l.trim().is_empty())
.map(PathBuf::from)
.collect()
.collect();
list.truncate(load_recent_limit());
list
}
/// Load the saved recent-file limit (clamped), defaulting to `RECENT_DEFAULT`.
pub(super) fn load_recent_limit() -> usize {
limit_file_path()
.and_then(|p| std::fs::read_to_string(p).ok())
.and_then(|s| s.trim().parse::<usize>().ok())
.map(|n| n.clamp(RECENT_MIN, RECENT_MAX))
.unwrap_or(RECENT_DEFAULT)
}
fn save_recent_limit(limit: usize) {
let Some(path) = limit_file_path() else { return };
if let Some(dir) = path.parent() {
let _ = std::fs::create_dir_all(dir);
}
let _ = std::fs::write(path, limit.to_string());
}
fn recents_file_path() -> Option<PathBuf> {
let base: PathBuf = if cfg!(target_os = "windows") {
std::env::var_os("APPDATA").map(PathBuf::from)?
} else if cfg!(target_os = "macos") {
let home = std::env::var_os("HOME")?;
let mut p = PathBuf::from(home);
p.push("Library");
p.push("Application Support");
p
} else if let Some(d) = std::env::var_os("XDG_CONFIG_HOME") {
PathBuf::from(d)
} else {
let home = std::env::var_os("HOME")?;
let mut p = PathBuf::from(home);
p.push(".config");
p
};
let mut p = base;
p.push("OpenCADStudio");
Some(p.join("recent.txt"))
Some(crate::config::config_dir()?.join("recent.txt"))
}
fn limit_file_path() -> Option<PathBuf> {
Some(crate::config::config_dir()?.join("recent_limit.txt"))
}
fn save_recents(list: &[PathBuf]) -> std::io::Result<()> {