diff --git a/src/components/context_menu_bin.rs b/src/components/context_menu_bin.rs index 5fa8a958..e9f8c501 100644 --- a/src/components/context_menu_bin.rs +++ b/src/components/context_menu_bin.rs @@ -1,7 +1,7 @@ use adw::subclass::prelude::*; use gtk::{gdk, glib, glib::clone, prelude::*, CompositeTemplate}; -use crate::utils::BoundObject; +use crate::utils::{key_bindings, BoundObject}; mod imp { use std::cell::{Cell, RefCell}; @@ -62,16 +62,7 @@ mod imp { klass.install_action("context-menu.activate", None, |obj, _, _| { obj.open_menu_at(0, 0); }); - klass.add_binding_action( - gdk::Key::F10, - gdk::ModifierType::SHIFT_MASK, - "context-menu.activate", - ); - klass.add_binding_action( - gdk::Key::Menu, - gdk::ModifierType::empty(), - "context-menu.activate", - ); + key_bindings::add_context_menu_bindings(klass, "context-menu.activate"); klass.install_action("context-menu.close", None, |obj, _, _| { if let Some(popover) = obj.popover() { diff --git a/src/session/view/content/room_history/message_row/reaction/mod.rs b/src/session/view/content/room_history/message_row/reaction/mod.rs index 9d92ff70..caccc027 100644 --- a/src/session/view/content/room_history/message_row/reaction/mod.rs +++ b/src/session/view/content/room_history/message_row/reaction/mod.rs @@ -11,7 +11,7 @@ use crate::{ model::{Member, MemberList, ReactionData, ReactionGroup}, view::content::room_history::member_timestamp::MemberTimestamp, }, - utils::{BoundObjectWeakRef, EMOJI_REGEX}, + utils::{key_bindings, BoundObjectWeakRef, EMOJI_REGEX}, }; mod imp { @@ -69,6 +69,11 @@ mod imp { fn class_init(klass: &mut Self::Class) { Self::bind_template(klass); Self::bind_template_callbacks(klass); + + klass.install_action("reaction.show-popover", None, |obj, _, _| { + obj.imp().show_popover(); + }); + key_bindings::add_context_menu_bindings(klass, "reaction.show-popover"); } fn instance_init(obj: &InitializingObject) { diff --git a/src/utils/key_bindings.rs b/src/utils/key_bindings.rs index b9d58dc9..7c0cdf68 100644 --- a/src/utils/key_bindings.rs +++ b/src/utils/key_bindings.rs @@ -4,7 +4,7 @@ use gtk::{gdk, subclass::prelude::*}; /// List of keys that activate a widget. // Copied from GtkButton's source code. -pub(crate) const ACTIVATE_KEYS: &[gdk::Key] = &[ +const ACTIVATE_KEYS: &[gdk::Key] = &[ gdk::Key::space, gdk::Key::KP_Space, gdk::Key::Return, @@ -12,10 +12,24 @@ pub(crate) const ACTIVATE_KEYS: &[gdk::Key] = &[ gdk::Key::KP_Enter, ]; -/// Activate the given action when one of the [`ACTIVATE_KEYS`] binding is -/// triggered. +/// Add key bindings to the given class to trigger the given action to activate +/// a widget. pub(crate) fn add_activate_bindings(klass: &mut T, action: &str) { for key in ACTIVATE_KEYS { klass.add_binding_action(*key, gdk::ModifierType::empty(), action); } } + +/// List of key and modifier combos that trigger a context menu to appear. +const CONTEXT_MENU_BINDINGS: &[(gdk::Key, gdk::ModifierType)] = &[ + (gdk::Key::F10, gdk::ModifierType::SHIFT_MASK), + (gdk::Key::Menu, gdk::ModifierType::empty()), +]; + +/// Add key bindings to the given class to trigger the given action to show a +/// context menu. +pub(crate) fn add_context_menu_bindings(klass: &mut T, action: &str) { + for (key, modifier) in CONTEXT_MENU_BINDINGS { + klass.add_binding_action(*key, *modifier, action); + } +}