2023-12-22 15:00:50 -07:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2026-09-08 13:49:17 -06:00
|
|
|
use cosmic::widget::menu::action::MenuAction;
|
2024-03-18 19:31:28 -07:00
|
|
|
use cosmic::widget::menu::key_bind::KeyBind;
|
2025-09-10 14:33:46 +02:00
|
|
|
use cosmic::widget::menu::{Item as MenuItem, menu_button};
|
2023-12-22 15:00:50 -07:00
|
|
|
use cosmic::{
|
2025-09-10 14:33:46 +02:00
|
|
|
Element,
|
2025-04-15 17:38:49 -04:00
|
|
|
app::Core,
|
2026-04-08 15:30:10 -06:00
|
|
|
iced::core::Border,
|
2026-09-08 13:49:17 -06:00
|
|
|
iced::{Background, Length},
|
2024-01-09 10:16:32 -07:00
|
|
|
widget::{
|
2026-09-08 13:49:17 -06:00
|
|
|
self,
|
2025-06-27 11:44:40 -06:00
|
|
|
menu::{ItemHeight, ItemWidth},
|
2025-04-15 17:38:49 -04:00
|
|
|
responsive_menu_bar, segmented_button,
|
2024-01-09 10:16:32 -07:00
|
|
|
},
|
2023-12-22 15:00:50 -07:00
|
|
|
};
|
2025-04-15 17:38:49 -04:00
|
|
|
use std::{collections::HashMap, sync::LazyLock};
|
2023-12-22 15:00:50 -07:00
|
|
|
|
2025-09-10 14:33:46 +02:00
|
|
|
use crate::{Action, ColorSchemeId, ColorSchemeKind, Config, Message, fl};
|
2023-12-22 15:00:50 -07:00
|
|
|
|
2025-04-15 17:38:49 -04:00
|
|
|
static MENU_ID: LazyLock<cosmic::widget::Id> =
|
|
|
|
|
LazyLock::new(|| cosmic::widget::Id::new("responsive-menu"));
|
|
|
|
|
|
2026-09-08 13:49:17 -06:00
|
|
|
/// What the terminal found under the right-click
|
2025-10-16 09:27:00 +02:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct MenuState {
|
|
|
|
|
pub link: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-08 13:49:17 -06:00
|
|
|
/// A context menu action dispatched to the tab the menu was opened on.
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
|
pub struct TabAction(pub segmented_button::Entity, pub Action);
|
|
|
|
|
|
|
|
|
|
impl MenuAction for TabAction {
|
|
|
|
|
type Message = Message;
|
|
|
|
|
|
|
|
|
|
fn message(&self) -> Message {
|
|
|
|
|
Message::TabContextAction(self.0, self.1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn context_menu(
|
2024-01-19 11:44:59 -07:00
|
|
|
config: &Config,
|
|
|
|
|
key_binds: &HashMap<KeyBind, Action>,
|
|
|
|
|
entity: segmented_button::Entity,
|
2025-10-16 09:27:00 +02:00
|
|
|
link: Option<String>,
|
2026-09-08 13:49:17 -06:00
|
|
|
) -> Vec<widget::menu::Tree<Message>> {
|
|
|
|
|
let item =
|
|
|
|
|
|label: String, action: Action| MenuItem::Button(label, None, TabAction(entity, action));
|
2023-12-22 15:40:10 -07:00
|
|
|
|
2026-09-08 13:49:17 -06:00
|
|
|
let mut items = vec![
|
2026-09-15 15:03:20 -06:00
|
|
|
item(fl!("new-tab"), Action::TabNew),
|
|
|
|
|
MenuItem::Divider,
|
2026-09-08 13:49:17 -06:00
|
|
|
item(fl!("copy"), Action::Copy),
|
|
|
|
|
item(fl!("paste"), Action::Paste),
|
|
|
|
|
item(fl!("select-all"), Action::SelectAll),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
item(fl!("clear-scrollback"), Action::ClearScrollback),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
item(fl!("split-horizontal"), Action::PaneSplitHorizontal),
|
|
|
|
|
item(fl!("split-vertical"), Action::PaneSplitVertical),
|
|
|
|
|
item(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized),
|
|
|
|
|
MenuItem::Divider,
|
2026-09-15 15:03:20 -06:00
|
|
|
MenuItem::CheckBox(
|
|
|
|
|
fl!("window-header"),
|
|
|
|
|
None,
|
|
|
|
|
config.show_headerbar,
|
|
|
|
|
TabAction(entity, Action::ShowHeaderBar(!config.show_headerbar)),
|
|
|
|
|
),
|
|
|
|
|
MenuItem::Divider,
|
2025-10-21 22:59:36 +02:00
|
|
|
];
|
2024-02-09 09:35:24 +01:00
|
|
|
#[cfg(feature = "password_manager")]
|
2026-09-08 13:49:17 -06:00
|
|
|
items.push(item(fl!("menu-password-manager"), Action::PasswordManager));
|
2026-09-15 15:03:20 -06:00
|
|
|
items.push(item(fl!("menu-settings"), Action::Settings));
|
2026-09-08 13:49:17 -06:00
|
|
|
// If we have a link, prepend the link items
|
2025-10-21 22:59:36 +02:00
|
|
|
if link.is_some() {
|
2026-09-08 13:49:17 -06:00
|
|
|
items.insert(0, item(fl!("open-link"), Action::LaunchUrlByMenu));
|
|
|
|
|
items.insert(1, item(fl!("copy-link"), Action::CopyUrlByMenu));
|
|
|
|
|
items.insert(2, MenuItem::Divider);
|
2025-10-21 22:59:36 +02:00
|
|
|
}
|
2026-09-08 13:49:17 -06:00
|
|
|
|
|
|
|
|
let key_binds: HashMap<KeyBind, TabAction> = key_binds
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(key_bind, action)| (key_bind.clone(), TabAction(entity, *action)))
|
|
|
|
|
.collect();
|
|
|
|
|
widget::menu::items(&key_binds, items)
|
2023-12-22 15:00:50 -07:00
|
|
|
}
|
2024-01-09 10:16:32 -07:00
|
|
|
|
2024-02-22 11:18:13 -07:00
|
|
|
pub fn color_scheme_menu<'a>(
|
|
|
|
|
kind: ColorSchemeKind,
|
2024-06-05 08:51:26 -06:00
|
|
|
id_opt: Option<ColorSchemeId>,
|
2024-02-22 11:18:13 -07:00
|
|
|
name: &str,
|
|
|
|
|
) -> Element<'a, Message> {
|
2024-05-30 13:59:14 -04:00
|
|
|
let menu_item =
|
|
|
|
|
|label, message| menu_button(vec![widget::text(label).into()]).on_press(message);
|
2024-02-22 09:55:46 -07:00
|
|
|
|
2026-07-06 09:26:53 -04:00
|
|
|
let mut column =
|
|
|
|
|
widget::menu::menu_column::MenuColumn::with_capacity(if id_opt.is_some() { 3 } else { 1 });
|
2024-06-05 08:51:26 -06:00
|
|
|
if let Some(id) = id_opt {
|
|
|
|
|
column = column.push(menu_item(
|
2024-02-22 09:55:46 -07:00
|
|
|
fl!("rename"),
|
2024-06-05 08:51:26 -06:00
|
|
|
Message::ColorSchemeRename(kind, id, name.to_string()),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
column = column.push(menu_item(
|
|
|
|
|
fl!("export"),
|
|
|
|
|
Message::ColorSchemeExport(kind, id_opt),
|
|
|
|
|
));
|
|
|
|
|
if let Some(id) = id_opt {
|
|
|
|
|
column = column.push(menu_item(
|
|
|
|
|
fl!("delete"),
|
|
|
|
|
Message::ColorSchemeDelete(kind, id),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widget::container(column)
|
|
|
|
|
.padding(1)
|
|
|
|
|
//TODO: move style to libcosmic
|
2024-10-22 12:31:02 -06:00
|
|
|
.style(|theme| {
|
2024-06-05 08:51:26 -06:00
|
|
|
let cosmic = theme.cosmic();
|
2026-07-06 09:26:53 -04:00
|
|
|
let component = &cosmic.background(theme.transparent).component;
|
2024-10-22 12:31:02 -06:00
|
|
|
widget::container::Style {
|
2024-06-05 08:51:26 -06:00
|
|
|
icon_color: Some(component.on.into()),
|
|
|
|
|
text_color: Some(component.on.into()),
|
|
|
|
|
background: Some(Background::Color(component.base.into())),
|
|
|
|
|
border: Border {
|
2024-11-05 13:21:05 +01:00
|
|
|
radius: cosmic.radius_s().map(|x| x + 1.0).into(),
|
2024-06-05 08:51:26 -06:00
|
|
|
width: 1.0,
|
|
|
|
|
color: component.divider.into(),
|
|
|
|
|
},
|
|
|
|
|
..Default::default()
|
|
|
|
|
}
|
2024-10-22 12:31:02 -06:00
|
|
|
})
|
2024-06-05 08:51:26 -06:00
|
|
|
.width(Length::Fixed(120.0))
|
|
|
|
|
.into()
|
2024-02-22 09:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2025-04-15 17:38:49 -04:00
|
|
|
pub fn menu_bar<'a>(
|
|
|
|
|
core: &Core,
|
|
|
|
|
config: &Config,
|
|
|
|
|
key_binds: &HashMap<KeyBind, Action>,
|
|
|
|
|
) -> Element<'a, Message> {
|
2024-02-09 15:45:46 -07:00
|
|
|
let mut profile_items = Vec::with_capacity(config.profiles.len());
|
|
|
|
|
for (name, id) in config.profile_names() {
|
2024-12-02 23:26:14 +01:00
|
|
|
profile_items.push(MenuItem::Button(name, None, Action::ProfileOpen(id)));
|
2024-02-09 15:45:46 -07:00
|
|
|
}
|
2024-03-18 19:31:28 -07:00
|
|
|
|
2024-02-09 15:45:46 -07:00
|
|
|
//TODO: what to do if there are no profiles?
|
|
|
|
|
|
2026-06-12 13:47:00 -07:00
|
|
|
let color_scheme_kind = config.color_scheme_kind(core.system_theme());
|
|
|
|
|
|
2025-04-15 17:38:49 -04:00
|
|
|
responsive_menu_bar()
|
|
|
|
|
.item_height(ItemHeight::Dynamic(40))
|
2026-01-02 21:49:31 +00:00
|
|
|
.item_width(ItemWidth::Uniform(320))
|
2025-04-15 17:38:49 -04:00
|
|
|
.spacing(4.0)
|
|
|
|
|
.into_element(
|
|
|
|
|
core,
|
|
|
|
|
key_binds,
|
|
|
|
|
MENU_ID.clone(),
|
|
|
|
|
Message::Surface,
|
|
|
|
|
vec![
|
|
|
|
|
(
|
|
|
|
|
fl!("file"),
|
|
|
|
|
vec![
|
|
|
|
|
MenuItem::Button(fl!("new-tab"), None, Action::TabNew),
|
|
|
|
|
MenuItem::Button(fl!("new-window"), None, Action::WindowNew),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Folder(fl!("profile"), profile_items),
|
|
|
|
|
MenuItem::Button(fl!("menu-profiles"), None, Action::Profiles),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(fl!("close-tab"), None, Action::TabClose),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(fl!("quit"), None, Action::WindowClose),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
fl!("edit"),
|
|
|
|
|
vec![
|
|
|
|
|
MenuItem::Button(fl!("copy"), None, Action::Copy),
|
|
|
|
|
MenuItem::Button(fl!("paste"), None, Action::Paste),
|
|
|
|
|
MenuItem::Button(fl!("select-all"), None, Action::SelectAll),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(fl!("clear-scrollback"), None, Action::ClearScrollback),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(fl!("find"), None, Action::Find),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
fl!("view"),
|
|
|
|
|
vec![
|
|
|
|
|
MenuItem::Button(fl!("zoom-in"), None, Action::ZoomIn),
|
|
|
|
|
MenuItem::Button(fl!("zoom-reset"), None, Action::ZoomReset),
|
|
|
|
|
MenuItem::Button(fl!("zoom-out"), None, Action::ZoomOut),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(fl!("next-tab"), None, Action::TabNext),
|
|
|
|
|
MenuItem::Button(fl!("previous-tab"), None, Action::TabPrev),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(
|
|
|
|
|
fl!("split-horizontal"),
|
|
|
|
|
None,
|
|
|
|
|
Action::PaneSplitHorizontal,
|
|
|
|
|
),
|
|
|
|
|
MenuItem::Button(fl!("split-vertical"), None, Action::PaneSplitVertical),
|
|
|
|
|
MenuItem::Button(
|
|
|
|
|
fl!("pane-toggle-maximize"),
|
|
|
|
|
None,
|
|
|
|
|
Action::PaneToggleMaximized,
|
|
|
|
|
),
|
|
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(
|
|
|
|
|
fl!("menu-color-schemes"),
|
|
|
|
|
None,
|
2026-06-12 13:47:00 -07:00
|
|
|
Action::ColorSchemes(color_scheme_kind),
|
2025-04-15 17:38:49 -04:00
|
|
|
),
|
2026-02-05 11:31:05 -07:00
|
|
|
MenuItem::Button(
|
|
|
|
|
fl!("menu-keyboard-shortcuts"),
|
|
|
|
|
None,
|
|
|
|
|
Action::KeyboardShortcuts,
|
|
|
|
|
),
|
2025-04-15 17:38:49 -04:00
|
|
|
MenuItem::Button(fl!("menu-settings"), None, Action::Settings),
|
2024-02-09 09:35:24 +01:00
|
|
|
#[cfg(feature = "password_manager")]
|
|
|
|
|
MenuItem::Button(
|
|
|
|
|
fl!("menu-password-manager"),
|
|
|
|
|
None,
|
|
|
|
|
Action::PasswordManager,
|
|
|
|
|
),
|
2025-04-15 17:38:49 -04:00
|
|
|
MenuItem::Divider,
|
|
|
|
|
MenuItem::Button(fl!("menu-about"), None, Action::About),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
2024-01-09 10:16:32 -07:00
|
|
|
}
|