Skip to content

Commit

Permalink
input: Use existing message to open keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Aug 29, 2023
1 parent 2137919 commit a1943ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
5 changes: 0 additions & 5 deletions app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,6 @@ impl Application for SettingsApp {
page::update!(self.pages, message, desktop::wallpaper::Page);
}
crate::pages::Message::Input(message) => {
if matches!(message, input::Message::OpenKeyboardShortcuts) {
if let Some(id) = self.pages.page_id::<input::keyboard::shortcuts::Page>() {
return self.activate_page(id);
}
}
if let Some(page) = self.pages.page_mut::<input::Page>() {
return page.update(message);
}
Expand Down
23 changes: 14 additions & 9 deletions app/src/pages/input/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,28 +291,33 @@ fn keyboard_shortcuts() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("keyboard-shortcuts"))
.descriptions(vec![fl!("keyboard-shortcuts", "desc")])
.view::<Page>(|_binder, _page, section| {
.view::<Page>(|binder, _page, section| {
let descriptions = &section.descriptions;

settings::view_section(&section.title)
.add(go_next_item(
let mut section = settings::view_section(&section.title);
if let Some((shortcuts_entity, _)) = binder
.info
.iter()
.find(|(_, v)| v.id == "keyboard-shortcuts")
{
section = section.add(go_next_item(
&descriptions[0],
Message::OpenKeyboardShortcuts,
))
.apply(cosmic::Element::from)
.map(crate::pages::Message::Input)
crate::pages::Message::Page(shortcuts_entity),
));
}
section.apply(cosmic::Element::from)
})
}

fn go_next_control() -> cosmic::Element<'static, Message> {
fn go_next_control<Msg: Clone + 'static>() -> cosmic::Element<'static, Msg> {
widget::row!(
horizontal_space(Length::Fill),
cosmic::widget::icon("go-next-symbolic", 20).style(cosmic::theme::Svg::Symbolic)
)
.into()
}

fn go_next_item(description: &str, msg: Message) -> cosmic::Element<'_, Message> {
fn go_next_item<Msg: Clone + 'static>(description: &str, msg: Msg) -> cosmic::Element<'_, Msg> {
settings::item(description, go_next_control())
.apply(widget::container)
.style(cosmic::theme::Container::custom(
Expand Down
2 changes: 0 additions & 2 deletions app/src/pages/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub enum Message {
PrimaryButtonSelected(cosmic::widget::segmented_button::Entity),
// seperate close message, to make sure another isn't closed?
ExpandInputSourcePopover(Option<String>),
OpenKeyboardShortcuts,
OpenSpecialCharacterDialog(keyboard::SpecialKey),
CloseSpecialCharacterDialog,
SpecialCharacterSelect(Option<&'static str>),
Expand Down Expand Up @@ -146,7 +145,6 @@ impl Page {
}
}
}
Message::OpenKeyboardShortcuts => {}
}
iced::Command::none()
}
Expand Down

0 comments on commit a1943ac

Please sign in to comment.