public SolutionWatcher() { if (Common.Instance.Solution != null) { Common.Instance.Solution.AdviseSolutionEvents(this, out mSolutionCookie); } mFileHistory.MaxHistory = Common.Instance.Settings.MaxFileHistory; mWindowEvents = Common.Instance.DTE2.Events.WindowEvents; mWindowEvents.WindowActivated += OnWindowActivated; mWindowEvents.WindowCreated += OnWindowCreated; mDocumentEvents = Common.Instance.DTE2.Events.DocumentEvents; mDocumentEvents.DocumentOpening += OnDocumentOpening; mDocumentEvents.DocumentOpened += OnDocumentOpened; mDocumentEvents.DocumentSaved += OnDocumentSaved; mSolutionItemsEvents = Common.Instance.DTE2.Events.SolutionItemsEvents; mSolutionItemsEvents.ItemAdded += OnItemAdded; mSolutionItemsEvents.ItemRemoved += OnItemRemoved; mSolutionItemsEvents.ItemRenamed += OnItemRenamed; RefreshOpenHistory(); OnFilesChanged += RefreshSymbolDatabase; }
protected override void Initialize() { base.Initialize(); // Prepare event var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (dte != null) { CommandVisible = false; WindowEvents = dte.Events.WindowEvents; WindowEvents.WindowActivated += WindowEvents_WindowActivated; WindowEvents.WindowClosing += WindowEvents_WindowClosing; } // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { // Create the command for the tool window CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides); var menuCmd = new OleMenuCommand(ToggleVisibility, viewIndentCommandID); menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus); mcs.AddCommand(menuCmd); } Service = new IndentGuideService(this); ((IServiceContainer)this).AddService(typeof(SIndentGuide), Service, true); Service.Upgrade(); Service.Load(); }
protected async override Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); // Prepare event var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (dte != null) { CommandVisible = false; WindowEvents = dte.Events.WindowEvents; WindowEvents.WindowActivated += WindowEvents_WindowActivated; WindowEvents.WindowClosing += WindowEvents_WindowClosing; } // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { // Create the command for the tool window CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides); var menuCmd = new OleMenuCommand(ToggleVisibility, viewIndentCommandID); menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus); mcs.AddCommand(menuCmd); } Service = new IndentGuideService(this); AddService(typeof(SIndentGuide), async(container, ct, type) => Service, true); Service.Upgrade(); Service.Load(); }
public void populateDefaultVSComObjects() { VisualStudio_2010.Package = this; VisualStudio_2010.ErrorListProvider = new ErrorListProvider(this); VisualStudio_2010.IVsUIShell = this.getService <IVsUIShell>(); VisualStudio_2010.DTE2 = this.getService <EnvDTE.DTE, EnvDTE80.DTE2>(); VisualStudio_2010.OleMenuCommandService = this.getService <OleMenuCommandService>(); Events = VisualStudio_2010.DTE2.Events; BuildEvents = Events.BuildEvents; CommandEvents = Events.CommandEvents; DebuggerEvents = Events.DebuggerEvents; DocumentEvents = Events.DocumentEvents; DTEEvents = Events.DTEEvents; FindEvents = Events.FindEvents; MiscFilesEvents = Events.MiscFilesEvents; OutputWindowEvents = Events.OutputWindowEvents; SelectionEvents = Events.SelectionEvents; SolutionEvents = Events.SolutionEvents; SolutionItemsEvents = Events.SolutionItemsEvents; TaskListEvents = Events.TaskListEvents; TextEditorEvents = Events.TextEditorEvents; WindowEvents = Events.WindowEvents; BuildEvents.OnBuildBegin += (scope, action) => VisualStudio_2010.On_BuildBegin.invoke(); BuildEvents.OnBuildDone += (scope, action) => VisualStudio_2010.On_BuildDone.invoke(); BuildEvents.OnBuildProjConfigDone += (Project, ProjectConfig, Platform, SolutionConfig, Success) => { //@"On OnBuildProjConfigDone: project: {0} , ProjectConfig: {1} , Platform: {2}, SolutionConfig: {3} , Success: {4}".debug(Project,ProjectConfig, Platform, SolutionConfig,Success); if (Success) { VisualStudio_2010.On_ProjectBuild_OK.invoke(Project); } else { VisualStudio_2010.On_ProjectBuild_Failed.invoke(Project); } }; SolutionEvents.Opened += () => VisualStudio_2010.On_SolutionOpened.invoke(); DocumentEvents.DocumentOpened += (document) => VisualStudio_2010.on_DocumentOpened.invoke(document); DocumentEvents.DocumentClosing += (document) => VisualStudio_2010.on_DocumentClosing.invoke(document); DocumentEvents.DocumentSaved += (document) => VisualStudio_2010.on_DocumentSaved.invoke(document); DocumentEvents.DocumentOpening += (documentPath, readOnly) => VisualStudio_2010.on_DocumentOpening.invoke(documentPath, readOnly); TextEditorEvents.LineChanged += (startPoint, endPoint, hInt) => VisualStudio_2010.on_LineChanged.invoke(startPoint, endPoint); WindowEvents.WindowActivated += (windowGotFocus, windowLostFocus) => { if (windowGotFocus.Document.notNull()) { VisualStudio_2010.on_ActiveDocumentChange.invoke(windowGotFocus.Document); } }; }
protected override void OnToolWindowCreate() { base.OnToolWindowCreate(); EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); EnvDTE80.Events2 events = (EnvDTE80.Events2)dte.Events; this.WindowEvents = (EnvDTE.WindowEvents)events.get_WindowEvents(null); this.WindowEvents.WindowActivated += new EnvDTE._dispWindowEvents_WindowActivatedEventHandler(WindowEvents_WindowActivated); }
public IDEWrapper(EnvDTE.DTE dte) { DTE = dte; UserImages = TeamCodingPackage.Current.UserImages; WindowEvents = dte.Events.WindowEvents; WindowEvents.WindowActivated += WindowEvents_WindowActivated; WindowEvents.WindowCreated += WindowEvents_WindowCreated; TeamCodingPackage.Current.Settings.UserSettings.UserTabDisplayChanged += UserSettings_UserTabDisplayChanged; }
public override void OnToolWindowCreated() { ThreadHelper.ThrowIfNotOnUIThread(); var dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); _windowEvents = dte.Events.WindowEvents; _dte = dte; _windowEvents.WindowActivated += OnDteWindowFocusChanged; Application.Current.Activated += (sender, e) => OnVsWindowFocusChanged(hasFocus: true); Application.Current.Deactivated += (sender, e) => OnVsWindowFocusChanged(hasFocus: false); }
private void SubscribeToEvents() { _dteService = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if(null != _dteService) { _buildEvents = _dteService.Events.BuildEvents; _windowEvents = _dteService.Events.WindowEvents; if(null != _buildEvents) { _buildEvents.OnBuildBegin += _buildEvents_OnBuildBegin; _buildEvents.OnBuildDone += _buildEvents_OnBuildDone; } if(null != _windowEvents) { _windowEvents.WindowActivated += _windowEvents_WindowActivated; } } }
/// <summary> /// Initializes a new instance of the <see cref="GitHostWindow"/> class. /// </summary> public GitHostWindow() : base(null) { // save references in order to make event registrations are not GCed _dte2 = (DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)); _events = _dte2.Events; _events2 = _events.SolutionEvents; _events2.Opened += SolutionEvents_Opened; _events3 = _events.WindowEvents; _events3.WindowActivated += _events3_WindowActivated; this.Caption = "Git Integrated Window"; // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. this.Content = _githost = new GitConsoleExtension.GitHostWindowControl(); }
protected override bool TryInitialize() { ThreadHelper.ThrowIfNotOnUIThread(); var dte = AcuminatorVSPackage.Instance.GetService <EnvDTE.DTE>(); //Store reference to DTE SolutionEvents and WindowEvents to prevent them from being GC-ed if (dte?.Events != null) { _solutionEvents = dte.Events.SolutionEvents; _windowEvents = dte.Events.WindowEvents; _documentEvents = dte.Events.DocumentEvents; _visibilityEvents = (dte.Events as EnvDTE80.Events2)?.WindowVisibilityEvents; } else { return(false); } return(_solutionEvents != null && _windowEvents != null && _documentEvents != null && _visibilityEvents != null); }
private void SubscribeToEvents() { _dteService = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (null != _dteService) { _buildEvents = _dteService.Events.BuildEvents; _windowEvents = _dteService.Events.WindowEvents; if (null != _buildEvents) { _buildEvents.OnBuildBegin += _buildEvents_OnBuildBegin; _buildEvents.OnBuildDone += _buildEvents_OnBuildDone; } if (null != _windowEvents) { _windowEvents.WindowActivated += _windowEvents_WindowActivated; } } }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); JoinableTaskFactory = ThreadHelper.JoinableTaskFactory; // Switches to the UI thread in order to consume some services used in command initialization await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Prepare event var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (dte != null) { CommandVisible = false; WindowEvents = dte.Events.WindowEvents; WindowEvents.WindowActivated += WindowEvents_WindowActivated; WindowEvents.WindowClosing += WindowEvents_WindowClosing; } // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { // Create the command for the tool window CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides); var menuCmd = new OleMenuCommand(ToggleVisibility, viewIndentCommandID); menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus); mcs.AddCommand(menuCmd); } Service = new IndentGuideService(this); // Adds a service on the background thread AddService(typeof(SIndentGuide), async(container, ct, type) => await System.Threading.Tasks.Task.FromResult(Service), true); Service.Upgrade(); Service.Load(); }
protected override void Initialize() { base.Initialize(); InitializeTaskProvider(); AddMenuCommands(); var dte = (EnvDTE.DTE)GetGlobalService(typeof(EnvDTE.DTE)); solutionEvents = dte.Events.SolutionEvents; windowEvents = dte.Events.WindowEvents; solutionEvents.Opened += RefreshTasksAsync; solutionEvents.AfterClosing += () => taskProvider.Tasks.Clear(); PackageOptions.Applied += (s, e) => OnPackageOptionsApplied(); if (Options.RequestOnStartup) { RefreshTasksAsync(); } }
protected override async Task InitializeAsync ( CancellationToken Token, IProgress <ServiceProgressData> Progress ) { await base.InitializeAsync(Token, Progress); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(Token); #region Events #region RunningDocumentTable var Table = new RunningDocumentTable(this); Table.Advise(new RunningDocTableEvents()); #endregion #region EnvDTE.Events var DTE = await Utils.GetDTEAsync(); Events = DTE.Events; DocumentEvents = Events.DocumentEvents; DocumentEvents.DocumentClosing += Document => { _ = Task.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (Document.Language != "C/C++") { return; } await TaskScheduler.Default; await File.Structure.Events.OnBeforeDocumentCloseAsync(); }, Token); }; WindowEvents = Events.WindowEvents; WindowEvents.WindowActivated += (GotFocus, LostFocus) => { if (GotFocus == LastWindowThatGotFocus) { return; } _ = Task.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (GotFocus.Document == null) { return; } if (GotFocus.Document.Language != "C/C++") { return; } await TaskScheduler.Default; LastWindowThatGotFocus = GotFocus; await File.Structure.Events.OnAfterWindowActivateAsync(); }, Token); }; #endregion await WindowCommand.InitializeAsync(this); #endregion }