forked from 1b-agent/opencadstudio-upstream
refactor(config): consolidate settings into one grouped settings.json
App preferences were spread across six flat plain-text files (settings.txt,
recent.txt, recent_limit.txt, statusbar.txt, ribbon.txt, plot.txt), each with a
bespoke line parser and no grouping. Replace them with a single grouped JSON,
serialized via serde (enabling the derive feature; serde_json was already a
dependency).
- New app/config.rs: AppConfig { settings, recent, statusbar, ribbon, plot } →
<config>/settings.json (pretty JSON), load()/save().
- Make UserSettings, StatusBarConfig/StatusPill, CollapseMode and
PlotDialogState serde-derived; #[serde(skip)] marks the plot dialog's runtime
fields so only print preferences persist. Their bespoke .txt load/save is
removed.
- App gains current_config/apply_config/save_config: one AppConfig::load at
startup distributes into live state; every settings-change site
(persist_settings_if_changed, recent add/remove/limit, status-bar pill
toggle, ribbon density, plot commit) routes through save_config, which diffs
against the last write to avoid thrashing.
- Clean start: the old flat files are ignored (no migration). ocad.pgp stays a
separate hand-editable file.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
256f9a282b
commit
dc7117f203
12 files changed
+228
-411
No files matched your search
@@ -54,7 +54,9 @@ const MAX_PANEL_SQUEEZE: f32 = 8.0;
|
||||
/// How the ribbon tool panels are sized. `Auto` adapts to the window width (the
|
||||
/// step-by-step degradation); the others pin every panel to one density so the
|
||||
/// user can override the automatic choice. The selection is persisted.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
|
||||
#[derive(
|
||||
Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, serde::Deserialize,
|
||||
)]
|
||||
pub enum CollapseMode {
|
||||
/// Size panels to the window: degrade from the right as space runs out.
|
||||
#[default]
|
||||
@@ -86,19 +88,6 @@ impl CollapseMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Stable identifier used for persistence.
|
||||
fn id(self) -> &'static str {
|
||||
match self {
|
||||
CollapseMode::Auto => "auto",
|
||||
CollapseMode::Full => "full",
|
||||
CollapseMode::Compact => "compact",
|
||||
CollapseMode::Collapsed => "collapsed",
|
||||
}
|
||||
}
|
||||
|
||||
fn from_id(s: &str) -> Option<Self> {
|
||||
CollapseMode::ALL.iter().copied().find(|m| m.id() == s)
|
||||
}
|
||||
|
||||
/// The degradation level every panel is pinned to, or `None` for `Auto`.
|
||||
fn forced_level(self) -> Option<u8> {
|
||||
@@ -110,27 +99,6 @@ impl CollapseMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Load the saved mode, defaulting to `Auto`.
|
||||
pub fn load() -> Self {
|
||||
config_path()
|
||||
.and_then(|p| std::fs::read_to_string(p).ok())
|
||||
.and_then(|s| CollapseMode::from_id(s.trim()))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Persist this mode (best-effort; silent on failure).
|
||||
pub fn save(self) {
|
||||
let Some(path) = config_path() else { return };
|
||||
if let Some(dir) = path.parent() {
|
||||
let _ = std::fs::create_dir_all(dir);
|
||||
}
|
||||
let _ = std::fs::write(path, self.id());
|
||||
}
|
||||
}
|
||||
|
||||
/// `<config-dir>/OpenCADStudio/ribbon.txt`, matching the other settings stores.
|
||||
fn config_path() -> Option<std::path::PathBuf> {
|
||||
Some(crate::config::config_dir()?.join("ribbon.txt"))
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CollapseMode {
|
||||
|
||||
Reference in new issue
Block a user