/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; _textEditorEvents = _applicationObject.Events.TextEditorEvents; _lineChangedEventHandler = new _dispTextEditorEvents_LineChangedEventHandler(Connect_LineChanged); _precomplete = new Precomplete(); }
private void bindTextEditorEvents() { if (_textEditorEvents != null) { return; } _textEditorEvents = _applicationObject.Events.TextEditorEvents; _lineChangedEvent = new _dispTextEditorEvents_LineChangedEventHandler(TextEditorEvents_OnLineChanged); _textEditorEvents.LineChanged += _lineChangedEvent; }
private void RegisterEvents(object sender = null, EventArgs e = null) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (((Config)mPlugin.Options).AutoCheckoutOnEdit) { if (_registeredCommands == null) { Log.Info("Adding handlers for automatically checking out text files as you edit them"); _registeredCommands = new List <string>(); var events = (EnvDTE80.Events2)mPlugin.App.Events; mTextDocEvents = events.get_TextDocumentKeyPressEvents(null); _beforeKeyPressEventHandler = new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(OnBeforeKeyPress); mTextDocEvents.BeforeKeyPress += _beforeKeyPressEventHandler; mTextEditorEvents = events.get_TextEditorEvents(null); _lineChangedEventHandler = new _dispTextEditorEvents_LineChangedEventHandler(OnLineChanged); mTextEditorEvents.LineChanged += _lineChangedEventHandler; foreach (string command in _commands) { if (RegisterHandler(command, OnCheckoutCurrentDocument)) { _registeredCommands.Add(command); } else { Log.Warning("Failed to register {0} to command '{1}'", nameof(OnCheckoutCurrentDocument), command); } } } } else if (_registeredCommands != null) { Log.Info("Removing handlers for automatically checking out text files as you edit them"); foreach (string command in _registeredCommands) { UnregisterHandler(command, OnCheckoutCurrentDocument); } _registeredCommands = null; mTextEditorEvents.LineChanged -= _lineChangedEventHandler; mTextEditorEvents = null; mTextDocEvents.BeforeKeyPress -= _beforeKeyPressEventHandler; mTextDocEvents = null; } }
private void bindTextEditorEvents() { if (_textEditorEvents != null) return; _textEditorEvents = _applicationObject.Events.TextEditorEvents; _lineChangedEvent = new _dispTextEditorEvents_LineChangedEventHandler(TextEditorEvents_OnLineChanged); _textEditorEvents.LineChanged += _lineChangedEvent; }