Show the Open Link menu item at the top of the menu if we have a link
This commit is contained in:
parent
b308110f22
commit
d486de067b
1 changed files with 37 additions and 38 deletions
75
src/menu.rs
75
src/menu.rs
|
|
@ -1,15 +1,14 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use cosmic::iced::Point;
|
use cosmic::iced::Point;
|
||||||
|
use cosmic::widget::Column;
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
use cosmic::widget::menu::key_bind::KeyBind;
|
||||||
use cosmic::widget::menu::{Item as MenuItem, menu_button};
|
use cosmic::widget::menu::{Item as MenuItem, menu_button};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
Element,
|
Element,
|
||||||
app::Core,
|
app::Core,
|
||||||
iced::{
|
iced::{
|
||||||
Background, Length,
|
Background, Length, advanced::widget::text::Style as TextStyle, widget::horizontal_space,
|
||||||
advanced::widget::text::Style as TextStyle,
|
|
||||||
widget::{column, horizontal_space},
|
|
||||||
},
|
},
|
||||||
iced_core::Border,
|
iced_core::Border,
|
||||||
theme,
|
theme,
|
||||||
|
|
@ -66,21 +65,6 @@ pub fn context_menu<'a>(
|
||||||
.on_press(Message::TabContextAction(entity, action))
|
.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| {
|
let menu_checkbox = |label, value, action| {
|
||||||
menu_button(vec![
|
menu_button(vec![
|
||||||
widget::text(label).into(),
|
widget::text(label).into(),
|
||||||
|
|
@ -93,34 +77,49 @@ pub fn context_menu<'a>(
|
||||||
.on_press(Message::TabContextAction(entity, action))
|
.on_press(Message::TabContextAction(entity, action))
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut content = column!(
|
let mut rows = vec![
|
||||||
menu_item(fl!("copy"), Action::Copy),
|
Element::from(menu_item(fl!("copy"), Action::Copy)),
|
||||||
menu_item(fl!("paste"), Action::Paste),
|
Element::from(menu_item(fl!("paste"), Action::Paste)),
|
||||||
menu_item(fl!("select-all"), Action::SelectAll),
|
Element::from(menu_item(fl!("select-all"), Action::SelectAll)),
|
||||||
divider::horizontal::light(),
|
Element::from(divider::horizontal::light()),
|
||||||
menu_item_conditional(fl!("open-link"), Action::LaunchUrlByMenu, link.is_some()),
|
Element::from(menu_item(fl!("clear-scrollback"), Action::ClearScrollback)),
|
||||||
divider::horizontal::light(),
|
Element::from(divider::horizontal::light()),
|
||||||
menu_item(fl!("clear-scrollback"), Action::ClearScrollback),
|
Element::from(menu_item(
|
||||||
divider::horizontal::light(),
|
fl!("split-horizontal"),
|
||||||
menu_item(fl!("split-horizontal"), Action::PaneSplitHorizontal),
|
Action::PaneSplitHorizontal,
|
||||||
menu_item(fl!("split-vertical"), Action::PaneSplitVertical),
|
)),
|
||||||
menu_item(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized),
|
Element::from(menu_item(fl!("split-vertical"), Action::PaneSplitVertical)),
|
||||||
divider::horizontal::light(),
|
Element::from(menu_item(
|
||||||
menu_item(fl!("new-tab"), Action::TabNew),
|
fl!("pane-toggle-maximize"),
|
||||||
menu_item(fl!("menu-settings"), Action::Settings),
|
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")]
|
#[cfg(feature = "password_manager")]
|
||||||
{
|
{
|
||||||
content = content.push(menu_item(
|
rows.push(Element::from(menu_item(
|
||||||
fl!("menu-password-manager"),
|
fl!("menu-password-manager"),
|
||||||
Action::PasswordManager,
|
Action::PasswordManager,
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
content = content.push(menu_checkbox(
|
rows.push(Element::from(menu_checkbox(
|
||||||
fl!("show-headerbar"),
|
fl!("show-headerbar"),
|
||||||
config.show_headerbar,
|
config.show_headerbar,
|
||||||
Action::ShowHeaderBar(!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)
|
widget::container(content)
|
||||||
.padding(1)
|
.padding(1)
|
||||||
//TODO: move style to libcosmic
|
//TODO: move style to libcosmic
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue