public void OnConnect(DTE2 applicationObject) { ApplicationObject = applicationObject; DocumentManager.BeforeKeyPress = OnBeforeKeyPress; DocumentManager.AfterKeyPress = OnAfterKeyPress; DocumentManager.Setup(applicationObject); var events = (Events2)applicationObject.Events; solutionEvents = events.SolutionEvents; projectItemEvents = events.ProjectItemsEvents; textEditorEvents = events.get_TextEditorEvents(null); documentEvents = events.DocumentEvents; dteEvents = events.DTEEvents; dteEvents.OnBeginShutdown += OnBeginShutdown; solutionEvents.Opened += OnSolutionOpened; solutionEvents.BeforeClosing += OnSolutionClosing; projectItemEvents.ItemAdded += OnSolutionItemAdded; projectItemEvents.ItemRenamed += OnSolutionItemRenamed; projectItemEvents.ItemRemoved += OnSolutionItemRemoved; textEditorEvents.LineChanged += OnTextEditorLineChanged; documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; Command cmd = ApplicationObject.Commands.Item("Edit.CompleteWord", -1); commandEvents = ApplicationObject.Events.get_CommandEvents(cmd.Guid, cmd.ID); commandEvents.BeforeExecute += OnBeforeCompleteWordRequested; }
public async Task StopPulseTrackingAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); this.StopTimer(); if (await GetServiceAsync(typeof(DTE)) is DTE dte) { Events events = dte.Events; WindowEvents windowEvents = events.WindowEvents; windowEvents.WindowActivated -= this.OnActiveDocumentChanged; this.dteEvents = events.DTEEvents; this.dteEvents.OnBeginShutdown -= this.OnBeginShutdown; this.textEditorEvents = events.TextEditorEvents; this.textEditorEvents.LineChanged -= this.OnLineChanged; this.buildEvents = events.BuildEvents; this.buildEvents.OnBuildDone -= this.OnBuildDone; this.documentEvents = events.DocumentEvents; this.documentEvents.DocumentSaved -= this.OnDocumentSaved; } }
/// <summary> /// Initialisation of the package; this method is called right after the package is sited, so this is the place /// where you can put all the Initialisation code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for Initialisation cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package Initialisation, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // When Initialised asynchronously, the current thread may be a background thread at this point. // Do any Initialisation that requires the UI thread after switching to the UI thread. //await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); GetLogger().LogInformation(GetPackageName(), "Initialising."); await base.InitializeAsync(cancellationToken, progress); try { var dte = (DTE)await this.GetServiceAsync(typeof(DTE)); var _dteEvents = dte.Events; _dteEditorEvents = _dteEvents.TextEditorEvents; _dteWindowEvents = _dteEvents.WindowEvents; _dteEditorEvents.LineChanged += OnLineChanged; _dteWindowEvents.WindowActivated += OnWindowActivated; _stack = new Stack <CancellationTokenSource>(); GetLogger().LogInformation(GetPackageName(), "Initialised."); } catch (Exception exception) { GetLogger().LogError(GetPackageName(), "Exception during initialisation", exception); } }
/// <summary> /// Initialize services available from Visual Studio. /// </summary> /// <param name="dte">Entry object of Visual Studio services.</param> public VisualStudioServices(DTE dte) { Log = new Log(); _changeWait.Interval = new TimeSpan(0, 0, 1); _changeWait.Tick += flushChanges; _solutionWait.Interval = new TimeSpan(0, 0, 1); _solutionWait.Tick += solutionOpenedAfterWait; _dte = dte; if (_dte == null) { //create empty services return; } _events = _dte.Events; _events2 = _dte.Events as Events2; _textEditorEvents = _events.TextEditorEvents; _solutionEvents = _events.SolutionEvents; if (_events2 != null) { _projectItemEvents = _events2.ProjectItemsEvents; } _solutionItemEvents = _events.SolutionItemsEvents; }
private void bindTextEditorEvents() { if (_textEditorEvents != null) { return; } _textEditorEvents = _applicationObject.Events.TextEditorEvents; _lineChangedEvent = new _dispTextEditorEvents_LineChangedEventHandler(TextEditorEvents_OnLineChanged); _textEditorEvents.LineChanged += _lineChangedEvent; }
private void OverviewWindow_Loaded(object sender, RoutedEventArgs e) { this.service = (DTE2)this.serviceProvider.GetService(typeof(DTE)); this.documentEvents = this.service.Events.DocumentEvents; this.textEditorEvents = this.service.Events.TextEditorEvents; this.windowEvents = this.service.Events.WindowEvents; this.windowEvents.WindowActivated += (newWindow, oldWindow) => this.UpdateTree(); this.documentEvents.DocumentOpened += doc => this.UpdateTree(); this.textEditorEvents.LineChanged += (start, end, idx) => this.UpdateTree(); }
private async Task BindToLocalVisualStudioEventsAsync() { var dte = (DTE) await GetServiceAsync(typeof(DTE)); var _dteEvents = dte.Events; _dteEditorEvents = _dteEvents.TextEditorEvents; _dteWindowEvents = _dteEvents.WindowEvents; _dteEditorEvents.LineChanged += OnLineChanged; _dteWindowEvents.WindowActivated += OnWindowActivated; }
public EditEventGenerator(IRSEnv env, IMessageBus messageBus, IDateUtils dateUtils, IContextProvider contextProvider, IThreading threading) : base(env, messageBus, dateUtils, threading) { _dateUtils = dateUtils; _contextProvider = contextProvider; _textEditorEvents = DTE.Events.TextEditorEvents; _textEditorEvents.LineChanged += TextEditorEvents_LineChanged; }
private async Task InitializeAsync(CancellationToken cancellationToken) { if (_dte is null) { _logger.Error("DTE is null"); return; } try { await _wakatime.InitializeAsync(); // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Visual Studio Events _docEvents = _dte.Events.DocumentEvents; _windowEvents = _dte.Events.WindowEvents; _solutionEvents = _dte.Events.SolutionEvents; _debuggerEvents = _dte.Events.DebuggerEvents; _buildEvents = _dte.Events.BuildEvents; _textEditorEvents = _dte.Events.TextEditorEvents; // Settings Form _settingsForm = new SettingsForm(_wakatime.Config, _logger); // Add our command handlers for menu (commands must exist in the .vsct file) if (await GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService mcs) { // Create the command for the menu item. var menuCommandId = new CommandID(new Guid(GuidList.GuidWakaTimeCmdSetString), 0x100); var menuItem = new MenuCommand(MenuItemCallback, menuCommandId); mcs.AddCommand(menuItem); } // setup event handlers _docEvents.DocumentOpened += DocEventsOnDocumentOpened; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents.Opened += SolutionEventsOnOpened; _debuggerEvents.OnEnterRunMode += DebuggerEventsOnEnterRunMode; _debuggerEvents.OnEnterDesignMode += DebuggerEventsOnEnterDesignMode; _debuggerEvents.OnEnterBreakMode += DebuggerEventsOnEnterBreakMode; _buildEvents.OnBuildProjConfigBegin += BuildEventsOnBuildProjConfigBegin; _buildEvents.OnBuildProjConfigDone += BuildEventsOnBuildProjConfigDone; _textEditorEvents.LineChanged += TextEditorEventsLineChanged; } catch (Exception ex) { _logger.Error("Error Initializing WakaTime", ex); } }
public DteTrigger(DTE dte) { _dte = dte; _textEditorEvents = _dte.Events.TextEditorEvents; _solutionEvents = _dte.Events.SolutionEvents; _selectionEvents = _dte.Events.SelectionEvents; _textEditorEvents.LineChanged += HandleTextEditorLineChanged; _solutionEvents.Opened += HandleSolutionEventsOnOpened; _selectionEvents.OnChange += HandleSelectionEventsOnChange; }
protected override void MonitorEditorChanges() { var dte = VisualStudio.ContinuousPackage.TheDTE; if (dte == null) { throw new InvalidOperationException("OMG Continuous Package has not inited yet"); } textEditorEvents = dte.Events.TextEditorEvents; // Stupid COM binding requires explicit GC roots textEditorEvents.LineChanged += TextEditorEvents_LineChanged; }
private void InitializeAsync() { // VisualStudio Object _docEvents = _objDte.Events.DocumentEvents; _windowEvents = _objDte.Events.WindowEvents; _solutionEvents = _objDte.Events.SolutionEvents; _editorEvents = _objDte.Events.TextEditorEvents; // setup event handlers _docEvents.DocumentSaved += DocumentEventsOnDocumentSaved; _editorEvents.LineChanged += TextEditorEventsOnLineChanged; _solutionEvents.BeforeClosing += SolutionEventsBeforeClosed; _windowEvents.WindowActivated += WindowEventsOnWindowActivated; }
public EditEventGenerator(IRSEnv env, IMessageBus messageBus, IDateUtils dateUtils, ContextGenerator contextGenerator, IThreading threading) : base(env, messageBus, dateUtils, threading) { _dateUtils = dateUtils; _contextGenerator = contextGenerator; _textEditorEvents = DTE.Events.TextEditorEvents; _textEditorEvents.LineChanged += TextEditorEvents_LineChanged; // TODO event happens before change is reflected... think about how to capture the // state *after* the change, e.g., by scheduling an artificial event or by attaching // this generator also to file save/close events }
private void Cleanup() { m_StringResourceBuilder.Window = null; m_StringResourceBuilder.FocusedTextDocumentWindow = null; m_FocusedTextDocumentWindowHash = 0; if (m_TextEditorEvents != null) { m_TextEditorEvents.LineChanged -= m_TextEditorEvents_LineChanged; m_TextEditorEvents = null; } //if ClearGrid(); m_StringResourceBuilder.ClearStringResources(); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); try { if (VisualStudio.Solution != null) { Log.Message("Starting Tidy Tabs inside Visual Studio {0} {1} for solution {2}", VisualStudio.Edition, VisualStudio.Version, VisualStudio.Solution.FullName); } windowEvents = VisualStudio.Events.WindowEvents; documentEvents = VisualStudio.Events.DocumentEvents; textEditorEvents = VisualStudio.Events.TextEditorEvents; solutionEvents = VisualStudio.Events.SolutionEvents; buildEvents = VisualStudio.Events.BuildEvents; windowEvents.WindowActivated += WindowEventsWindowActivated; documentEvents.DocumentClosing += DocumentEventsOnDocumentClosing; documentEvents.DocumentSaved += DocumentEventsOnDocumentSaved; textEditorEvents.LineChanged += TextEditorEventsOnLineChanged; solutionEvents.Opened += SolutionEventsOnOpened; buildEvents.OnBuildBegin += BuildEventsOnOnBuildBegin; shell = (IVsShell)GetService(typeof(SVsShell)); if (shell != null) { shell.AdviseBroadcastMessages(this, out shellCookie); } OleMenuCommandService menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (menuCommandService != null) { CommandID menuCommandId = new CommandID(GuidList.guidTidyTabsCmdSet, (int)PkgCmdIDList.cmdidTidyTabs); MenuCommand menuItem = new MenuCommand(TidyTabsMenuItemCommandActivated, menuCommandId); menuCommandService.AddCommand(menuItem); } } catch (Exception ex) { Log.Exception(ex); } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async TasksTask InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(false); try { var commandService = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(false) as OleMenuCommandService; _dte = (DTE) await GetServiceAsync(typeof(DTE)).ConfigureAwait(false); _visualStudio = await GetServiceAsync(typeof(SDTE)).ConfigureAwait(false) as DTE2; // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _settings = SettingsProvider.Initialize(GetWritableSettingsStore(this)); _documentManager = new DocumentManager(this, _visualStudio, _settings); CleanTabsCommand.Initialize(_documentManager, commandService); _windowEvents = _dte.Events.WindowEvents; _documentEvents = _dte.Events.DocumentEvents; _textEditorEvents = _dte.Events.TextEditorEvents; _solutionEvents = _dte.Events.SolutionEvents; _buildEvents = _dte.Events.BuildEvents; _documentEvents.DocumentOpened += OnDocumentEvent; _documentEvents.DocumentSaved += OnDocumentEvent; _windowEvents.WindowActivated += OnWindowActivated; _textEditorEvents.LineChanged += OnLineChanged; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.BeforeClosing += OnSolutionClosing; _buildEvents.OnBuildBegin += OnBuildBegin; LoadSolution(); } catch (Exception e) { ActivityLog.TryLogError("KeepingTabs", e.Message); Console.WriteLine(e.ToString()); throw; } }
private void InitializeAsync() { try { // VisualStudio Object _docEvents = ObjDte.Events.DocumentEvents; _windowEvents = ObjDte.Events.WindowEvents; _solutionEvents = ObjDte.Events.SolutionEvents; _debuggerEvents = ObjDte.Events.DebuggerEvents; _buildEvents = ObjDte.Events.BuildEvents; _textEditorEvents = ObjDte.Events.TextEditorEvents; // Settings Form _settingsForm = new SettingsForm(ref WakaTime); _settingsForm.ConfigSaved += SettingsFormOnConfigSaved; // Add our command handlers for menu (commands must exist in the .vsct file) if (GetService(typeof(IMenuCommandService)) is OleMenuCommandService mcs) { // Create the command for the menu item. var menuCommandId = new CommandID(GuidList.GuidWakaTimeCmdSet, (int)PkgCmdIdList.UpdateWakaTimeSettings); var menuItem = new MenuCommand(MenuItemCallback, menuCommandId); mcs.AddCommand(menuItem); } // setup event handlers _docEvents.DocumentOpened += DocEventsOnDocumentOpened; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents.Opened += SolutionEventsOnOpened; _debuggerEvents.OnEnterRunMode += DebuggerEventsOnEnterRunMode; _debuggerEvents.OnEnterDesignMode += DebuggerEventsOnEnterDesignMode; _debuggerEvents.OnEnterBreakMode += DebuggerEventsOnEnterBreakMode; _buildEvents.OnBuildProjConfigBegin += BuildEventsOnBuildProjConfigBegin; _buildEvents.OnBuildProjConfigDone += BuildEventsOnBuildProjConfigDone; _textEditorEvents.LineChanged += TextEditorEventsLineChanged; WakaTime.InitializeAsync(); } catch (Exception ex) { WakaTime.Logger.Error("Error Initializing WakaTime", ex); } }
private void InitializeAsync() { try { Task.Run(async() => await _wakatime.InitializeAsync()).Wait(); // Visual Studio Events _docEvents = _dte.Events.DocumentEvents; _windowEvents = _dte.Events.WindowEvents; _solutionEvents = _dte.Events.SolutionEvents; _debuggerEvents = _dte.Events.DebuggerEvents; _buildEvents = _dte.Events.BuildEvents; _textEditorEvents = _dte.Events.TextEditorEvents; // Settings Form _settingsForm = new SettingsForm(_wakatime.Config, _logger); // Add our command handlers for menu (commands must exist in the .vsct file) if (GetService(typeof(IMenuCommandService)) is OleMenuCommandService mcs) { // Create the command for the menu item. var menuCommandId = new CommandID(new Guid(GuidList.GuidWakaTimeCmdSetString), 0x100); var menuItem = new MenuCommand(MenuItemCallback, menuCommandId); mcs.AddCommand(menuItem); } // setup event handlers _docEvents.DocumentOpened += DocEventsOnDocumentOpened; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents.Opened += SolutionEventsOnOpened; _debuggerEvents.OnEnterRunMode += DebuggerEventsOnEnterRunMode; _debuggerEvents.OnEnterDesignMode += DebuggerEventsOnEnterDesignMode; _debuggerEvents.OnEnterBreakMode += DebuggerEventsOnEnterBreakMode; _buildEvents.OnBuildProjConfigBegin += BuildEventsOnBuildProjConfigBegin; _buildEvents.OnBuildProjConfigDone += BuildEventsOnBuildProjConfigDone; _textEditorEvents.LineChanged += TextEditorEventsLineChanged; } catch (Exception ex) { _logger.Error("Error Initializing WakaTime", ex); } }
/// <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; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { CreateMenuItems(); } else { CreateMenuItems(); CreateWindow(_addInInstance); _buildEvents = _applicationObject.Events.BuildEvents; _textEditorEvents = _applicationObject.Events.TextEditorEvents; _buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(_buildEvents_OnBuildDone); } }
/// <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) { try { applicationObject = (DTE2)application; addInInstance = (AddIn)addInInst; object tempObject = null; var controlName = "MSILWindow.Window.WindowControl"; // Change this to your path var assemblyPath = @"C:\Users\filip.ekberg\Documents\GitHub\MSILWindow\MSILWindow.Window\bin\Debug\MSILWindow.Window.dll"; var controlGuid = "{6d0f6084-69ef-4100-92c5-5e7e3a557e05}"; toolWins = (Windows2)applicationObject.Windows; toolWin = toolWins.CreateToolWindow2(addInInstance, assemblyPath, controlName, "Real-time MSIL Viewer", controlGuid, ref tempObject); if (toolWin != null) { toolWin.Visible = true; } events = applicationObject.Events; buildEvents = events.BuildEvents; buildEvents.OnBuildDone += BuildEvents_OnBuildDone; textEditorEvents = events.get_TextEditorEvents(); textEditorEvents.LineChanged += Connect_LineChanged; serviceProxy = ChannelFactory <ICommandService> .CreateChannel(new NetNamedPipeBinding(), serviceAddress); } catch { } }
private void InitEvents() { if (solutionEvents == null) { solutionEvents = m_dte.Events.SolutionEvents; solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionOpened); solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(SolutionClosed); solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(ProjectAdded); solutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(ProjectRemoved); solutionEvents.ProjectRenamed += new _dispSolutionEvents_ProjectRenamedEventHandler(ProjectRenamed); } if (windowEvents == null) { windowEvents = m_dte.Events.get_WindowEvents(null); windowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowActivated); windowEvents.WindowClosing += new _dispWindowEvents_WindowClosingEventHandler(WindowClosing); } if( textEditorEvents == null ) { textEditorEvents = m_dte.Events.get_TextEditorEvents(null); textEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(LineChanged); } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); try { if (VisualStudio.Solution != null) { Log.Message("Starting Tidy Tabs inside Visual Studio {0} {1} for solution {2}", VisualStudio.Edition, VisualStudio.Version, VisualStudio.Solution.FullName); } windowEvents = VisualStudio.Events.WindowEvents; documentEvents = VisualStudio.Events.DocumentEvents; textEditorEvents = VisualStudio.Events.TextEditorEvents; solutionEvents = VisualStudio.Events.SolutionEvents; buildEvents = VisualStudio.Events.BuildEvents; windowEvents.WindowActivated += WindowEventsWindowActivated; documentEvents.DocumentClosing += DocumentEventsOnDocumentClosing; documentEvents.DocumentSaved += DocumentEventsOnDocumentSaved; textEditorEvents.LineChanged += TextEditorEventsOnLineChanged; solutionEvents.Opened += SolutionEventsOnOpened; buildEvents.OnBuildBegin += BuildEventsOnOnBuildBegin; shell = (IVsShell)GetService(typeof(SVsShell)); if (shell != null) { shell.AdviseBroadcastMessages(this, out shellCookie); } OleMenuCommandService menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (menuCommandService != null) { CommandID menuCommandId = new CommandID(GuidList.guidTidyTabsCmdSet, (int)PkgCmdIDList.cmdidTidyTabs); MenuCommand menuItem = new MenuCommand(TidyTabsMenuItemCommandActivated, menuCommandId); menuCommandService.AddCommand(menuItem); } } catch (Exception ex) { Log.Exception(ex); } }
public EventHandlerBase(IServiceProvider serviceProvider, IOsbideEventGenerator osbideEvents) { if (serviceProvider == null) { throw new Exception("Service provider is null"); } ServiceProvider = serviceProvider; //save references to dte events buildEvents = dte.Events.BuildEvents; genericCommandEvents = dte.Events.CommandEvents; menuCommandEvents = dte.Events.get_CommandEvents(MenuEventGuid); debuggerEvents = dte.Events.DebuggerEvents; documentEvents = dte.Events.DocumentEvents; findEvents = dte.Events.FindEvents; miscFileEvents = dte.Events.MiscFilesEvents; outputWindowEvents = dte.Events.OutputWindowEvents; selectionEvents = dte.Events.SelectionEvents; solutionEvents = dte.Events.SolutionEvents; solutionItemsEvents = dte.Events.SolutionItemsEvents; textEditorEvents = dte.Events.TextEditorEvents; //attach osbide requests _osbideEvents = osbideEvents; _osbideEvents.SolutionSubmitRequest += new EventHandler <SubmitAssignmentArgs>(OsbideSolutionSubmitted); _osbideEvents.SolutionDownloaded += new EventHandler <SolutionDownloadedEventArgs>(OsbideSolutionDownloaded); _osbideEvents.SubmitEventRequested += new EventHandler <SubmitEventArgs>(SubmitEventRequested); //attach listeners for dte events //build events buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(OnBuildBegin); buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(OnBuildDone); //generic command events genericCommandEvents.AfterExecute += new _dispCommandEvents_AfterExecuteEventHandler(GenericCommand_AfterCommandExecute); genericCommandEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(GenericCommand_BeforeCommandExecute); //menu-related command command menuCommandEvents.AfterExecute += new _dispCommandEvents_AfterExecuteEventHandler(MenuCommand_AfterExecute); menuCommandEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(MenuCommand_BeforeExecute); //debugger events debuggerEvents.OnContextChanged += new _dispDebuggerEvents_OnContextChangedEventHandler(OnContextChanged); debuggerEvents.OnEnterBreakMode += new _dispDebuggerEvents_OnEnterBreakModeEventHandler(OnEnterBreakMode); debuggerEvents.OnEnterDesignMode += new _dispDebuggerEvents_OnEnterDesignModeEventHandler(OnEnterDesignMode); debuggerEvents.OnEnterRunMode += new _dispDebuggerEvents_OnEnterRunModeEventHandler(OnEnterRunMode); debuggerEvents.OnExceptionNotHandled += new _dispDebuggerEvents_OnExceptionNotHandledEventHandler(OnExceptionNotHandled); debuggerEvents.OnExceptionThrown += new _dispDebuggerEvents_OnExceptionThrownEventHandler(OnExceptionThrown); //document events documentEvents.DocumentClosing += new _dispDocumentEvents_DocumentClosingEventHandler(DocumentClosing); documentEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(DocumentOpened); documentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(DocumentSaved); //find events findEvents.FindDone += new _dispFindEvents_FindDoneEventHandler(FindDone); //misc file events miscFileEvents.ItemAdded += new _dispProjectItemsEvents_ItemAddedEventHandler(ProjectItemAdded); miscFileEvents.ItemRemoved += new _dispProjectItemsEvents_ItemRemovedEventHandler(ProjectItemRemoved); miscFileEvents.ItemRenamed += new _dispProjectItemsEvents_ItemRenamedEventHandler(ProjectItemRenamed); //output window events outputWindowEvents.PaneUpdated += new _dispOutputWindowEvents_PaneUpdatedEventHandler(OutputPaneUpdated); //selection events selectionEvents.OnChange += new _dispSelectionEvents_OnChangeEventHandler(SelectionChange); //solution events solutionEvents.BeforeClosing += new _dispSolutionEvents_BeforeClosingEventHandler(SolutionBeforeClosing); solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionOpened); solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(ProjectAdded); solutionEvents.Renamed += new _dispSolutionEvents_RenamedEventHandler(SolutionRenamed); //solution item events solutionItemsEvents.ItemAdded += new _dispProjectItemsEvents_ItemAddedEventHandler(SolutionItemAdded); solutionItemsEvents.ItemRemoved += new _dispProjectItemsEvents_ItemRemovedEventHandler(SolutionItemRemoved); solutionItemsEvents.ItemRenamed += new _dispProjectItemsEvents_ItemRenamedEventHandler(SolutionItemRenamed); //text editor events textEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(EditorLineChanged); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { var cm = (IComponentModel)GetGlobalService(typeof(SComponentModel)); eafs = cm.GetService <IVsEditorAdaptersFactoryService>(); Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString())); base.Initialize(); // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the menu item. CommandID menuCommandID = new CommandID(GuidList.guidKineticaCmdSet, (int)PkgCmdIDList.cmdStartTracking); MenuCommand menuItem = new MenuCommand(StartTracking, menuCommandID); mcs.AddCommand(menuItem); // command for saving the snapshot to a folder var id = new CommandID(GuidList.guidKineticaCmdSet, (int)PkgCmdIDList.cmdSaveSnapshot); var mi = new MenuCommand(SaveSnapshots, id); mcs.AddCommand(mi); } // listen to document changes var dte = (DTE)GetService(typeof(DTE)); textEditorEvents = dte.Events.TextEditorEvents; textEditorEvents.LineChanged += (point, endPoint, hint) => { var elapsed = st.ElapsedMilliseconds; var app = (DTE)GetService(typeof(SDTE)); if (app.ActiveDocument != null && app.ActiveDocument.Type == "Text") { //// or the view //var txtMgr = (IVsTextManager) GetService(typeof (SVsTextManager)); //IVsTextView view; //txtMgr.GetActiveView(1, null, out view); IVsTextView view; textManager.GetActiveView(1, null, out view); var wpfView = eafs.GetWpfTextView(view); var doc = (TextDocument)app.ActiveDocument.Object(); var ep = doc.CreateEditPoint(doc.StartPoint); string txt = ep.GetText(doc.EndPoint); // fixme: hashcode collisions WILL happen here snapshots.Add(st.ElapsedMilliseconds, txt); } }; st.Start(); // get the text manager textManager = (IVsTextManager)base.GetService(typeof(SVsTextManager)); }
protected override void MonitorEditorChanges () { var dte = VisualStudio.ContinuousPackage.TheDTE; if (dte == null) throw new InvalidOperationException ("OMG Continuous Package has not inited yet"); textEditorEvents = dte.Events.TextEditorEvents; // Stupid COM binding requires explicit GC roots textEditorEvents.LineChanged += TextEditorEvents_LineChanged; }
public MyVSPackage() { _textEditorEvents = DTE.Events.TextEditorEvents; _textEditorEvents.LineChanged += (point, endPoint, hint) => //Do something here }
public EventHandlerBase(IServiceProvider serviceProvider, IEventGenerator osbideEvents) { if (serviceProvider == null) { throw new Exception("Service provider is null"); } ServiceProvider = serviceProvider; //attach osbide requests _osbideEvents = osbideEvents; _osbideEvents.SolutionSubmitRequest += SolutionSubmitted; _osbideEvents.SubmitEventRequested += SubmitEventRequested; //save references to dte events buildEvents = Dte.Events.BuildEvents; genericCommandEvents = Dte.Events.CommandEvents; menuCommandEvents = Dte.Events.CommandEvents[MenuEventGuid]; debuggerEvents = Dte.Events.DebuggerEvents; documentEvents = Dte.Events.DocumentEvents; findEvents = Dte.Events.FindEvents; miscFileEvents = Dte.Events.MiscFilesEvents; outputWindowEvents = Dte.Events.OutputWindowEvents; selectionEvents = Dte.Events.SelectionEvents; solutionEvents = Dte.Events.SolutionEvents; solutionItemsEvents = Dte.Events.SolutionItemsEvents; textEditorEvents = Dte.Events.TextEditorEvents; //attach osbide requests //var osbideEventGenerator = osbideEvents; //osbideEventGenerator.SolutionSubmitRequest += SolutionSubmitted; //osbideEventGenerator.SubmitEventRequested += SubmitEventRequested; //attach listeners for dte events //build events buildEvents.OnBuildBegin += OnBuildBegin; buildEvents.OnBuildDone += OnBuildDone; //generic command events genericCommandEvents.AfterExecute += GenericCommand_AfterCommandExecute; genericCommandEvents.BeforeExecute += GenericCommand_BeforeCommandExecute; //menu-related command command menuCommandEvents.AfterExecute += MenuCommand_AfterExecute; menuCommandEvents.BeforeExecute += MenuCommand_BeforeExecute; //debugger events debuggerEvents.OnContextChanged += OnContextChanged; debuggerEvents.OnEnterBreakMode += OnEnterBreakMode; debuggerEvents.OnEnterDesignMode += OnEnterDesignMode; debuggerEvents.OnEnterRunMode += OnEnterRunMode; debuggerEvents.OnExceptionNotHandled += OnExceptionNotHandled; debuggerEvents.OnExceptionThrown += OnExceptionThrown; //document events documentEvents.DocumentClosing += DocumentClosing; documentEvents.DocumentOpened += DocumentOpened; documentEvents.DocumentSaved += DocumentSaved; //find events findEvents.FindDone += FindDone; //misc file events miscFileEvents.ItemAdded += ProjectItemAdded; miscFileEvents.ItemRemoved += ProjectItemRemoved; miscFileEvents.ItemRenamed += ProjectItemRenamed; //output window events outputWindowEvents.PaneUpdated += OutputPaneUpdated; //selection events selectionEvents.OnChange += SelectionChange; //solution events solutionEvents.BeforeClosing += SolutionBeforeClosing; solutionEvents.Opened += SolutionOpened; solutionEvents.ProjectAdded += ProjectAdded; solutionEvents.Renamed += SolutionRenamed; //solution item events solutionItemsEvents.ItemAdded += SolutionItemAdded; solutionItemsEvents.ItemRemoved += SolutionItemRemoved; solutionItemsEvents.ItemRenamed += SolutionItemRenamed; //text editor events textEditorEvents.LineChanged += EditorLineChanged; // Create an event log watcher that will notify us if any windows event logs // of type Error are created in the "Application" log file. This is so we can // tell if a user experiences a runtime exception while running their code // outside debug mode. string queryStr = "*[System/Level=2]"; EventLogQuery query = new EventLogQuery("Application", PathType.LogName, queryStr); eventLogWatcher = new EventLogWatcher(query); // subscribe to it's event (Note: it is not enabled yet, it will be enabled if the // user runs without debuging) eventLogWatcher.EventRecordWritten += NETErrorEventRecordWritten; }
private void WindowEvents_WindowActivated(EnvDTE.Window gotFocus, EnvDTE.Window lostFocus) { //Trace.WriteLine(string.Format("\n>>>> WindowEvents_WindowActivated() - '{0}' <- '{1}' ({2})\n", gotFocus.Caption, lostFocus.Caption, (m_Dte2.ActiveDocument == null) ? "null" : m_Dte2.ActiveDocument.Name)); Debug.Print("\n>>>> WindowEvents_WindowActivated() - '{0}' <- '{1}' ({2})\n", (gotFocus == null) ? "null" : gotFocus.Caption, (lostFocus == null) ? "null" : lostFocus.Caption, (m_Dte2.ActiveDocument == null) ? "null" : m_Dte2.ActiveDocument.Name); if (m_StringResourceBuilder.IsBrowsing) { return; } if (!m_IsVisible) { return; } if (m_Dte2.ActiveDocument == null) { if (m_StringResourceBuilder.Window != null) { WindowEvents_WindowClosing(m_StringResourceBuilder.Window); } return; } //if Trace.WriteLine("WindowEvents_WindowActivated()"); if (m_TextEditorEvents != null) { m_TextEditorEvents.LineChanged -= m_TextEditorEvents_LineChanged; m_TextEditorEvents = null; } //if //if (m_TextDocumentKeyPressEvents != null) //{ // m_TextDocumentKeyPressEvents.AfterKeyPress -= m_TextDocumentKeyPressEvents_AfterKeyPress; // m_TextDocumentKeyPressEvents.AfterKeyPress += m_TextDocumentKeyPressEvents_AfterKeyPress; // m_TextDocumentKeyPressEvents = null; //} //if EnvDTE.Window window = m_Dte2.ActiveDocument.ActiveWindow; bool isGotDocument = (gotFocus != null) && (gotFocus.Document != null), isLostDocument = (lostFocus != null) && (lostFocus.Document != null), isGotCode = isGotDocument && (gotFocus.Caption.EndsWith(".cs") || gotFocus.Caption.EndsWith(".vb")), isLostCode = isLostDocument && (lostFocus.Caption.EndsWith(".cs") || lostFocus.Caption.EndsWith(".vb")); if (!isGotDocument /*&& !isLostDocument*/ && (m_StringResourceBuilder.Window != null)) { window = m_StringResourceBuilder.Window; } if (isGotCode) { window = gotFocus; } else if (!isGotDocument && isLostCode) { window = lostFocus; } if ((window != null) && (window.Document != null) && (window.Caption.EndsWith(".cs") || window.Caption.EndsWith(".vb"))) { TextDocument txtDoc = window.Document.Object("TextDocument") as TextDocument; if (txtDoc != null) { EnvDTE80.Events2 events = (EnvDTE80.Events2)m_Dte2.Events; m_TextEditorEvents = events.TextEditorEvents[txtDoc]; m_TextEditorEvents.LineChanged -= m_TextEditorEvents_LineChanged; m_TextEditorEvents.LineChanged += m_TextEditorEvents_LineChanged; //m_TextDocumentKeyPressEvents = events.TextDocumentKeyPressEvents[txtDoc]; //m_TextDocumentKeyPressEvents.AfterKeyPress -= m_TextDocumentKeyPressEvents_AfterKeyPress; //m_TextDocumentKeyPressEvents.AfterKeyPress += m_TextDocumentKeyPressEvents_AfterKeyPress; if (m_FocusedTextDocumentWindowHash != window.GetHashCode()) { m_FocusedTextDocumentWindowHash = window.GetHashCode(); m_StringResourceBuilder.FocusedTextDocumentWindow = window; this.Dispatcher.BeginInvoke(new Action(m_StringResourceBuilder.DoBrowse)); } //if } //if } //else if (m_StringResourceBuilder.Window != null) // WindowEvents_WindowClosing(m_StringResourceBuilder.Window); }
private void bindTextEditorEvents() { if (_textEditorEvents != null) return; _textEditorEvents = _applicationObject.Events.TextEditorEvents; _lineChangedEvent = new _dispTextEditorEvents_LineChangedEventHandler(TextEditorEvents_OnLineChanged); _textEditorEvents.LineChanged += _lineChangedEvent; }