aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/terminal.vala
diff options
context:
space:
mode:
Diffstat (limited to 'terminal.vala')
-rw-r--r--terminal.vala40
1 files changed, 40 insertions, 0 deletions
diff --git a/terminal.vala b/terminal.vala
index 0013abd..c392d7f 100644
--- a/terminal.vala
+++ b/terminal.vala
@@ -32,11 +32,14 @@ class Terminal : Gtk.Overlay {
[GtkChild] unowned Gtk.Revealer search_revealer;
[GtkChild] unowned Gtk.ScrolledWindow scrolled_window;
[GtkChild] unowned Gtk.SearchEntry search_entry;
+ [GtkChild] unowned Gtk.SeparatorMenuItem open_with_separator;
[GtkChild] unowned Vte.Terminal vte;
Gtk.Clipboard clipboard;
Gtk.Clipboard primary;
Gtk.Settings settings;
+ Gtk.MenuItem[] open_with_items = {};
+
bool has_search;
bool overlay_scrolling_env_override;
string url_match;
@@ -135,6 +138,21 @@ class Terminal : Gtk.Overlay {
vte.set_color_highlight_foreground(conf.selection_foreground);
vte.set_color_highlight(conf.selection_background);
+ foreach (var item in open_with_items) {
+ uri_context_menu.remove(item);
+ }
+ open_with_items.resize(0);
+
+ foreach(var program in conf.open_with_programs) {
+ // TRANSLATORS: %s is the name of a "open with …" program set by the user in the configuration
+ var item = new Gtk.MenuItem.with_label(_("Open with %s").printf(program.name));
+ item.activate.connect(() => { uri_open_with(program.command); });
+ item.set_visible(true);
+ open_with_items += item;
+ uri_context_menu.add(item);
+ }
+ open_with_separator.set_visible(conf.open_with_programs.length > 0);
+
if (conf.get_warnings().length > 0) {
string header = "<b>%s</b>\n".printf(_("Configuration loaded with warnings:"));
infobar_show(header + string.joinv("\n", conf.get_warnings()), Gtk.MessageType.WARNING);
@@ -316,6 +334,28 @@ class Terminal : Gtk.Overlay {
}
}
+ void uri_open_with(string[] command) {
+ string uri;
+ if (url_match != null) {
+ uri = url_match;
+ } else if (hyperlink_match != null) {
+ uri = hyperlink_match;
+ } else {
+ return;
+ }
+
+ string[] argv = {};
+ foreach (var arg in command) {
+ if (arg == "%") {
+ argv += uri;
+ } else {
+ argv += arg;
+ }
+ }
+
+ spawn_process(null, argv);
+ }
+
void adjust_font_scale(double scale) {
vte.set_font_scale(scale.clamp(FONT_SCALE_MIN, FONT_SCALE_MAX));
}