Skip to content

Instantly share code, notes, and snippets.

@nathanielcook
Created September 30, 2016 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanielcook/5ed019bb523187794c2b7c50d7a51138 to your computer and use it in GitHub Desktop.
Save nathanielcook/5ed019bb523187794c2b7c50d7a51138 to your computer and use it in GitHub Desktop.
NoCmdClickTextEditorExtension.cs
public class NoCmdClickTextEditorExtension : TextEditorExtension
{
static PropertyInfo textEditorExtensionChainProperty;
static PropertyInfo nextProperty;
static PropertyInfo linksShownProperty;
static NoCmdClickTextEditorExtension()
{
textEditorExtensionChainProperty = typeof(TextEditor).GetProperty("TextEditorExtensionChain", BindingFlags.NonPublic | BindingFlags.Instance);
nextProperty = typeof(TextEditorExtension).GetProperty("Next", BindingFlags.NonPublic | BindingFlags.Instance);
linksShownProperty = typeof(AbstractNavigationExtension).GetProperty("LinksShown", BindingFlags.NonPublic | BindingFlags.Static);
Gtk.Key.SnooperInstall(KeySnooper);
}
static int KeySnooper(Gtk.Widget widget, Gdk.EventKey evnt)
{
if (evnt != null && evnt.Type == Gdk.EventType.KeyPress && evnt.Key == Gdk.Key.Meta_L || evnt.Key == Gdk.Key.Meta_R)
{
SetLinksShownToFalse();
}
return 0; // false, continue processing this event
}
protected override void Initialize()
{
this.Editor.MouseMoved += Editor_MouseMoved;
}
void Editor_MouseMoved(object sender, MouseMovedEventArgs e)
{
SetLinksShownToFalse();
}
public override void Dispose()
{
this.Editor.MouseMoved -= Editor_MouseMoved;
base.Dispose();
}
static void SetLinksShownToFalse()
{
var editor = IdeApp.Workbench.ActiveDocument.Editor;
if (editor != null)
{
var firstExtension = GetTextEditorExtensionChain(editor);
TextEditorExtension nextExtension = firstExtension;
do
{
var nextExtensionType = nextExtension.GetType();
if (nextExtensionType.Name == "CSharpNavigationTextEditorExtension")
{
linksShownProperty.SetValue(nextExtension, false);
break;
}
} while ((nextExtension = GetNextExtension(nextExtension)) != null);
}
}
static TextEditorExtension GetTextEditorExtensionChain(TextEditor editor)
{
return (TextEditorExtension)textEditorExtensionChainProperty.GetValue(editor);
}
static TextEditorExtension GetNextExtension(TextEditorExtension thisExtension)
{
return (TextEditorExtension)nextProperty.GetValue(thisExtension);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment