feat: inner-app dialog API support

This commit is contained in:
Michael Aaron Murphy 2024-03-27 16:01:35 +01:00 committed by Michael Murphy
parent 43b478ee68
commit 29f0489c8a
3 changed files with 23 additions and 2 deletions

View file

@ -60,7 +60,6 @@ impl SettingsApp {
PageCommands::DesktopPanel => self.pages.page_id::<desktop::options::Page>(), PageCommands::DesktopPanel => self.pages.page_id::<desktop::options::Page>(),
PageCommands::Displays => self.pages.page_id::<display::Page>(), PageCommands::Displays => self.pages.page_id::<display::Page>(),
PageCommands::Firmware => self.pages.page_id::<system::firmware::Page>(), PageCommands::Firmware => self.pages.page_id::<system::firmware::Page>(),
PageCommands::Keyboard => self.pages.page_id::<input::keyboard::Page>(),
PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(), PageCommands::Mouse => self.pages.page_id::<input::mouse::Page>(),
PageCommands::Network => None, PageCommands::Network => None,
PageCommands::Notifications => self.pages.page_id::<desktop::notifications::Page>(), PageCommands::Notifications => self.pages.page_id::<desktop::notifications::Page>(),
@ -529,6 +528,12 @@ impl cosmic::Application for SettingsApp {
None None
} }
} }
fn dialog(&self) -> Option<Element<Self::Message>> {
self.pages
.dialog(self.active_page)
.map(|e| e.map(Message::PageMessage))
}
} }
impl SettingsApp { impl SettingsApp {

View file

@ -136,13 +136,20 @@ impl<Message: 'static> Binder<Message> {
page.downcast_ref::<P>() page.downcast_ref::<P>()
} }
/// Obtain a reference to a page by its type ID. /// Create a context drawer for the given page.
#[must_use] #[must_use]
pub fn context_drawer(&self, id: crate::Entity) -> Option<Element<'_, Message>> { pub fn context_drawer(&self, id: crate::Entity) -> Option<Element<'_, Message>> {
let page = self.page.get(id)?; let page = self.page.get(id)?;
page.context_drawer() page.context_drawer()
} }
/// Create a dialog for the given page.
#[must_use]
pub fn dialog(&self, id: crate::Entity) -> Option<Element<'_, Message>> {
let page = self.page.get(id)?;
page.dialog()
}
/// Obtain a reference to a page by its type ID. /// Obtain a reference to a page by its type ID.
#[must_use] #[must_use]
pub fn page_mut<P: Page<Message>>(&mut self) -> Option<&mut P> { pub fn page_mut<P: Page<Message>>(&mut self) -> Option<&mut P> {

View file

@ -28,6 +28,7 @@ pub trait Page<Message: 'static>: Downcast {
/// Information about the page /// Information about the page
fn info(&self) -> Info; fn info(&self) -> Info;
/// Initialize the sections used by this page.
#[must_use] #[must_use]
fn content( fn content(
&self, &self,
@ -36,20 +37,28 @@ pub trait Page<Message: 'static>: Downcast {
None None
} }
/// Display a context drawer for the page.
#[must_use] #[must_use]
fn context_drawer(&self) -> Option<Element<'_, Message>> { fn context_drawer(&self) -> Option<Element<'_, Message>> {
None None
} }
/// Display an inner app dialog for the page.
fn dialog(&self) -> Option<Element<'_, Message>> {
None
}
/// Response from a file chooser dialog request. /// Response from a file chooser dialog request.
fn file_chooser(&mut self, _selected: Vec<url::Url>) -> Command<Message> { fn file_chooser(&mut self, _selected: Vec<url::Url>) -> Command<Message> {
Command::none() Command::none()
} }
/// Alter the contents of the page's header view.
fn header_view(&self) -> Option<Element<'_, Message>> { fn header_view(&self) -> Option<Element<'_, Message>> {
None None
} }
/// Reload page metadata via a Command.
#[must_use] #[must_use]
#[allow(unused)] #[allow(unused)]
fn reload(&mut self, page: crate::Entity) -> Command<Message> { fn reload(&mut self, page: crate::Entity) -> Command<Message> {