aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/terminal.vala
diff options
context:
space:
mode:
authorJuhani Krekelä2021-07-24 19:15:13 +0300
committerWolfgang Müller2021-11-27 14:05:19 +0100
commita9706ec27edc0aef03f72daba28647aca1c42070 (patch)
treea6589cc410f91fb45e1093423fde9170de43e83f /terminal.vala
parent78e1e14fa676a6c995d9dc61ad038a9906f37bf7 (diff)
downloadweltschmerz-a9706ec27edc0aef03f72daba28647aca1c42070.tar.gz
Add ability to specify additional URI handlers
This commit adds a new section, open-with, to the configuration file. The options specified there will be added as "Open with …" menu items in the URI context menu. This is to make it easier to perform other actions on the URI than opening it in the system default browser; a user might for example add another browser, media player, or a script that preprocesses the URI before opening it.
Diffstat (limited to '')
-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));
}