feat(dialog): persist global sort option (#2039)

Add dialog_sort_name field to State to track the dialog sort option.
Add state_handler and state fields to Dialog to load saved state.
Implement tab::Command::SetSort for Dialog to apply and persist sort
options.
This commit is contained in:
Huy Nguyen 2026-09-22 23:06:06 +07:00 • committed by GitHub
parent b326e48cf6
commit e2cad979ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 4 deletions

View file

@ -150,6 +150,7 @@ pub enum TypeToSearch {
#[serde(default)] #[serde(default)]
pub struct State { pub struct State {
pub sort_names: FxOrderMap<String, (HeadingOptions, bool)>, pub sort_names: FxOrderMap<String, (HeadingOptions, bool)>,
pub dialog_sort_name: (HeadingOptions, bool),
} }
impl Default for State { impl Default for State {
@ -161,6 +162,7 @@ impl Default for State {
(HeadingOptions::Modified, false), (HeadingOptions::Modified, false),
) )
})), })),
dialog_sort_name: (HeadingOptions::Modified, false),
} }
} }
} }

View file

@ -3,6 +3,7 @@
use cosmic::app::cosmic::Cosmic; use cosmic::app::cosmic::Cosmic;
use cosmic::app::{Core, Task, context_drawer}; use cosmic::app::{Core, Task, context_drawer};
use cosmic::cosmic_config::ConfigSet;
use cosmic::iced::core::SmolStr; use cosmic::iced::core::SmolStr;
use cosmic::iced::core::widget::operation; use cosmic::iced::core::widget::operation;
use cosmic::iced::futures::{self, SinkExt}; use cosmic::iced::futures::{self, SinkExt};
@ -32,11 +33,13 @@ use std::{env, fmt, fs};
use crate::app::{ use crate::app::{
Action, ContextPage, Message as AppMessage, PreviewItem, PreviewKind, REPLACE_BUTTON_ID, Action, ContextPage, Message as AppMessage, PreviewItem, PreviewKind, REPLACE_BUTTON_ID,
}; };
use crate::config::{Config, DialogConfig, TIME_CONFIG_ID, ThumbCfg, TimeConfig, TypeToSearch}; use crate::config::{
Config, DialogConfig, State, TIME_CONFIG_ID, ThumbCfg, TimeConfig, TypeToSearch,
};
use crate::key_bind::key_binds; use crate::key_bind::key_binds;
use crate::localize::LANGUAGE_SORTER; use crate::localize::LANGUAGE_SORTER;
use crate::mounter::{MOUNTERS, MounterItem, MounterItems, MounterKey, MounterMessage}; use crate::mounter::{MOUNTERS, MounterItem, MounterItems, MounterKey, MounterMessage};
use crate::tab::{self, ItemMetadata, Location, SearchLocation, Tab}; use crate::tab::{self, HeadingOptions, ItemMetadata, Location, SearchLocation, Tab};
use crate::zoom::{zoom_in_view, zoom_out_view, zoom_to_default}; use crate::zoom::{zoom_in_view, zoom_out_view, zoom_to_default};
use crate::{fl, home_dir, menu, mime_icon}; use crate::{fl, home_dir, menu, mime_icon};
@ -251,6 +254,7 @@ impl<M: Send + 'static> Dialog<M> {
crate::localize::localize(); crate::localize::localize();
let (config_handler, config) = Config::load(); let (config_handler, config) = Config::load();
let (state_handler, state) = State::load();
let mut settings = window::Settings { let mut settings = window::Settings {
decorations: false, decorations: false,
@ -285,6 +289,8 @@ impl<M: Send + 'static> Dialog<M> {
window_id, window_id,
config_handler, config_handler,
config, config,
state_handler,
state,
}; };
let (cosmic, cosmic_command) = Cosmic::<App>::init((core, flags)); let (cosmic, cosmic_command) = Cosmic::<App>::init((core, flags));
@ -439,6 +445,8 @@ struct Flags {
#[allow(dead_code)] #[allow(dead_code)]
config_handler: Option<cosmic_config::Config>, config_handler: Option<cosmic_config::Config>,
config: Config, config: Config,
state_handler: Option<cosmic_config::Config>,
state: State,
} }
/// Messages that are used specifically by our [`App`]. /// Messages that are used specifically by our [`App`].
@ -1027,8 +1035,7 @@ impl Application for App {
None, None,
); );
tab.mode = tab::Mode::Dialog(flags.kind.clone()); tab.mode = tab::Mode::Dialog(flags.kind.clone());
tab.sort_name = tab::HeadingOptions::Modified; (tab.sort_name, tab.sort_direction) = flags.state.dialog_sort_name;
tab.sort_direction = false;
let key_binds = key_binds(&tab.mode); let key_binds = key_binds(&tab.mode);
@ -1786,6 +1793,17 @@ impl Application for App {
self.auto_scroll_speed = None; self.auto_scroll_speed = None;
} }
} }
tab::Command::SetSort(_, heading_options, direction) => {
self.flags.state.dialog_sort_name = (heading_options, direction);
if let Some(state_handler) = self.flags.state_handler.as_ref()
&& let Err(err) = state_handler.set::<&(HeadingOptions, bool)>(
"dialog_sort_name",
&self.flags.state.dialog_sort_name,
)
{
log::warn!("Failed to save dialog sort name: {err:?}");
}
}
unsupported => { unsupported => {
log::warn!("{unsupported:?} not supported in dialog mode"); log::warn!("{unsupported:?} not supported in dialog mode");
} }