diff --git a/i18n/en/cosmic_term.ftl b/i18n/en/cosmic_term.ftl index b8b5738..de8681a 100644 --- a/i18n/en/cosmic_term.ftl +++ b/i18n/en/cosmic_term.ftl @@ -51,7 +51,7 @@ next-tab = Next tab previous-tab = Previous tab split-horizontal = Split horizontal split-vertical = Split vertical -pane-toggle-maximize = Toggle pane maximized +pane-toggle-maximize = Toggle maximized menu-settings = Settings... # Context menu diff --git a/src/key_bind.rs b/src/key_bind.rs index 6d3a7b4..15c03e6 100644 --- a/src/key_bind.rs +++ b/src/key_bind.rs @@ -37,6 +37,7 @@ impl fmt::Display for KeyBind { } } +//TODO: load from config pub fn key_binds() -> HashMap { let mut key_binds = HashMap::new(); diff --git a/src/main.rs b/src/main.rs index ffa4198..498b2c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1415,7 +1415,7 @@ impl Application for App { let tab_element: Element<'_, Message> = match context_menu { Some(position) => widget::popover( terminal_box.context_menu(position), - menu::context_menu(&self.config, entity), + menu::context_menu(&self.config, &self.key_binds, entity), ) .position(position) .into(), diff --git a/src/menu.rs b/src/menu.rs index 44dd2c4..012682c 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -33,9 +33,28 @@ macro_rules! menu_button { ); } -pub fn context_menu<'a>(config: &Config, entity: segmented_button::Entity) -> Element<'a, Message> { - let menu_action = |label, action| { - menu_button!(widget::text(label)).on_press(Message::TabContextAction(entity, action)) +pub fn context_menu<'a>( + config: &Config, + key_binds: &HashMap, + entity: segmented_button::Entity, +) -> Element<'a, Message> { + let find_key = |action: &Action| -> String { + for (key_bind, key_action) in key_binds.iter() { + if action == key_action { + return key_bind.to_string(); + } + } + String::new() + }; + + let menu_item = |label, action| { + let key = find_key(&action); + menu_button!( + widget::text(label), + horizontal_space(Length::Fill), + widget::text(key) + ) + .on_press(Message::TabContextAction(entity, action)) }; let menu_checkbox = |label, value, action| { @@ -51,16 +70,16 @@ pub fn context_menu<'a>(config: &Config, entity: segmented_button::Entity) -> El }; widget::container(column!( - menu_action(fl!("copy"), Action::Copy), - menu_action(fl!("paste"), Action::Paste), - menu_action(fl!("select-all"), Action::SelectAll), + menu_item(fl!("copy"), Action::Copy), + menu_item(fl!("paste"), Action::Paste), + menu_item(fl!("select-all"), Action::SelectAll), horizontal_rule(1), - menu_action(fl!("split-horizontal"), Action::PaneSplitHorizontal), - menu_action(fl!("split-vertical"), Action::PaneSplitVertical), - menu_action(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized), + menu_item(fl!("split-horizontal"), Action::PaneSplitHorizontal), + menu_item(fl!("split-vertical"), Action::PaneSplitVertical), + menu_item(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized), horizontal_rule(1), - menu_action(fl!("new-tab"), Action::TabNew), - menu_action(fl!("menu-settings"), Action::Settings), + menu_item(fl!("new-tab"), Action::TabNew), + menu_item(fl!("menu-settings"), Action::Settings), menu_checkbox( fl!("show-headerbar"), config.show_headerbar,