Show shortcuts in context menu
This commit is contained in:
parent
a2e0d527c4
commit
6d519018a0
4 changed files with 33 additions and 13 deletions
|
|
@ -51,7 +51,7 @@ next-tab = Next tab
|
||||||
previous-tab = Previous tab
|
previous-tab = Previous tab
|
||||||
split-horizontal = Split horizontal
|
split-horizontal = Split horizontal
|
||||||
split-vertical = Split vertical
|
split-vertical = Split vertical
|
||||||
pane-toggle-maximize = Toggle pane maximized
|
pane-toggle-maximize = Toggle maximized
|
||||||
menu-settings = Settings...
|
menu-settings = Settings...
|
||||||
|
|
||||||
# Context menu
|
# Context menu
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ impl fmt::Display for KeyBind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: load from config
|
||||||
pub fn key_binds() -> HashMap<KeyBind, Action> {
|
pub fn key_binds() -> HashMap<KeyBind, Action> {
|
||||||
let mut key_binds = HashMap::new();
|
let mut key_binds = HashMap::new();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1415,7 +1415,7 @@ impl Application for App {
|
||||||
let tab_element: Element<'_, Message> = match context_menu {
|
let tab_element: Element<'_, Message> = match context_menu {
|
||||||
Some(position) => widget::popover(
|
Some(position) => widget::popover(
|
||||||
terminal_box.context_menu(position),
|
terminal_box.context_menu(position),
|
||||||
menu::context_menu(&self.config, entity),
|
menu::context_menu(&self.config, &self.key_binds, entity),
|
||||||
)
|
)
|
||||||
.position(position)
|
.position(position)
|
||||||
.into(),
|
.into(),
|
||||||
|
|
|
||||||
41
src/menu.rs
41
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> {
|
pub fn context_menu<'a>(
|
||||||
let menu_action = |label, action| {
|
config: &Config,
|
||||||
menu_button!(widget::text(label)).on_press(Message::TabContextAction(entity, action))
|
key_binds: &HashMap<KeyBind, Action>,
|
||||||
|
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| {
|
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!(
|
widget::container(column!(
|
||||||
menu_action(fl!("copy"), Action::Copy),
|
menu_item(fl!("copy"), Action::Copy),
|
||||||
menu_action(fl!("paste"), Action::Paste),
|
menu_item(fl!("paste"), Action::Paste),
|
||||||
menu_action(fl!("select-all"), Action::SelectAll),
|
menu_item(fl!("select-all"), Action::SelectAll),
|
||||||
horizontal_rule(1),
|
horizontal_rule(1),
|
||||||
menu_action(fl!("split-horizontal"), Action::PaneSplitHorizontal),
|
menu_item(fl!("split-horizontal"), Action::PaneSplitHorizontal),
|
||||||
menu_action(fl!("split-vertical"), Action::PaneSplitVertical),
|
menu_item(fl!("split-vertical"), Action::PaneSplitVertical),
|
||||||
menu_action(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized),
|
menu_item(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized),
|
||||||
horizontal_rule(1),
|
horizontal_rule(1),
|
||||||
menu_action(fl!("new-tab"), Action::TabNew),
|
menu_item(fl!("new-tab"), Action::TabNew),
|
||||||
menu_action(fl!("menu-settings"), Action::Settings),
|
menu_item(fl!("menu-settings"), Action::Settings),
|
||||||
menu_checkbox(
|
menu_checkbox(
|
||||||
fl!("show-headerbar"),
|
fl!("show-headerbar"),
|
||||||
config.show_headerbar,
|
config.show_headerbar,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue