diff options
Diffstat (limited to '')
-rw-r--r-- | terminal.ui | 1 | ||||
-rw-r--r-- | terminal.vala | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/terminal.ui b/terminal.ui index 6d5d206..af94317 100644 --- a/terminal.ui +++ b/terminal.ui @@ -139,6 +139,7 @@ <signal name="button-press-event" handler="vte_button_press" swapped="no"/> <signal name="button-release-event" handler="vte_button_release" swapped="no"/> <signal name="child-exited" handler="gtk_main_quit" swapped="no"/> + <signal name="drag-data-received" handler="vte_drag_data_received" swapped="no"/> <signal name="hyperlink-hover-uri-changed" handler="vte_hyperlink_hover" swapped="no"/> <signal name="key-press-event" handler="vte_key_press" swapped="no"/> <signal name="scroll-event" handler="vte_scroll" swapped="no"/> diff --git a/terminal.vala b/terminal.vala index 67256d4..fcb456c 100644 --- a/terminal.vala +++ b/terminal.vala @@ -70,6 +70,13 @@ class Terminal : Gtk.Overlay { uri_context_menu.attach_to_widget(vte, null); standard_context_menu.attach_to_widget(vte, null); + Gtk.TargetList targets = new Gtk.TargetList({}); + targets.add_text_targets(0); + targets.add_uri_targets(1); + + Gtk.drag_dest_set(vte, Gtk.DestDefaults.ALL, {}, Gdk.DragAction.COPY); + Gtk.drag_dest_set_target_list(vte, targets); + clipboard = Gtk.Clipboard.get_default(window.get_display()); primary = Gtk.Clipboard.get_for_display(window.get_display(), Gdk.SELECTION_PRIMARY); @@ -591,4 +598,31 @@ class Terminal : Gtk.Overlay { window.set_urgency_hint(false); window.set_urgency_hint(true); } + + [GtkCallback] + void vte_drag_data_received(Gdk.DragContext context, int x, int y, Gtk.SelectionData selection_data, uint info, uint time_) { + if (info == 0) { + string text = selection_data.get_text(); + + if (text != null) { + vte.paste_text(text); + } + } else if (info == 1) { + string[] uris = selection_data.get_uris(); + string text = ""; + + foreach (var uri in uris) { + if (uri == null || uri.length == 0) + continue; + + if (uri.has_prefix("file://")) { + uri = Shell.quote(Uri.unescape_string(uri.substring(7))); + } + + text = string.join(" ", text, uri); + } + + vte.paste_text(text.strip()); + } + } } |