781
781
[DllImport("gtksharpglue-2", CallingConvention=CallingConvention.Cdecl)]
782
782
static extern void gtksharp_container_override_forall (IntPtr gtype, ForallDelegate cb);
784
public static string MarkupLinks (string text)
786
if (Mono.TextEditor.GtkWorkarounds.GtkMinorVersion < 18)
788
return HighlightUrlSemanticRule.UrlRegex.Replace (text, MatchToUrl);
791
static string MatchToUrl (System.Text.RegularExpressions.Match m)
793
var s = m.ToString ();
794
return String.Format ("<a href='{0}'>{1}</a>", s, s.Replace ("_", "__"));
797
public static void SetLinkHandler (this Gtk.Label label, Action<string> urlHandler)
799
if (Mono.TextEditor.GtkWorkarounds.GtkMinorVersion >= 18)
800
new UrlHandlerClosure (urlHandler).ConnectTo (label);
803
//create closure manually so we can apply ConnectBefore
804
class UrlHandlerClosure
806
Action<string> urlHandler;
808
public UrlHandlerClosure (Action<string> urlHandler)
810
this.urlHandler = urlHandler;
814
void HandleLink (object sender, ActivateLinkEventArgs args)
816
urlHandler (args.Url);
820
public void ConnectTo (Gtk.Label label)
822
var signal = GLib.Signal.Lookup (label, "activate-link", typeof(ActivateLinkEventArgs));
823
signal.AddDelegate (new EventHandler<ActivateLinkEventArgs> (HandleLink));
826
class ActivateLinkEventArgs : GLib.SignalArgs
828
public string Url { get { return (string)base.Args [0]; } }
785
833
public struct KeyboardShortcut : IEquatable<KeyboardShortcut>