diff --git a/src/menu.rs b/src/menu.rs index a4856c7..5ae4535 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -1,15 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-only use cosmic::iced::Point; +use cosmic::widget::Column; use cosmic::widget::menu::key_bind::KeyBind; use cosmic::widget::menu::{Item as MenuItem, menu_button}; use cosmic::{ Element, app::Core, iced::{ - Background, Length, - advanced::widget::text::Style as TextStyle, - widget::{column, horizontal_space}, + Background, Length, advanced::widget::text::Style as TextStyle, widget::horizontal_space, }, iced_core::Border, theme, @@ -66,21 +65,6 @@ pub fn context_menu<'a>( .on_press(Message::TabContextAction(entity, action)) }; - let menu_item_conditional = |label, action, condition| { - let key = find_key(&action); - let mut button = menu_button(vec![ - widget::text(label).into(), - horizontal_space().into(), - widget::text(key) - .class(theme::Text::Custom(key_style)) - .into(), - ]); - if condition { - button = button.on_press(Message::TabContextAction(entity, action)); - } - button - }; - let menu_checkbox = |label, value, action| { menu_button(vec![ widget::text(label).into(), @@ -93,34 +77,49 @@ pub fn context_menu<'a>( .on_press(Message::TabContextAction(entity, action)) }; - let mut content = column!( - menu_item(fl!("copy"), Action::Copy), - menu_item(fl!("paste"), Action::Paste), - menu_item(fl!("select-all"), Action::SelectAll), - divider::horizontal::light(), - menu_item_conditional(fl!("open-link"), Action::LaunchUrlByMenu, link.is_some()), - divider::horizontal::light(), - menu_item(fl!("clear-scrollback"), Action::ClearScrollback), - divider::horizontal::light(), - menu_item(fl!("split-horizontal"), Action::PaneSplitHorizontal), - menu_item(fl!("split-vertical"), Action::PaneSplitVertical), - menu_item(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized), - divider::horizontal::light(), - menu_item(fl!("new-tab"), Action::TabNew), - menu_item(fl!("menu-settings"), Action::Settings), - ); + let mut rows = vec![ + Element::from(menu_item(fl!("copy"), Action::Copy)), + Element::from(menu_item(fl!("paste"), Action::Paste)), + Element::from(menu_item(fl!("select-all"), Action::SelectAll)), + Element::from(divider::horizontal::light()), + Element::from(menu_item(fl!("clear-scrollback"), Action::ClearScrollback)), + Element::from(divider::horizontal::light()), + Element::from(menu_item( + fl!("split-horizontal"), + Action::PaneSplitHorizontal, + )), + Element::from(menu_item(fl!("split-vertical"), Action::PaneSplitVertical)), + Element::from(menu_item( + fl!("pane-toggle-maximize"), + Action::PaneToggleMaximized, + )), + Element::from(divider::horizontal::light()), + Element::from(menu_item(fl!("new-tab"), Action::TabNew)), + Element::from(menu_item(fl!("menu-settings"), Action::Settings)), + ]; #[cfg(feature = "password_manager")] { - content = content.push(menu_item( + rows.push(Element::from(menu_item( fl!("menu-password-manager"), Action::PasswordManager, - )); + ))); } - content = content.push(menu_checkbox( + rows.push(Element::from(menu_checkbox( fl!("show-headerbar"), config.show_headerbar, Action::ShowHeaderBar(!config.show_headerbar), - )); + ))); + + //If we have a link + //prepend the Open Link item + if link.is_some() { + rows.insert( + 0, + Element::from(menu_item(fl!("open-link"), Action::LaunchUrlByMenu)), + ); + rows.insert(1, Element::from(divider::horizontal::light())); + } + let content = Column::with_children(rows); widget::container(content) .padding(1) //TODO: move style to libcosmic