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 | |
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.
-rw-r--r-- | terminal.ui | 24 | ||||
-rw-r--r-- | terminal.vala | 17 | ||||
-rw-r--r-- | weltschmerz.1 | 8 |
3 files changed, 48 insertions, 1 deletions
diff --git a/terminal.ui b/terminal.ui index 4618d40..257dcbb 100644 --- a/terminal.ui +++ b/terminal.ui @@ -47,6 +47,11 @@ </object> </child> </object> + <object class="GtkImage" id="open_directory_item_image"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="stock">gtk-open</property> + </object> <object class="GtkImage" id="search_image_down"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -262,5 +267,24 @@ <accelerator key="v" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/> </object> </child> + <child> + <object class="GtkSeparatorMenuItem" id="separator"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + </child> + <child> + <object class="GtkImageMenuItem" id="open_directory_item"> + <property name="label" translatable="yes">_Open directory</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="tooltip_text" translatable="yes">Open current directory in the file manager</property> + <property name="use_underline">True</property> + <property name="image">open_directory_item_image</property> + <property name="use_stock">False</property> + <signal name="activate" handler="open_directory" swapped="no"/> + <accelerator key="o" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/> + </object> + </child> </object> </interface> 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 . |