diff options
author | Wynn Wolf Arbor | 2020-03-28 22:09:10 +0100 |
---|---|---|
committer | Wynn Wolf Arbor | 2020-04-13 15:45:45 +0200 |
commit | 948460c9d0a1c4b90ed2b0d790365758f2fa73e3 (patch) | |
tree | 226bbd13cd727189464a3d0adb6fee058699794f /terminal.vala | |
parent | ec211bccdcfb5bfabd03f6bcff8df02bb5eab266 (diff) | |
download | weltschmerz-948460c9d0a1c4b90ed2b0d790365758f2fa73e3.tar.gz |
Add Open directory feature
VTE can leverage the child program's support of OSC 7 to keep track of
the current directory. This commit adds support for opening said
directory in the default file manager, either by using a shortcut or by
activating a new entry in the context menu.
Diffstat (limited to 'terminal.vala')
-rw-r--r-- | terminal.vala | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/terminal.vala b/terminal.vala index c7a2c81..c963a75 100644 --- a/terminal.vala +++ b/terminal.vala @@ -28,6 +28,7 @@ class Terminal : Gtk.Overlay { [GtkChild] Gtk.Menu hyperlink_context_menu; [GtkChild] Gtk.MenuItem copy_item_text; [GtkChild] Gtk.MenuItem copy_item_html; + [GtkChild] Gtk.MenuItem open_directory_item; [GtkChild] Gtk.Revealer search_revealer; [GtkChild] Gtk.ScrolledWindow scrolled_window; [GtkChild] Gtk.SearchEntry search_entry; @@ -274,7 +275,10 @@ class Terminal : Gtk.Overlay { search_button_down.set_sensitive(has_search); } - void uri_open(string uri) { + void uri_open(string? uri) { + if (uri == null) + return; + try { AppInfo.launch_default_for_uri(uri, get_display().get_app_launch_context()); } catch (Error e) { @@ -304,6 +308,11 @@ class Terminal : Gtk.Overlay { adjust_font_scale(vte.get_font_scale() / FONT_SCALE_FACTOR); } + [GtkCallback] + void open_directory() { + uri_open(vte.get_current_directory_uri()); + } + void vte_copy(bool html = false) { if (vte.get_has_selection()) { vte.copy_clipboard_format(html ? Vte.Format.HTML : Vte.Format.TEXT); @@ -328,6 +337,7 @@ class Terminal : Gtk.Overlay { } else { copy_item_text.set_sensitive(vte.get_has_selection()); copy_item_html.set_sensitive(vte.get_has_selection()); + open_directory_item.set_sensitive(vte.get_current_directory_uri() != null); standard_context_menu.popup_at_pointer(event); } return true; @@ -377,6 +387,11 @@ class Terminal : Gtk.Overlay { return true; } + if (match_key(event, CONTROL_MASK | SHIFT_MASK, Gdk.Key.O)) { + open_directory(); + return true; + } + if (match_key(event, CONTROL_MASK, Gdk.Key.@0)) { vte.set_font_scale(1.0); return true; |