dialog: preserve show details setting
This commit is contained in:
parent
5fd643b166
commit
4f0c5c1ec1
2 changed files with 54 additions and 10 deletions
|
|
@ -164,6 +164,7 @@ impl State {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub app_theme: AppTheme,
|
pub app_theme: AppTheme,
|
||||||
|
pub dialog: DialogConfig,
|
||||||
pub desktop: DesktopConfig,
|
pub desktop: DesktopConfig,
|
||||||
pub favorites: Vec<Favorite>,
|
pub favorites: Vec<Favorite>,
|
||||||
pub show_details: bool,
|
pub show_details: bool,
|
||||||
|
|
@ -206,6 +207,7 @@ impl Default for Config {
|
||||||
Self {
|
Self {
|
||||||
app_theme: AppTheme::System,
|
app_theme: AppTheme::System,
|
||||||
desktop: DesktopConfig::default(),
|
desktop: DesktopConfig::default(),
|
||||||
|
dialog: DialogConfig::default(),
|
||||||
favorites: vec![
|
favorites: vec![
|
||||||
Favorite::Home,
|
Favorite::Home,
|
||||||
Favorite::Documents,
|
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.
|
/// Global and local [`crate::tab::Tab`] config.
|
||||||
///
|
///
|
||||||
/// [`TabConfig`] contains options that are passed to each instance of [`crate::tab::Tab`].
|
/// [`TabConfig`] contains options that are passed to each instance of [`crate::tab::Tab`].
|
||||||
|
|
|
||||||
|
|
@ -734,6 +734,8 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_config(&mut self) -> Task<Message> {
|
fn update_config(&mut self) -> Task<Message> {
|
||||||
|
self.core.window.show_context = self.flags.config.dialog.show_details;
|
||||||
|
|
||||||
self.update_nav_model();
|
self.update_nav_model();
|
||||||
|
|
||||||
self.update(Message::TabMessage(tab::Message::Config(
|
self.update(Message::TabMessage(tab::Message::Config(
|
||||||
|
|
@ -1240,6 +1242,33 @@ impl Application for App {
|
||||||
|
|
||||||
/// Handle application events here.
|
/// Handle application events here.
|
||||||
fn update(&mut self, message: Message) -> Task<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
|
// 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.[<set_ $name>](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 {
|
match message {
|
||||||
Message::None => {}
|
Message::None => {}
|
||||||
Message::Cancel => {
|
Message::Cancel => {
|
||||||
|
|
@ -1506,15 +1535,13 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Preview => match self.context_page {
|
Message::Preview => {
|
||||||
ContextPage::Preview(..) => {
|
self.context_page = ContextPage::Preview(None, PreviewKind::Selected);
|
||||||
self.core.window.show_context = !self.core.window.show_context;
|
let mut new_dialog = self.flags.config.dialog;
|
||||||
}
|
new_dialog.show_details = !new_dialog.show_details;
|
||||||
_ => {
|
config_set!(dialog, new_dialog);
|
||||||
self.context_page = ContextPage::Preview(None, PreviewKind::Selected);
|
return self.update_config();
|
||||||
self.core.window.show_context = true;
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
Message::Save(replace) => {
|
Message::Save(replace) => {
|
||||||
if let DialogKind::SaveFile { filename } = &self.flags.kind {
|
if let DialogKind::SaveFile { filename } = &self.flags.kind {
|
||||||
if !filename.is_empty() {
|
if !filename.is_empty() {
|
||||||
|
|
@ -1600,7 +1627,10 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
tab::Command::Preview(kind) => {
|
tab::Command::Preview(kind) => {
|
||||||
self.context_page = ContextPage::Preview(None, 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 => {
|
tab::Command::WindowDrag => {
|
||||||
commands.push(window::drag(self.flags.window_id));
|
commands.push(window::drag(self.flags.window_id));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue