From 4f0c5c1ec14d969c07bbee963f69a52fcde60154 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 21 Jul 2025 19:50:28 -0600 Subject: [PATCH] dialog: preserve show details setting --- src/config.rs | 14 ++++++++++++++ src/dialog.rs | 50 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 14dc2d0..d0b5741 100644 --- a/src/config.rs +++ b/src/config.rs @@ -164,6 +164,7 @@ impl State { #[serde(default)] pub struct Config { pub app_theme: AppTheme, + pub dialog: DialogConfig, pub desktop: DesktopConfig, pub favorites: Vec, pub show_details: bool, @@ -206,6 +207,7 @@ impl Default for Config { Self { app_theme: AppTheme::System, desktop: DesktopConfig::default(), + dialog: DialogConfig::default(), favorites: vec![ Favorite::Home, Favorite::Documents, @@ -249,6 +251,18 @@ impl DesktopConfig { } } +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, CosmicConfigEntry, Deserialize, Serialize)] +#[serde(default)] +pub struct DialogConfig { + pub show_details: bool, +} + +impl Default for DialogConfig { + fn default() -> Self { + Self { show_details: true } + } +} + /// Global and local [`crate::tab::Tab`] config. /// /// [`TabConfig`] contains options that are passed to each instance of [`crate::tab::Tab`]. diff --git a/src/dialog.rs b/src/dialog.rs index 2bca885..89b25ec 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -734,6 +734,8 @@ impl App { } fn update_config(&mut self) -> Task { + self.core.window.show_context = self.flags.config.dialog.show_details; + self.update_nav_model(); self.update(Message::TabMessage(tab::Message::Config( @@ -1240,6 +1242,33 @@ impl Application for App { /// Handle application events here. fn update(&mut self, message: Message) -> Task { + // Helper for updating config values efficiently + macro_rules! config_set { + ($name: ident, $value: expr) => { + match &self.flags.config_handler { + Some(config_handler) => { + match paste::paste! { self.flags.config.[](config_handler, $value) } { + Ok(_) => {} + Err(err) => { + log::warn!( + "failed to save config {:?}: {}", + stringify!($name), + err + ); + } + } + } + None => { + self.flags.config.$name = $value; + log::warn!( + "failed to save config {:?}: no config handler", + stringify!($name) + ); + } + } + }; + } + match message { Message::None => {} Message::Cancel => { @@ -1506,15 +1535,13 @@ impl Application for App { } } } - Message::Preview => match self.context_page { - ContextPage::Preview(..) => { - self.core.window.show_context = !self.core.window.show_context; - } - _ => { - self.context_page = ContextPage::Preview(None, PreviewKind::Selected); - self.core.window.show_context = true; - } - }, + Message::Preview => { + self.context_page = ContextPage::Preview(None, PreviewKind::Selected); + let mut new_dialog = self.flags.config.dialog; + new_dialog.show_details = !new_dialog.show_details; + config_set!(dialog, new_dialog); + return self.update_config(); + } Message::Save(replace) => { if let DialogKind::SaveFile { filename } = &self.flags.kind { if !filename.is_empty() { @@ -1600,7 +1627,10 @@ impl Application for App { } tab::Command::Preview(kind) => { self.context_page = ContextPage::Preview(None, kind); - self.set_show_context(true); + let mut new_dialog = self.flags.config.dialog; + new_dialog.show_details = true; + config_set!(dialog, new_dialog); + commands.push(self.update_config()); } tab::Command::WindowDrag => { commands.push(window::drag(self.flags.window_id));