Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/Widgets/Terminal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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 (() => {
Expand Down