Commit 90ab8833 authored by Victor Ananjevsky's avatar Victor Ananjevsky

add custom uri handler

parent 2820676b
......@@ -170,6 +170,9 @@ Print result for any of the return codes. This option doesn't work if timeout wa
All commands runs unter specified interpreter. Default is \fIbash -c '%s'\fP. This option can reduse quoting in commands. If \fI%s\fP is specified, it will be replaced by the command.
Otherwise command will be appended to the end of command line.
.TP
.B \-\-uri-handler=\fICMD\fP
Use \fICMD\fP as uri handler. By default yad uses \fIopen-command\fP parameter from settings. URI adds to the end of specified command-line.
.TP
.B \-\-borders=\fINUM\fP
Set dialog window borders.
.TP
......@@ -973,7 +976,7 @@ This options applies to all of yad's file chooser dialogs.
Add preview widget. Preview images loads from normal (default) or large thumbnails according to XDG Thumbnails
specification v0.8.0 (http://standards.freedesktop.org/thumbnail-spec/latest/) or creates by yad for image files and saves
as normal or large thumbnails.
.TP
.TP
.B \-\-large-preview
Use large previews by default. This option can be permanently turned on through yad settings.
.TP
......
......@@ -632,6 +632,13 @@ select_date_cb (GtkEntry * entry, GtkEntryIconPosition pos, GdkEventButton * eve
gtk_widget_grab_focus (GTK_WIDGET (entry));
}
static void
link_clicked_cb (GtkLinkButton *btn, gpointer data)
{
const gchar *uri = gtk_link_button_get_uri (btn);
open_uri (uri);
}
static gboolean
handle_stdin (GIOChannel * ch, GIOCondition cond, gpointer data)
{
......@@ -971,6 +978,7 @@ form_create_widget (GtkWidget * dlg)
gchar *buf = g_strcompress (fld->name[0] ? fld->name : _("Link"));
e = gtk_link_button_new_with_label ("", buf);
gtk_widget_set_name (e, "yad-form-link");
g_signal_connect (G_OBJECT (e), "activate-link", G_CALLBACK (link_clicked_cb), NULL);
gtk_grid_attach (GTK_GRID (tbl), e, col * 2, row, 2, 1);
gtk_widget_set_hexpand (e, TRUE);
fields = g_slist_append (fields, e);
......
......@@ -144,6 +144,8 @@ static GOptionEntry general_options[] = {
N_("Don't scale icons"), NULL },
{ "use-interp", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, set_interp,
N_("Run commands under specified interpreter (default: bash -c '%s')"), N_("CMD") },
{ "uri-handler", 0, 0, G_OPTION_ARG_STRING, &options.data.uri_handler,
N_("Set URI handler"), N_("CMD") },
/* window settings */
{ "sticky", 0, 0, G_OPTION_ARG_NONE, &options.data.sticky,
N_("Set window sticky"), NULL },
......@@ -1510,6 +1512,11 @@ yad_options_init (void)
options.data.def_resp = YAD_RESPONSE_OK;
options.data.use_interp = FALSE;
options.data.interp = "bash -c '%s'";
#ifndef STANDALONE
options.data.uri_handler = g_settings_get_string (settings, "open-command");
#else
options.data.uri_handler = OPEN_CMD;
#endif
/* Initialize window options */
options.data.sticky = FALSE;
......
......@@ -159,7 +159,7 @@ tag_event_cb (GtkTextTag * tag, GObject * obj, GdkEvent * ev, GtkTextIter * iter
{
GtkTextIter start = *iter;
GtkTextIter end = *iter;
gchar *url, *cmdline;
gchar *url;
if (ev->type == GDK_BUTTON_PRESS)
{
......@@ -171,16 +171,9 @@ tag_event_cb (GtkTextTag * tag, GObject * obj, GdkEvent * ev, GtkTextIter * iter
gtk_text_iter_forward_to_tag_toggle (&end, tag);
url = gtk_text_iter_get_text (&start, &end);
#ifndef STANDALONE
cmdline = g_strdup_printf (g_settings_get_string (settings, "open-command"), url);
#else
cmdline = g_strdup_printf (OPEN_CMD, url);
#endif
open_uri (url);
g_free (url);
run_command_async (cmdline);
g_free (cmdline);
return TRUE;
}
}
......
......@@ -781,6 +781,19 @@ pango_to_css (gchar *font)
return res;
}
void
open_uri (gchar *uri)
{
gchar *cmdline;
if (!uri && !uri[0])
return;
cmdline = g_strdup_printf ("%s '$s'", options.data.uri_handler, uri);
run_command_async (cmdline);
g_free (cmdline);
}
#ifdef HAVE_SPELL
void
show_langs ()
......
......@@ -236,6 +236,7 @@ typedef struct {
gint def_resp;
gboolean use_interp;
gchar *interp;
gchar *uri_handler;
/* window settings */
gboolean sticky;
gboolean fixed;
......@@ -663,6 +664,8 @@ void run_command_async (gchar *cmd);
gchar * pango_to_css (gchar *font);
void open_uri (gchar *uri);
#ifdef HAVE_SPELL
void show_langs ();
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment