[longomatch] Add a workaround to set a URL Handler for GtkLabel
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add a workaround to set a URL Handler for GtkLabel
- Date: Sat, 29 Nov 2014 15:02:29 +0000 (UTC)
commit 2c51e83b3fce5800621959d88e8c35d0c5f371b2
Author: Julien Moutte <julien fluendo com>
Date: Sat Nov 29 12:30:02 2014 +0100
Add a workaround to set a URL Handler for GtkLabel
LongoMatch.GUI/Gui/GtkGlue.cs | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/GtkGlue.cs b/LongoMatch.GUI/Gui/GtkGlue.cs
index 99e659b..56fed75 100644
--- a/LongoMatch.GUI/Gui/GtkGlue.cs
+++ b/LongoMatch.GUI/Gui/GtkGlue.cs
@@ -30,6 +30,44 @@ namespace LongoMatch
public static void MenuItemSetLabel (MenuItem menu, string label) {
gtk_menu_item_set_label (menu.Handle, GLib.Marshaller.StringToFilenamePtr (label));
}
+
+ /// <summary>
+ /// Sets the link handler for a given GtkLabel.
+ /// </summary>
+ /// <param name="label">GtkLabel to set the handler for.</param>
+ /// <param name="urlHandler">URL handler.</param>
+ public static void SetLinkHandler (Gtk.Label label, Action<string> urlHandler)
+ {
+ new UrlHandlerClosure (urlHandler).ConnectTo (label);
+ }
+
+ class UrlHandlerClosure
+ {
+ Action<string> urlHandler;
+
+ public UrlHandlerClosure (Action<string> urlHandler)
+ {
+ this.urlHandler = urlHandler;
+ }
+
+ [GLib.ConnectBefore]
+ void HandleLink (object sender, ActivateLinkEventArgs args)
+ {
+ urlHandler (args.Url);
+ args.RetVal = true;
+ }
+
+ public void ConnectTo (Gtk.Label label)
+ {
+ var signal = GLib.Signal.Lookup (label, "activate-link",
typeof(ActivateLinkEventArgs));
+ signal.AddDelegate (new EventHandler<ActivateLinkEventArgs> (HandleLink));
+ }
+
+ class ActivateLinkEventArgs : GLib.SignalArgs
+ {
+ public string Url { get { return (string)base.Args [0]; } }
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]