From 948460c9d0a1c4b90ed2b0d790365758f2fa73e3 Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Sat, 28 Mar 2020 22:09:10 +0100 Subject: 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. --- terminal.ui | 24 ++++++++++++++++++++++++ terminal.vala | 17 ++++++++++++++++- weltschmerz.1 | 8 ++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/terminal.ui b/terminal.ui index 4618d40..257dcbb 100644 --- a/terminal.ui +++ b/terminal.ui @@ -47,6 +47,11 @@ + + True + False + gtk-open + True False @@ -262,5 +267,24 @@ + + + True + False + + + + + _Open directory + True + False + Open current directory in the file manager + True + open_directory_item_image + False + + + + 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; diff --git a/weltschmerz.1 b/weltschmerz.1 index f2481c8..b73ca30 100644 --- a/weltschmerz.1 +++ b/weltschmerz.1 @@ -44,6 +44,14 @@ and .Sy CTRL + - . It can be reset to its default value with .Sy CTRL + 0 . +.Pp +The program's current directory can be opened in the default file manager with +.Sy CTRL + Shift + O . +Note that +.Nm +relies on proper support of OSC 7 to do this. +If the child program (such as the shell or an editor) does not send OSC 7, +this feature will not work. .Sh SEARCH OVERLAY The search overlay can be opened by pressing .Sy CTRL + Shift + F . -- cgit v1.2.3-2-gb3c3