diff --git a/cosmic-settings/src/app.rs b/cosmic-settings/src/app.rs index 1b702e6..f1996fb 100644 --- a/cosmic-settings/src/app.rs +++ b/cosmic-settings/src/app.rs @@ -56,6 +56,7 @@ use std::{borrow::Cow, str::FromStr}; #[allow(clippy::module_name_repetitions)] pub struct SettingsApp { active_page: page::Entity, + active_context_page: Option, loaded_pages: BTreeSet, config: Config, core: Core, @@ -133,7 +134,7 @@ pub enum Message { DesktopInfo, Error(String), None, - OpenContextDrawer(Cow<'static, str>), + OpenContextDrawer(Entity, Cow<'static, str>), #[cfg(feature = "wayland")] OutputAdded(OutputInfo, WlOutput), #[cfg(feature = "wayland")] @@ -169,6 +170,7 @@ impl cosmic::Application for SettingsApp { fn init(core: Core, flags: Self::Flags) -> (Self, Task) { let mut app = SettingsApp { active_page: page::Entity::default(), + active_context_page: None, loaded_pages: BTreeSet::new(), config: Config::new(), core, @@ -682,13 +684,15 @@ impl cosmic::Application for SettingsApp { Message::SetTheme(t) => return set_theme(t), - Message::OpenContextDrawer(title) => { + Message::OpenContextDrawer(page, title) => { self.core.window.show_context = true; + self.active_context_page = Some(page); self.set_context_title(title.to_string()); } Message::CloseContextDrawer => { self.core.window.show_context = false; + self.active_context_page = None; } Message::Error(error) => { @@ -750,9 +754,11 @@ impl cosmic::Application for SettingsApp { fn context_drawer(&self) -> Option> { if self.core.window.show_context { - self.pages - .context_drawer(self.active_page) - .map(|e| e.map(Message::PageMessage)) + self.active_context_page.and_then(|context_page| { + self.pages + .context_drawer(context_page) + .map(|e| e.map(Message::PageMessage)) + }) } else { None } @@ -972,14 +978,12 @@ impl SettingsApp { if let Some(ref sender) = self.page_sender { for page in load { - eprintln!("loading {page:?}"); self.loaded_pages.insert(page); tasks.push(self.pages.on_enter(page, sender.clone())); } } for page in unload { - eprintln!("unloading {page:?}"); self.loaded_pages.remove(&page); self.pages.on_leave(page); } diff --git a/cosmic-settings/src/pages/bluetooth/mod.rs b/cosmic-settings/src/pages/bluetooth/mod.rs index 5be239d..d66dc8a 100644 --- a/cosmic-settings/src/pages/bluetooth/mod.rs +++ b/cosmic-settings/src/pages/bluetooth/mod.rs @@ -75,7 +75,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, sender: tokio::sync::mpsc::Sender, ) -> cosmic::Task { // TODO start stream for new device diff --git a/cosmic-settings/src/pages/desktop/appearance/mod.rs b/cosmic-settings/src/pages/desktop/appearance/mod.rs index d7ad2fb..6440ac3 100644 --- a/cosmic-settings/src/pages/desktop/appearance/mod.rs +++ b/cosmic-settings/src/pages/desktop/appearance/mod.rs @@ -34,7 +34,7 @@ use icon_themes::{IconHandles, IconThemes}; use ron::ser::PrettyConfig; use serde::Serialize; use slab::Slab; -use slotmap::SlotMap; +use slotmap::{Key, SlotMap}; use crate::app; use crate::widget::color_picker_context_view; @@ -62,6 +62,7 @@ enum ContextView { } pub struct Page { + entity: page::Entity, on_enter_handle: Option, can_reset: bool, no_custom_window_hint: bool, @@ -153,6 +154,7 @@ impl }); Self { + entity: page::Entity::null(), on_enter_handle: None, can_reset: if theme_mode.is_dark { theme_builder == ThemeBuilder::dark() @@ -423,6 +425,7 @@ impl Page { self.font_search.clear(); return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, fl!("monospace-font").into(), )); } @@ -432,6 +435,7 @@ impl Page { self.font_search.clear(); return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, fl!("interface-font").into(), )); } @@ -1070,7 +1074,10 @@ impl Page { Message::IconsAndToolkit => { self.context_view = Some(ContextView::IconsAndToolkit); - return cosmic::command::message(crate::app::Message::OpenContextDrawer("".into())); + return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, + "".into(), + )); } Message::Daytime(day_time) => { @@ -1197,7 +1204,10 @@ impl Page { ColorPickerUpdate::ToggleColorPicker => { self.context_view = Some(context_view); - cosmic::command::message(crate::app::Message::OpenContextDrawer(context_title)) + cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, + context_title, + )) } _ => Task::none(), @@ -1393,6 +1403,10 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -1430,7 +1444,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _: page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { let (task, handle) = cosmic::command::batch(vec![ diff --git a/cosmic-settings/src/pages/desktop/dock/applets.rs b/cosmic-settings/src/pages/desktop/dock/applets.rs index e3cecf0..fa92101 100644 --- a/cosmic-settings/src/pages/desktop/dock/applets.rs +++ b/cosmic-settings/src/pages/desktop/dock/applets.rs @@ -6,7 +6,7 @@ use cosmic::{ }; use cosmic_panel_config::CosmicPanelConfig; use cosmic_settings_page::{self as page, section, Section}; -use slotmap::SlotMap; +use slotmap::{Key, SlotMap}; use std::borrow::Cow; use crate::{ @@ -31,6 +31,7 @@ impl Default for Page { }); Self { inner: applets_inner::Page { + entity: page::Entity::null(), available_entries: freedesktop_desktop_entry::Iter::new( freedesktop_desktop_entry::default_paths(), ) diff --git a/cosmic-settings/src/pages/desktop/mod.rs b/cosmic-settings/src/pages/desktop/mod.rs index ca88eff..0f7282f 100644 --- a/cosmic-settings/src/pages/desktop/mod.rs +++ b/cosmic-settings/src/pages/desktop/mod.rs @@ -17,9 +17,15 @@ use cosmic_settings_page as page; #[derive(Debug)] #[allow(clippy::struct_excessive_bools)] #[derive(Default)] -pub struct Page {} +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("desktop", "video-display-symbolic").title(fl!("desktop")) } diff --git a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs index 6a308f4..d22fcc4 100644 --- a/cosmic-settings/src/pages/desktop/panel/applets_inner.rs +++ b/cosmic-settings/src/pages/desktop/panel/applets_inner.rs @@ -33,7 +33,7 @@ use crate::{app, pages}; use cosmic_panel_config::CosmicPanelConfig; use cosmic_settings_page::{self as page, section, Section}; use freedesktop_desktop_entry::DesktopEntry; -use slotmap::SlotMap; +use slotmap::{Key, SlotMap}; use tracing::error; const MIME_TYPE: &str = "text/uri-list"; @@ -51,6 +51,7 @@ const DRAG_START_DISTANCE_SQUARED: f32 = 64.0; pub static APPLET_DND_ICON_ID: Lazy = Lazy::new(window::Id::unique); pub struct Page { + pub(crate) entity: page::Entity, pub(crate) available_entries: Vec>, pub(crate) config_helper: Option, pub(crate) current_config: Option, @@ -68,6 +69,7 @@ impl Default for Page { (panel_config.name == "Panel").then_some(panel_config) }); Self { + entity: page::Entity::null(), available_entries: freedesktop_desktop_entry::Iter::new( freedesktop_desktop_entry::default_paths(), ) @@ -99,6 +101,10 @@ impl AppletsPage for Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + #[allow(clippy::too_many_lines)] fn content( &self, @@ -137,6 +143,13 @@ impl page::Page for Page { None => return None, }) } + + fn on_enter( + &mut self, + _sender: tokio::sync::mpsc::Sender, + ) -> Task { + Task::none() + } } impl page::AutoBind for Page {} @@ -425,9 +438,10 @@ impl Page { } Message::AddAppletDrawer => { self.context = Some(ContextDrawer::AddApplet); - return cosmic::command::message(app::Message::OpenContextDrawer(Cow::Owned(fl!( - "add-applet" - )))); + return cosmic::command::message(app::Message::OpenContextDrawer( + self.entity, + Cow::Owned(fl!("add-applet")), + )); } }; Task::none() diff --git a/cosmic-settings/src/pages/desktop/wallpaper/mod.rs b/cosmic-settings/src/pages/desktop/wallpaper/mod.rs index 4e3ae76..4f87a33 100644 --- a/cosmic-settings/src/pages/desktop/wallpaper/mod.rs +++ b/cosmic-settings/src/pages/desktop/wallpaper/mod.rs @@ -36,7 +36,7 @@ use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode}; use image::imageops::FilterType::Lanczos3; use image::{ImageBuffer, Rgba}; use slab::Slab; -use slotmap::{DefaultKey, SecondaryMap, SlotMap}; +use slotmap::{DefaultKey, Key, SecondaryMap, SlotMap}; const ZOOM: usize = 0; const FIT: usize = 1; @@ -137,6 +137,9 @@ enum ContextView { /// The page struct for the wallpaper view. pub struct Page { + /// Internal ID of this page in the application. + entity: page::Entity, + /// Abort handle to the on_enter task. on_enter_handle: Option, @@ -192,6 +195,10 @@ pub struct Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -207,7 +214,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { // Check if the page is already being loaded. @@ -286,6 +292,7 @@ impl page::AutoBind for Page {} impl Default for Page { fn default() -> Self { let mut page = Page { + entity: page::Entity::null(), on_enter_handle: None, context_view: None, show_tab_bar: false, @@ -747,6 +754,7 @@ impl Page { Message::ColorAddContext => { self.context_view = Some(ContextView::AddColor); return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, fl!("color-picker").into(), )); } diff --git a/cosmic-settings/src/pages/display/mod.rs b/cosmic-settings/src/pages/display/mod.rs index 30104bc..44e5c76 100644 --- a/cosmic-settings/src/pages/display/mod.rs +++ b/cosmic-settings/src/pages/display/mod.rs @@ -234,7 +234,6 @@ impl page::Page for Page { #[cfg(not(feature = "test"))] fn on_enter( &mut self, - _page: page::Entity, sender: tokio::sync::mpsc::Sender, ) -> Task { if let Some(task) = self.background_service.take() { @@ -280,7 +279,6 @@ impl page::Page for Page { #[cfg(feature = "test")] fn on_enter( &mut self, - _page: page::Entity, sender: tokio::sync::mpsc::Sender, ) -> Task { cosmic::command::future(async move { diff --git a/cosmic-settings/src/pages/input/keyboard/mod.rs b/cosmic-settings/src/pages/input/keyboard/mod.rs index 25cfc74..3e149a5 100644 --- a/cosmic-settings/src/pages/input/keyboard/mod.rs +++ b/cosmic-settings/src/pages/input/keyboard/mod.rs @@ -14,7 +14,7 @@ use cosmic_comp_config::XkbConfig; use cosmic_settings_page::{self as page, section, Section}; use itertools::Itertools; use slab::Slab; -use slotmap::{DefaultKey, SlotMap}; +use slotmap::{DefaultKey, Key, SlotMap}; static COMPOSE_OPTIONS: &[(&str, &str)] = &[ // ("Left Alt", "compose:lalt"), XXX? @@ -90,6 +90,7 @@ const KB_REPEAT_RATE_MAX: u32 = 45; const KB_REPEAT_RATE_MIN: u32 = 5; pub struct Page { + entity: page::Entity, config: cosmic_config::Config, context: Option, input_source_search: String, @@ -105,6 +106,7 @@ impl Default for Page { let config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap(); Self { + entity: page::Entity::null(), context: None, expanded_source_popover: None, keyboard_layouts: SlotMap::new(), @@ -253,6 +255,10 @@ fn special_char_radio_row<'a>( } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -285,7 +291,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.xkb = super::get_config(&self.config, "xkb_config"); @@ -453,6 +458,7 @@ impl Page { Message::ShowInputSourcesContext => { self.context = Some(Context::ShowInputSourcesContext); return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, fl!("keyboard-sources", "add").into(), )); } @@ -464,6 +470,7 @@ impl Page { Message::OpenSpecialCharacterContext(key) => { self.context = Some(Context::SpecialCharacter(key)); return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, key.title().into(), )); } diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/common.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/common.rs index 5d97915..12783b5 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/common.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/common.rs @@ -4,7 +4,9 @@ use cosmic::widget::{self, button, icon, settings, text}; use cosmic::{theme, Apply, Element, Task}; use cosmic_config::{ConfigGet, ConfigSet}; use cosmic_settings_config::shortcuts::{self, Action, Binding, Shortcuts}; +use cosmic_settings_page as page; use slab::Slab; +use slotmap::Key; use std::borrow::Cow; use std::io; use std::str::FromStr; @@ -89,6 +91,7 @@ impl ShortcutModel { #[must_use] pub struct Model { + pub entity: page::Entity, pub defaults: Shortcuts, pub replace_dialog: Option<(usize, Binding, Action, String)>, pub shortcut_models: Slab, @@ -101,6 +104,7 @@ pub struct Model { impl Default for Model { fn default() -> Self { Self { + entity: page::Entity::null(), defaults: Shortcuts::default(), replace_dialog: None, shortcut_models: Slab::new(), @@ -390,7 +394,7 @@ impl Model { self.replace_dialog = None; let mut tasks = vec![cosmic::command::message( - crate::app::Message::OpenContextDrawer(description.into()), + crate::app::Message::OpenContextDrawer(self.entity, description.into()), )]; if let Some(model) = self.shortcut_models.get(0) { diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs index d27076f..1a502f0 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/custom.rs @@ -9,9 +9,10 @@ use cosmic_settings_config::shortcuts::{Action, Shortcuts}; use cosmic_settings_config::Binding; use cosmic_settings_page::{self as page, section, Section}; use slab::Slab; -use slotmap::SlotMap; +use slotmap::{Key, SlotMap}; pub struct Page { + entity: page::Entity, model: super::Model, add_shortcut: AddShortcut, replace_dialog: Vec<(Binding, Action, String)>, @@ -22,6 +23,7 @@ pub struct Page { impl Default for Page { fn default() -> Self { Self { + entity: page::Entity::null(), model: super::Model::default().custom().actions(bindings), add_shortcut: AddShortcut::default(), replace_dialog: Vec::new(), @@ -211,6 +213,7 @@ impl Page { self.add_shortcut.enable(); return Task::batch(vec![ cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, fl!("custom-shortcuts", "context").into(), )), widget::text_input::focus(self.name_id.clone()), @@ -294,6 +297,11 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + self.model.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("custom-shortcuts", "input-keyboard-symbolic") .title(fl!("custom-shortcuts")) @@ -348,7 +356,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.model.on_enter(); diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/manage_windows.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/manage_windows.rs index ea29bd4..0109603 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/manage_windows.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/manage_windows.rs @@ -29,6 +29,10 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.model.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("manage-windows", "input-keyboard-symbolic").title(fl!("manage-windows")) } @@ -54,7 +58,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.model.on_enter(); diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs index 2b0aec7..73b01fd 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/mod.rs @@ -27,6 +27,7 @@ use slotmap::{DefaultKey, Key, SecondaryMap, SlotMap}; use std::io; pub struct Page { + entity: page::Entity, modified: Modified, search: Search, search_model: Model, @@ -82,6 +83,7 @@ pub enum Category { impl Default for Page { fn default() -> Self { Self { + entity: page::Entity::default(), modified: Modified::default(), search: Search::default(), search_model: Model::default(), @@ -99,6 +101,11 @@ impl Default for Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + self.search_model.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -134,7 +141,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { if self.shortcuts_context.is_none() { diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/move_window.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/move_window.rs index bffd3c8..fdaa84b 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/move_window.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/move_window.rs @@ -29,6 +29,10 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.model.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("move-windows", "input-keyboard-symbolic").title(fl!("move-windows")) } @@ -54,7 +58,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.model.on_enter(); diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/nav.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/nav.rs index ae526ac..81ce0b4 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/nav.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/nav.rs @@ -29,6 +29,10 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.model.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("nav-shortcuts", "input-keyboard-symbolic").title(fl!("nav-shortcuts")) } @@ -54,7 +58,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.model.on_enter(); diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/system.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/system.rs index 38060e1..9d92cb2 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/system.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/system.rs @@ -29,6 +29,10 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.model.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("system-shortcut", "input-keyboard-symbolic").title(fl!("system-shortcut")) } @@ -54,7 +58,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.model.on_enter(); diff --git a/cosmic-settings/src/pages/input/keyboard/shortcuts/tiling.rs b/cosmic-settings/src/pages/input/keyboard/shortcuts/tiling.rs index e92ff43..8832974 100644 --- a/cosmic-settings/src/pages/input/keyboard/shortcuts/tiling.rs +++ b/cosmic-settings/src/pages/input/keyboard/shortcuts/tiling.rs @@ -29,6 +29,10 @@ impl Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.model.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("window-tiling", "input-keyboard-symbolic").title(fl!("window-tiling")) } @@ -54,7 +58,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { self.model.on_enter(); diff --git a/cosmic-settings/src/pages/input/mouse.rs b/cosmic-settings/src/pages/input/mouse.rs index 6aad08c..f055aef 100644 --- a/cosmic-settings/src/pages/input/mouse.rs +++ b/cosmic-settings/src/pages/input/mouse.rs @@ -19,9 +19,15 @@ pub fn default_primary_button() -> cosmic::widget::segmented_button::SingleSelec } #[derive(Default)] -pub struct Page; +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, diff --git a/cosmic-settings/src/pages/networking/mod.rs b/cosmic-settings/src/pages/networking/mod.rs index 3e47df8..e2f930d 100644 --- a/cosmic-settings/src/pages/networking/mod.rs +++ b/cosmic-settings/src/pages/networking/mod.rs @@ -22,6 +22,7 @@ static NM_CONNECTION_EDITOR: &str = "nm-connection-editor"; #[derive(Debug, Default)] pub struct Page { + entity: page::Entity, nm_task: Option>, devices: Vec>, vpn: page::Entity, @@ -68,6 +69,10 @@ impl From for crate::pages::Message { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> cosmic_settings_page::Info { page::Info::new( "network-and-wireless", @@ -221,7 +226,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: page::Entity, sender: tokio::sync::mpsc::Sender, ) -> cosmic::Task { if self.nm_task.is_none() { diff --git a/cosmic-settings/src/pages/networking/vpn/mod.rs b/cosmic-settings/src/pages/networking/vpn/mod.rs index d44bc10..2dc387c 100644 --- a/cosmic-settings/src/pages/networking/vpn/mod.rs +++ b/cosmic-settings/src/pages/networking/vpn/mod.rs @@ -189,6 +189,7 @@ pub struct NmState { #[derive(Debug, Default)] pub struct Page { + entity: page::Entity, nm_task: Option>, nm_state: Option, dialog: Option, @@ -203,6 +204,10 @@ pub struct Page { impl page::AutoBind for Page {} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> cosmic_settings_page::Info { page::Info::new("vpn", "preferences-vpn-symbolic") .title(fl!("vpn")) @@ -327,7 +332,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, sender: tokio::sync::mpsc::Sender, ) -> cosmic::Task { if self.nm_task.is_none() { diff --git a/cosmic-settings/src/pages/networking/wifi.rs b/cosmic-settings/src/pages/networking/wifi.rs index c550e79..80acf99 100644 --- a/cosmic-settings/src/pages/networking/wifi.rs +++ b/cosmic-settings/src/pages/networking/wifi.rs @@ -93,6 +93,7 @@ enum WiFiDialog { #[derive(Debug, Default)] pub struct Page { + entity: page::Entity, nm_task: Option>, nm_state: Option, /// When defined, displays connections for the specific device. @@ -118,6 +119,10 @@ pub struct NmState { impl page::AutoBind for Page {} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> cosmic_settings_page::Info { page::Info::new("wifi", "preferences-wireless-symbolic") .title(fl!("wifi")) @@ -196,7 +201,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, sender: tokio::sync::mpsc::Sender, ) -> cosmic::Task { if self.nm_task.is_none() { diff --git a/cosmic-settings/src/pages/networking/wired.rs b/cosmic-settings/src/pages/networking/wired.rs index 1731f6e..76104a2 100644 --- a/cosmic-settings/src/pages/networking/wired.rs +++ b/cosmic-settings/src/pages/networking/wired.rs @@ -78,6 +78,7 @@ enum WiredDialog { #[derive(Debug, Default)] pub struct Page { + entity: page::Entity, nm_task: Option>, nm_state: Option, dialog: Option, @@ -104,6 +105,10 @@ pub struct NmState { impl page::AutoBind for Page {} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> cosmic_settings_page::Info { page::Info::new("wired", "preferences-wired-symbolic") .title(fl!("wired")) @@ -152,7 +157,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, sender: tokio::sync::mpsc::Sender, ) -> cosmic::Task { if self.nm_task.is_none() { diff --git a/cosmic-settings/src/pages/power/mod.rs b/cosmic-settings/src/pages/power/mod.rs index 6605688..aad69fa 100644 --- a/cosmic-settings/src/pages/power/mod.rs +++ b/cosmic-settings/src/pages/power/mod.rs @@ -16,12 +16,17 @@ use slotmap::SlotMap; #[derive(Default)] pub struct Page { + entity: page::Entity, battery: Battery, connected_devices: Vec, on_enter_handle: Option, } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("power", "preferences-power-and-battery-symbolic") .title(fl!("power")) @@ -41,7 +46,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> cosmic::Task { let futures: Vec> = vec![ diff --git a/cosmic-settings/src/pages/sound.rs b/cosmic-settings/src/pages/sound.rs index dc2ed92..fb262c0 100644 --- a/cosmic-settings/src/pages/sound.rs +++ b/cosmic-settings/src/pages/sound.rs @@ -70,6 +70,7 @@ pub enum DeviceId { #[derive(Default)] pub struct Page { + entity: page::Entity, pipewire_thread: Option<(tokio::sync::oneshot::Sender<()>, pipewire::Sender<()>)>, pulse_thread: Option>, devices: BTreeMap, @@ -111,6 +112,10 @@ pub struct Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -126,7 +131,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, sender: tokio::sync::mpsc::Sender, ) -> Task { if self.pulse_thread.is_none() { diff --git a/cosmic-settings/src/pages/system/about.rs b/cosmic-settings/src/pages/system/about.rs index 0d71a55..3ac575a 100644 --- a/cosmic-settings/src/pages/system/about.rs +++ b/cosmic-settings/src/pages/system/about.rs @@ -19,6 +19,7 @@ pub enum Message { #[derive(Clone, Debug, Default)] pub struct Page { + entity: page::Entity, editing_device_name: bool, info: Info, on_enter_handle: Option, @@ -27,6 +28,10 @@ pub struct Page { impl page::AutoBind for Page {} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -46,7 +51,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { let (task, handle) = Task::future(async move { diff --git a/cosmic-settings/src/pages/system/firmware.rs b/cosmic-settings/src/pages/system/firmware.rs index 878e660..2fa3456 100644 --- a/cosmic-settings/src/pages/system/firmware.rs +++ b/cosmic-settings/src/pages/system/firmware.rs @@ -6,9 +6,15 @@ use cosmic_settings_page::{self as page, section}; use slotmap::SlotMap; #[derive(Default)] -pub struct Page; +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, diff --git a/cosmic-settings/src/pages/system/mod.rs b/cosmic-settings/src/pages/system/mod.rs index a6186fe..81b11e6 100644 --- a/cosmic-settings/src/pages/system/mod.rs +++ b/cosmic-settings/src/pages/system/mod.rs @@ -9,9 +9,15 @@ pub mod users; use cosmic_settings_page as page; #[derive(Default)] -pub struct Page; +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("system", "system-users-symbolic").title(fl!("system")) } diff --git a/cosmic-settings/src/pages/system/users.rs b/cosmic-settings/src/pages/system/users.rs index 4182f4d..f9066ba 100644 --- a/cosmic-settings/src/pages/system/users.rs +++ b/cosmic-settings/src/pages/system/users.rs @@ -6,9 +6,15 @@ use cosmic_settings_page::{self as page, section}; use slotmap::SlotMap; #[derive(Default)] -pub struct Page; +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, diff --git a/cosmic-settings/src/pages/time/date.rs b/cosmic-settings/src/pages/time/date.rs index 7d2ea3c..5025f80 100644 --- a/cosmic-settings/src/pages/time/date.rs +++ b/cosmic-settings/src/pages/time/date.rs @@ -11,15 +11,14 @@ use cosmic::{ widget::{self, dropdown, settings}, Apply, Element, Task, }; -use cosmic_settings_page::Section; -use cosmic_settings_page::{self as page, section}; +use cosmic_settings_page::{self as page, section, Section}; use icu::{ calendar::{DateTime, Iso}, datetime::DateTimeFormatter, locid::Locale, }; use slab::Slab; -use slotmap::SlotMap; +use slotmap::{Key, SlotMap}; pub use timedate_zbus::TimeDateProxy; use tracing::error; @@ -35,6 +34,7 @@ pub struct Info { } pub struct Page { + entity: page::Entity, cosmic_applet_config: cosmic_config::Config, first_day_of_week: usize, military_time: bool, @@ -95,6 +95,7 @@ impl Default for Page { }); Self { + entity: page::Entity::null(), cosmic_applet_config, first_day_of_week, formatted_date: String::new(), @@ -112,6 +113,10 @@ impl Default for Page { } impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, @@ -131,7 +136,6 @@ impl page::Page for Page { fn on_enter( &mut self, - _page: cosmic_settings_page::Entity, _sender: tokio::sync::mpsc::Sender, ) -> Task { cosmic::Task::future(async move { @@ -180,6 +184,7 @@ impl Page { self.timezone_search.clear(); self.timezone_context = true; return cosmic::command::message(crate::app::Message::OpenContextDrawer( + self.entity, fl!("time-zone").into(), )); } diff --git a/cosmic-settings/src/pages/time/mod.rs b/cosmic-settings/src/pages/time/mod.rs index 66c430a..f2275b5 100644 --- a/cosmic-settings/src/pages/time/mod.rs +++ b/cosmic-settings/src/pages/time/mod.rs @@ -8,9 +8,15 @@ pub mod date; pub mod region; #[derive(Default)] -pub struct Page; +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn info(&self) -> page::Info { page::Info::new("time", "preferences-time-and-language-symbolic") .title(fl!("time")) diff --git a/cosmic-settings/src/pages/time/region.rs b/cosmic-settings/src/pages/time/region.rs index 98603d8..37a18b9 100644 --- a/cosmic-settings/src/pages/time/region.rs +++ b/cosmic-settings/src/pages/time/region.rs @@ -6,9 +6,15 @@ use cosmic_settings_page::{self as page, section}; use slotmap::SlotMap; #[derive(Default)] -pub struct Page; +pub struct Page { + entity: page::Entity, +} impl page::Page for Page { + fn set_id(&mut self, entity: page::Entity) { + self.entity = entity; + } + fn content( &self, sections: &mut SlotMap>, diff --git a/page/src/binder.rs b/page/src/binder.rs index 2d273f5..4ba6309 100644 --- a/page/src/binder.rs +++ b/page/src/binder.rs @@ -102,13 +102,15 @@ impl Binder { P::sub_pages(crate::Insert { id, model: self }) } - pub fn register_page>(&mut self, page: P) -> crate::Entity { + pub fn register_page>(&mut self, mut page: P) -> crate::Entity { let id = self.info.insert(page.info()); if let Some(content) = page.content(&mut self.sections) { self.content.insert(id, content); } + page.set_id(id); + self.page.insert(id, Box::new(page)); id @@ -172,7 +174,7 @@ impl Binder { sender: tokio::sync::mpsc::Sender, ) -> Task { if let Some(page) = self.page.get_mut(id) { - return page.on_enter(id, sender); + return page.on_enter(sender); } Task::none() diff --git a/page/src/lib.rs b/page/src/lib.rs index 0ff5126..819b9d9 100644 --- a/page/src/lib.rs +++ b/page/src/lib.rs @@ -65,11 +65,7 @@ pub trait Page: Downcast { /// Reload page metadata via a Task. #[allow(unused)] - fn on_enter( - &mut self, - page: crate::Entity, - sender: tokio::sync::mpsc::Sender, - ) -> Task { + fn on_enter(&mut self, sender: tokio::sync::mpsc::Sender) -> Task { Task::none() } @@ -78,6 +74,9 @@ pub trait Page: Downcast { Task::none() } + /// Assigns the entity ID of the page to the page. + fn set_id(&mut self, entity: Entity) {} + /// The title to display in the page header. fn title(&self) -> Option<&str> { None