[geany/geany-plugins] 8100ee: Geniuspaste: Install a custom URL handler for Paste link

Enrico Tröger git-noreply at xxxxx
Sat Mar 12 14:26:59 UTC 2016


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sat, 12 Mar 2016 14:26:59 UTC
Commit:      8100ee52f5481a84f3e9fdaeee7af2e73e06adea
             https://github.com/geany/geany-plugins/commit/8100ee52f5481a84f3e9fdaeee7af2e73e06adea

Log Message:
-----------
Geniuspaste: Install a custom URL handler for Paste link

This workarounds a strange crash on Windows when the default GTK
URL handler is called.
We need the URL handler only on the secondary text label but we
cannot access it directly, so iterate over all labels of the message
dialog's message area and attach the custom handler to all of the
labels. This shouldn't harm much as only the secondary label contains
a link.


Modified Paths:
--------------
    geniuspaste/src/geniuspaste.c

Modified: geniuspaste/src/geniuspaste.c
24 lines changed, 24 insertions(+), 0 deletions(-)
===================================================================
@@ -578,12 +578,30 @@ static gchar *pastebin_parse_response(const Pastebin  *pastebin,
     return url;
 }
 
+static gboolean message_dialog_label_link_activated(GtkLabel *label, gchar *uri, gpointer user_data)
+{
+    utils_open_browser(uri);
+    return TRUE;
+}
+
+static void message_dialog_label_set_url_hook(GtkWidget *widget, gpointer data)
+{
+    if (GTK_IS_LABEL(widget))
+    {
+        g_signal_connect(widget,
+                         "activate-link",
+                         G_CALLBACK(message_dialog_label_link_activated),
+                         NULL);
+    }
+}
+
 G_GNUC_PRINTF (4, 5)
 static void show_msgbox(GtkMessageType type, GtkButtonsType buttons,
                         const gchar *main_text,
                         const gchar *secondary_markup, ...)
 {
     GtkWidget *dlg;
+    GtkWidget *dlg_vbox;
     va_list ap;
     gchar *markup;
 
@@ -601,6 +619,12 @@ static void show_msgbox(GtkMessageType type, GtkButtonsType buttons,
                        "secondary-text", markup,
                        "secondary-use-markup", TRUE,
                        NULL);
+    /* fetch the message area of the dialog and attach a custom URL hook to the labels */
+    dlg_vbox = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dlg));
+    gtk_container_foreach(GTK_CONTAINER(dlg_vbox),
+                          message_dialog_label_set_url_hook,
+                          NULL);
+    /* run the dialog */
     gtk_dialog_run(GTK_DIALOG(dlg));
     gtk_widget_destroy(dlg);
 }



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list