diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala index 7b445eaab..5ad91bec9 100644 --- a/src/Widgets/Terminal.vala +++ b/src/Widgets/Terminal.vala @@ -6,7 +6,6 @@ public class Code.Terminal : Gtk.Box { public const string ACTION_GROUP = "term"; - public const string ACTION_PREFIX = ACTION_GROUP + "."; public const string ACTION_COPY = "action-copy"; public const string ACTION_PASTE = "action-paste"; @@ -35,6 +34,8 @@ public class Code.Terminal : Gtk.Box { private GLib.Pid child_pid; private Gtk.Clipboard current_clipboard; + private Gtk.GestureMultiPress secondary_button_controller; + private Menu menu_model; private Scratch.Application application; @@ -128,14 +129,18 @@ public class Code.Terminal : Gtk.Box { actions = new SimpleActionGroup (); actions.add_action (copy_action); actions.add_action (paste_action); + terminal.insert_action_group (ACTION_GROUP, actions); - var menu_model = new GLib.Menu (); - menu_model.append (_("Copy"), ACTION_PREFIX + ACTION_COPY); - menu_model.append (_("Paste"), ACTION_PREFIX + ACTION_PASTE); + menu_model = new GLib.Menu (); + menu_model.append (_("Copy"), ACTION_COPY); + menu_model.append (_("Paste"), ACTION_PASTE); - var menu = new Gtk.Menu.from_model (menu_model); - menu.insert_action_group (ACTION_GROUP, actions); - menu.show_all (); + var menu = new Gtk.PopoverMenu () { + modal = true, + relative_to = terminal, + position = RIGHT + }; + menu.bind_model (menu_model, ACTION_GROUP); key_controller = new Gtk.EventControllerKey (terminal) { propagation_phase = BUBBLE @@ -146,17 +151,17 @@ public class Code.Terminal : Gtk.Box { terminal.enter_notify_event.connect (() => { if (!terminal.has_focus) { terminal.grab_focus (); - } }); - terminal.button_press_event.connect ((event) => { - if (event.button == 3) { - paste_action.set_enabled (current_clipboard.wait_is_text_available ()); - menu.select_first (false); - menu.popup_at_pointer (event); - } - return false; + secondary_button_controller = new Gtk.GestureMultiPress (terminal) { + propagation_phase = CAPTURE, + button = Gdk.BUTTON_SECONDARY + }; + secondary_button_controller.pressed.connect ((n, x, y) => { + paste_action.set_enabled (current_clipboard.wait_is_text_available ()); + menu.pointing_to = Gdk.Rectangle () {x = (int)x, y = (int)y, height = 1, width = 1}; + menu.popup (); }); realize.connect (() => {