/// <summary> /// Initializes a new instance of the <see cref="VSEventsHandler"/> class. /// </summary> /// <param name="package">The Visual Studio Extension Package.</param> public VSEventsHandler(OpenCoverUIPackage package) { _package = package; _solutionEvents = _package.DTE.Events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.AfterClosing += OnSolutionClosing; }
public PluginList() { InitializeComponent(); _logger = new Logger(); _dte = Package.GetGlobalService(typeof(DTE)) as DTE; if (_dte == null) return; _solution = _dte.Solution; if (_solution == null) return; _events = _dte.Events; var windowEvents = _events.WindowEvents; windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents = _events.SolutionEvents; _solutionEvents.BeforeClosing += BeforeSolutionClosing; _solutionEvents.BeforeClosing += SolutionBeforeClosing; _solutionEvents.ProjectAdded += SolutionProjectAdded; _solutionEvents.ProjectRemoved += SolutionProjectRemoved; _solutionEvents.ProjectRenamed += SolutionProjectRenamed; SelectedAssemblyItem.PropertyChanged += SelectedAssemblyItem_PropertyChanged; }
protected override void Initialize() { base.Initialize(); //if invalid data, adjust it dataAdjuster.Adjust(); // Get solution build manager sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (sbm != null) { sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); } // Must hold a reference to the solution events object or the events wont fire, garbage collection related events = GetDTE().Events.SolutionEvents; events.Opened += Solution_Opened; PrintLine("Build monitor initialized"); PrintLine("Path to persist data: {0}", Settings.RepositoryPath); monitor.SolutionBuildFinished = b => { Print("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime()); PrintLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime()); }; monitor.ProjectBuildFinished = b => PrintLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName); }
private SolutionHandler(DTE2 dte) { _dte = dte; _events = _dte.Events.SolutionEvents; _events.Opened += OnSolutionOpened; _events.AfterClosing += OnSolutionClosed; }
internal SolutionManager(DTE dte, IVsSolution vsSolution, IVsMonitorSelection vsMonitorSelection) { if (dte == null) { throw new ArgumentNullException("dte"); } _initNeeded = true; _dte = dte; _vsSolution = vsSolution; _vsMonitorSelection = vsMonitorSelection; // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events. _solutionEvents = _dte.Events.SolutionEvents; // can be null in unit tests if (vsMonitorSelection != null) { Guid solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid; _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie); uint cookie; int hr = _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); ErrorHandler.ThrowOnFailure(hr); } _solutionEvents.BeforeClosing += OnBeforeClosing; _solutionEvents.AfterClosing += OnAfterClosing; _solutionEvents.ProjectAdded += OnProjectAdded; _solutionEvents.ProjectRemoved += OnProjectRemoved; _solutionEvents.ProjectRenamed += OnProjectRenamed; // Run the init on another thread to avoid an endless loop of SolutionManager -> Project System -> VSPackageManager -> SolutionManager ThreadPool.QueueUserWorkItem(new WaitCallback(Init)); }
public GoToDefinitionFilterProvider( [Import(typeof(SVsServiceProvider))] System.IServiceProvider serviceProvider, IVsEditorAdaptersFactoryService editorFactory, IEditorOptionsFactoryService editorOptionsFactory, ITextDocumentFactoryService textDocumentFactoryService, [Import(typeof(DotNetReferenceSourceProvider))] ReferenceSourceProvider referenceSourceProvider, VSLanguageService fsharpVsLanguageService, ProjectFactory projectFactory) { _serviceProvider = serviceProvider; _editorFactory = editorFactory; _editorOptionsFactory = editorOptionsFactory; _textDocumentFactoryService = textDocumentFactoryService; _referenceSourceProvider = referenceSourceProvider; _fsharpVsLanguageService = fsharpVsLanguageService; _projectFactory = projectFactory; var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var events = dte.Events as Events2; if (events != null) { _solutionEvents = events.SolutionEvents; _solutionEvents.AfterClosing += Cleanup; } }
public AutoLinkerService(DTE2 visualStudio, IConfigurationService configurationService, IVisualStudioService visualStudioService) { Argument.IsNotNull("visualStudio", visualStudio); Argument.IsNotNull("configurationService", configurationService); Argument.IsNotNull("visualStudioService", visualStudioService); _visualStudio = visualStudio; _configurationService = configurationService; _visualStudioService = visualStudioService; var events = (Events2)_visualStudio.Events; _solutionEvents = events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.AfterClosing += OnSolutionClosed; _solutionItemsEvents = events.MiscFilesEvents; _solutionItemsEvents.ItemAdded += OnSolutionItemAdded; _solutionItemsEvents.ItemRemoved += OnSolutionItemRemoved; _solutionItemsEvents.ItemRenamed += OnSolutionItemRenamed; _projectItemsEvents = events.ProjectItemsEvents; _projectItemsEvents.ItemAdded += OnSolutionItemAdded; _projectItemsEvents.ItemRemoved += OnSolutionItemRemoved; _projectItemsEvents.ItemRenamed += OnSolutionItemRenamed; }
protected override void Initialize() { _dte = GetService(typeof(DTE)) as DTE2; Package = this; Telemetry.SetDeviceName(_dte.Edition); Logger.Initialize(this, Constants.VSIX_NAME); Events2 events = (Events2)_dte.Events; _solutionEvents = events.SolutionEvents; _solutionEvents.AfterClosing += () => { TableDataSource.Instance.CleanAllErrors(); }; _solutionEvents.ProjectRemoved += (project) => { TableDataSource.Instance.CleanAllErrors(); }; _buildEvents = events.BuildEvents; _buildEvents.OnBuildBegin += OnBuildBegin; CreateConfig.Initialize(this); Recompile.Initialize(this); CompileOnBuild.Initialize(this); RemoveConfig.Initialize(this); CompileAllFiles.Initialize(this); CleanOutputFiles.Initialize(this); base.Initialize(); }
/// <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) { Globals.DTE = (DTE2)application; Globals.Addin = (AddIn)addInInst; solutionEvents = Globals.DTE.Events.SolutionEvents; solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); solutionEvents.BeforeClosing += new _dispSolutionEvents_BeforeClosingEventHandler(SolutionEvents_BeforeClosing); commandManager = new CommandManager(Globals.DTE, Globals.Addin); commandBarBuilder = new CommandBarBuilder(Globals.DTE, Globals.Addin); switch (connectMode) { case ext_ConnectMode.ext_cm_UISetup: // Initialize the UI of the add-in break; case ext_ConnectMode.ext_cm_Startup: // The add-in was marked to load on startup // Do nothing at this point because the IDE may not be fully initialized // Visual Studio will call OnStartupComplete when fully initialized break; case ext_ConnectMode.ext_cm_AfterStartup: // The add-in was loaded by hand after startup using the Add-In Manager // Initialize it in the same way that when is loaded on startup Initialize(); break; } }
static ReloadFactory() { var dte = (DTE2)Package.GetGlobalService(typeof(DTE)); _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.AfterClosing += SolutionEvents_AfterClosing; _solutionEvents.ProjectRemoved += _solutionEvents_ProjectRemoved; }
public WebResourceList() { InitializeComponent(); _dte = Package.GetGlobalService(typeof(DTE)) as DTE; if (_dte == null) return; _solution = _dte.Solution; if (_solution == null) return; _events = _dte.Events; var windowEvents = _events.WindowEvents; windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents = _events.SolutionEvents; _solutionEvents.BeforeClosing += BeforeSolutionClosing; _solutionEvents.Opened += SolutionOpened; _solutionEvents.ProjectAdded += SolutionProjectAdded; _solutionEvents.ProjectRemoved += SolutionProjectRemoved; _solutionEvents.ProjectRenamed += SolutionProjectRenamed; _events2 = (Events2)_dte.Events; _projectItemsEvents = _events2.ProjectItemsEvents; _projectItemsEvents.ItemAdded += ProjectItemAdded; _projectItemsEvents.ItemRemoved += ProjectItemRemoved; _projectItemsEvents.ItemRenamed += ProjectItemRenamed; }
public InstallerProjectManagementService(InstallBakerEventAggregator eventAggregator, SolutionEvents solutionEvents, Solution solution) : base(eventAggregator) { _solutionEvents = solutionEvents; _currentSolution = solution; LoadInstallerProject(); HookEvents(); }
public VsEventProvider( ISourceControlService sourceControlService) { _vsEnvironment = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)) as DTE2; _sourceControlService = sourceControlService; _solutionEvents = _vsEnvironment.Events.SolutionEvents; _solutionEvents.AfterClosing += OnSolutionClosing; _solutionEvents.Opened += OnSolutionOpened; }
public VisualStudioConnection(Package package) { _package = package; _dte = (DTE2)Package.GetGlobalService(typeof(DTE)); _solutionEvents = ((Events2)_dte.Events).SolutionEvents; _buildEvents = ((Events2)_dte.Events).BuildEvents; _subject = new Subject<EventType>(); }
private Storage(RegistryKey storeTarget, DTE2 application) { _storeTarget = storeTarget; _application = application; _solutionEvents = application.Events.SolutionEvents; _historicProcesses = new List<AttachData>(); _sessionProcesses = new List<AttachData>(); }
public DteWithEvents(DTE dte) { DTE = dte; SolutionEvents = dte.Events.SolutionEvents; ProjectItemsEvents = ((Events2)dte.Events).ProjectItemsEvents; DocumentEvents = ((Events2) dte.Events).DocumentEvents; BuildEvents = ((Events2) dte.Events).BuildEvents; CodeModelEvents = ((Events2)dte.Events).CodeModelEvents; }
public VisualStudioSolutionService() { _currentDTE = VSJenkinsManagerPackage.Instance.GetService<DTE>(); _solutionEvents = _currentDTE.Events.SolutionEvents; _solutionEvents.Opened += FireSolutionChangedEvent; _solutionEvents.AfterClosing += FireSolutionChangedEvent; _solutionEvents.Renamed += RenamedSolution; }
public PackageRestorer(DTE dte, IServiceProvider serviceProvider) { _dte = dte; _errorListProvider = new ErrorListProvider(serviceProvider); _buildEvents = dte.Events.BuildEvents; _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.AfterClosing += SolutionEvents_AfterClosing; }
private void BindSolutionEvents() { this.solutionEvents = this.events.SolutionEvents; this.solutionEvents.Opened += this.SolutionEvents_Opened; this.solutionEvents.AfterClosing += SolutionEvents_AfterClosing; // TODO CF from NL: implement based on ConnectEvents.cs }
public DteSolution(Solution solution) { _solution = solution; _projects = _solution.Projects.OfType<Project>().Select(x => new DteProject(x)).ToList(); _solutionEvents = _solution.DTE.Events.SolutionEvents; _solutionEvents.ProjectAdded += HandleProjectAdded; _solutionEvents.ProjectRemoved += HandleProjectRemoved; _solutionEvents.ProjectRenamed += HandleProjectRenamed; Version = new Version(solution.DTE.Version); }
/// <summary> /// Initializes a new instance of the <see cref="CoverageOverviewControl"/> class. /// </summary> public CoverageOverviewControl() { _dte = (DTE)CoverageOverviewCommand.Instance.ServiceProvider.GetService(typeof(DTE)); _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.Opened += SolutionEventsOpened; LogFactory.CurrentLogger = new VisualStudioLogger(CoverageOverviewCommand.Instance.ServiceProvider); this.InitializeComponent(); this.Loaded += CoverageOverviewControl_Loaded; }
public SolutionListener(SVsServiceProvider sp, ILogger logger, SettingsPersister persister, SettingsLocator locator) { this.logger = logger; this.locator = locator; this.persister = persister; dte = (DTE)sp.GetService(typeof(DTE)); dteEvents = dte.Events.DTEEvents; solutionEvents = dte.Events.SolutionEvents; projectEvents = ((Events2)dte.Events).ProjectItemsEvents; }
/// <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; _windowEvents = _applicationObject.Events.WindowEvents; _windowEvents.WindowCreated += OnWindowCreated; _solutionEvents = _applicationObject.Events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpened; }
/// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary> /// <param term='commandName'>The name of the command to execute.</param> /// <param term='executeOption'>Describes how the command should be run.</param> /// <param term='varIn'>Parameters passed from the caller to the command handler.</param> /// <param term='varOut'>Parameters passed from the command handler to the caller.</param> /// <param term='handled'>Informs the caller if the command was handled or not.</param> /// <seealso class='Exec' /> public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if(commandName == "NAntAddin.Connect.NAntAddin") { ////////////////////////////////////////////////////////////////////////// // If view doesn't yet exists, create a new one if (_addInWindow == null) { object addInView = null; // Create the AddIn View _addInWindow = AddInUtils.CreateAddinView( _applicationObject, _addInInstance, ref addInView, "{01E76687-72C6-4209-85A8-49D0F447E0BE}", "NAntAddin", typeof(NAntAddinView), Properties.Resources.ant); // If view sucessfully create, just initialize it if (addInView != null) { // Initialize the view _addInView = addInView as NAntAddinView; _addInView.ViewController.ApplicationObject = _applicationObject; // Keep a SolutionEvents instance not garbagable _solutionEvents = _applicationObject.Events.SolutionEvents; // And install listeners to solution opened/closed events _solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(_addInView.OnSolutionOpened); _solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(_addInView.OnSolutionClosed); // If a solution is already opened, just simulate opening the solution if (_applicationObject.Solution.IsOpen) _addInView.OnSolutionOpened(); } } // Always display the AddIn if NAntAddin is selected on menu _addInWindow.Activate(); ////////////////////////////////////////////////////////////////////////// handled = true; return; } } }
protected override void Initialize() { this.dte = GetService(typeof(SDTE)) as DTE; this.solutionEvents = this.dte.Events.SolutionEvents; this.solutionEvents.Opened += this.solutionEvents_Opened; this.solutionEvents.BeforeClosing += this.solutionEvents_BeforeClosing; this.projectItemsEvents = ((EnvDTE80.Events2)this.dte.Events).ProjectItemsEvents; this.projectItemsEvents.ItemAdded += this.projectItemsEvents_ItemAdded; this.projectItemsEvents.ItemRemoved += this.projectItemsEvents_ItemRemoved; }
/// <summary> /// Constructor /// </summary> /// <param name="package">VSPackage instance to get all the different Visual Studio /// component references from</param> /// public EventBus(Package package, ViewModel.MainViewModel mainViewMode) { Package = package; MainViewModel = mainViewMode; // Setup the DTE helper DTE = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; _SolutionEvents = DTE.Events.SolutionEvents; _SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); _SolutionEvents.BeforeClosing += new _dispSolutionEvents_BeforeClosingEventHandler(SolutionEvents_BeforeClosing); }
public GoToDefinitionFilterProvider([Import(typeof(SVsServiceProvider))] System.IServiceProvider serviceProvider) { this.serviceProvider = serviceProvider; var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var events = dte.Events as Events2; if (events != null) { this.solutionEvents = events.SolutionEvents; this.solutionEvents.AfterClosing += Cleanup; } }
private SolutionManager() { dte = (DTE) Package.GetGlobalService(typeof (DTE)); solutionEvents = dte.Events.SolutionEvents; solutionEvents.Opened += OnSolutionOpened; solutionEvents.AfterClosing += OnAfterClosing; if (dte.Solution.IsOpen) { OnSolutionOpened(); } }
/// <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(); Logger.Initialise(); this.dte = Package.GetGlobalService(typeof(DTE)) as DTE2; this.events = this.dte.Events as Events2; this.solutionEvents = this.events.SolutionEvents; this.solutionEvents.Opened += SolutionEvents_Opened; this.solutionEvents.AfterClosing += Solution_AfterClosed; }
public DartProjectTracker([Import]SVsServiceProvider serviceProvider) { var dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE)); // Subscribe to project changes. solutionEvents = dte.Events.SolutionEvents; solutionEvents.ProjectAdded += TrackProject; solutionEvents.ProjectRemoved += UntrackProject; solutionEvents.BeforeClosing += UntrackAllProjects; // Subscribe for existing projects already open when we were triggered. foreach (Project project in dte.Solution.Projects) TrackProject(project); }
/// <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 OnInitialize() { // --- Prepare project system extension files CheckCpsFiles(); // --- We are going to use this singleton instance Default = this; RegisterEditorFactory(new RomEditorFactory()); RegisterEditorFactory(new TzxEditorFactory()); RegisterEditorFactory(new TapEditorFactory()); RegisterEditorFactory(new DisAnnEditorFactory()); RegisterEditorFactory(new SpConfEditorFactory()); // --- Register providers SpectrumMachine.Reset(); SpectrumMachine.RegisterProvider <IRomProvider>(() => new PackageRomProvider()); SpectrumMachine.RegisterProvider <IKeyboardProvider>(() => new KeyboardProvider()); SpectrumMachine.RegisterProvider <IBeeperProvider>(() => new AudioWaveProvider()); SpectrumMachine.RegisterProvider <ITapeProvider>(() => new VsIntegratedTapeProvider()); SpectrumMachine.RegisterProvider <ISoundProvider>(() => new AudioWaveProvider(AudioProviderType.Psg)); DebugInfoProvider = new VsIntegratedSpectrumDebugInfoProvider(); SpectrumMachine.RegisterProvider <ISpectrumDebugInfoProvider>(() => DebugInfoProvider); // --- Prepare for package shutdown _packageDteEvents = ApplicationObject.Events.DTEEvents; _packageDteEvents.OnBeginShutdown += () => { PackageClosing?.Invoke(this, EventArgs.Empty); }; _solutionEvents = ApplicationObject.Events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.AfterClosing += OnSolutionClosed; // --- Create other helper objects CodeManager = new Z80CodeManager(); TestManager = new Z80TestManager(); StateFileManager = new VmStateFileManager(); ErrorList = new ErrorListWindow(); TaskList = new TaskListWindow(); }
public DockableCLArgsControl() { InitializeComponent(); savedArgs = new NamedArgsDictionary(); debugEvents = IDEUtils.DTE.Events.DebuggerEvents; debugEvents.OnEnterRunMode += DebuggerEvents_OnEnterRunMode; solutionEvents = IDEUtils.DTE.Events.SolutionEvents; solutionEvents.Opened += SolutionEvents_OnOpened; solutionEvents.AfterClosing += SolutionEvents_OnAfterClosing; Properties.Settings.Default.PropertyChanged += OnSettingChanged; foreach (var commandBinding in CmdArgs.TextArea.CommandBindings.Cast <CommandBinding>()) { if (commandBinding.Command == ApplicationCommands.Paste) { commandBinding.PreviewCanExecute += new CanExecuteRoutedEventHandler(pasteCommandBinding_PreviewCanExecute); break; } } SetTextBoxProperties(); runChangedHandler = false; CmdArgs.Text = IDEUtils.GetCommandArgs(); runChangedHandler = true; CmdArgs.IsEnabled = false; try { Init(); } catch (Exception) { throw;// Don't care if it fails here } }
/// <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 Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // 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 this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await VSBuildTimeReportWindowCommand.InitializeAsync(this); // Get solution build manager _sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2; if (_sbm != null) { _sbm.AdviseUpdateSolutionEvents(this, out _); } // Must hold a reference to the solution events object or the events wont fire, garbage collection related _events = GetDTE().Events.SolutionEvents; _events.Opened += Solution_Opened; LoadAndInitializeBuildSession(); }
private async Task BindEventsAsync(CancellationToken cancellationToken) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var ide = _serviceProvider.Resolve <IIDE>(); // Capture solution events. Otherwise it gets GC'ed. _solutionEvents = ide.Environment.Events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpensOrCloses; _solutionEvents.AfterClosing += OnSolutionOpensOrCloses; // This package could load after a solution has loaded. If a solution is loaded and the session manager has // not yet loaded any solution settings, fire the event. var sessionManager = _serviceProvider.Resolve <ISessionManager>(); if (sessionManager.HasSolutionSettingsLoaded == false && ide.Environment.Solution?.IsOpen == true) { OnSolutionOpensOrCloses(); } }
private void Initialize() { _dte = TaskExplorerWindowCommand.Instance.ServiceProvider.GetService(typeof(DTE)) as DTE2; if (_dte == null) { throw new InvalidOperationException("Solution info cannot be loaded"); } UpdateState(); _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.Opened += () => { UpdateState(); SolutionOpened?.Invoke(this); }; _solutionEvents.AfterClosing += () => { UpdateState(); SolutionClosed?.Invoke(this); }; }
private ProjectEventCommand(IServiceProvider provider) { _provider = provider; _listeners = new ConcurrentDictionary <Project, FileSystemWatcher>(); var dte = (DTE2)provider.GetService(typeof(DTE)); _events = dte.Events.SolutionEvents; if (dte.Solution.IsOpen) { OnSolutionOpened(); } _events.Opened += OnSolutionOpened; _events.BeforeClosing += OnSolutionClosing; _events.ProjectAdded += EnsureProjectIsActive; _events.ProjectRemoved += OnProjectRemoved; _timer = new Timer(TimerElapsed, null, 0, Timeout.Infinite); }
/// <summary> /// Sets the Visual Studio IDE object. /// </summary> private DTE InitializeDTE() { // Store the dte so that it can be used later. var dte = Package.GetService <DTE>(); _events = dte.Events; // Registers handlers for the Activated and Closing events from the text window. _windowsEvents = _events.get_WindowEvents(null); _windowsEvents.WindowActivated += windowsEvents_WindowActivated; _windowsEvents.WindowClosing += windowsEvents_WindowClosing; // Registers handlers for certain solution events. _solnEvents = _events.SolutionEvents; _solnEvents.Opened += solnEvents_Opened; _solnEvents.QueryCloseSolution += solnEvents_QueryCloseSolution; // Get the code model data. _codeCache = new CodeOutlineCache(_control, dte); return(dte); }
internal void UnsubscribeToSolutionExplorerChanges() { if (!isListeningToSolutionExplorerChanges) { return; } DTE dte = (DTE)serviceProvider.GetService(typeof(DTE)); if (dte != null) { DTE2 dte2 = (DTE2)dte; this.solutionEvents = dte.Events.SolutionEvents; solutionEvents.ProjectAdded -= new _dispSolutionEvents_ProjectAddedEventHandler(OnProjectAdded); this.solutionItemsEvents = dte.Events.SolutionItemsEvents; solutionItemsEvents.ItemRemoved -= new _dispProjectItemsEvents_ItemRemovedEventHandler(OnProjectItemRemoved); solutionItemsEvents.ItemRenamed -= new _dispProjectItemsEvents_ItemRenamedEventHandler(OnProjectItemRenamed); } isListeningToSolutionExplorerChanges = false; }
internal protected virtual async System.Threading.Tasks.Task SubscribeToSolutionEventsAsync() { if (!this.init) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var asyncServiceProvider = serviceProvider.GetService(typeof(SAsyncServiceProvider)) as IAsyncServiceProvider; var dte = await asyncServiceProvider?.GetServiceAsync(typeof(SDTE)) as DTE2; this.solutionEvents = dte.Events.SolutionEvents; this.solutionEvents.BeforeClosing += () => { lock (@lock) { this.cache = new MemoryCache("commitTypes"); } }; this.init = true; } }
public DteEventsHandler(DTE _dte) { dte = _dte; var events = dte.Events as Events2; buildEvents = events.BuildEvents; buildEvents.OnBuildBegin += buildEvents_OnBuildBegin; buildEvents.OnBuildProjConfigBegin += OnBuildProjConfigBegin; buildEvents.OnBuildProjConfigDone += OnBuildProjConfigDone; buildEvents.OnBuildDone += buildEvents_OnBuildDone; documentEvents = events.get_DocumentEvents(null); documentEvents.DocumentSaved += DocumentSaved; projectItemsEvents = events.ProjectItemsEvents; projectItemsEvents.ItemAdded += ProjectItemsEvents_ItemAdded; projectItemsEvents.ItemRemoved += ProjectItemsEvents_ItemRemoved; projectItemsEvents.ItemRenamed += ProjectItemsEvents_ItemRenamed; solutionEvents = events.SolutionEvents; solutionEvents.ProjectAdded += SolutionEvents_ProjectAdded; solutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved; solutionEvents.Opened += SolutionEvents_Opened; solutionEvents.AfterClosing += SolutionEvents_AfterClosing; var debugCommandsGUID = "{5EFC7975-14BC-11CF-9B2B-00AA00573819}"; debugStartEvents = events.get_CommandEvents(debugCommandsGUID, 295); debugStartEvents.BeforeExecute += debugStartEvents_BeforeExecute; debugStartWithoutDebuggingEvents = events.get_CommandEvents(debugCommandsGUID, 368); debugStartWithoutDebuggingEvents.BeforeExecute += debugStartWithoutDebuggingEvents_BeforeExecute; dispId_VCFileConfiguration_ExcludedFromBuild = GetPropertyDispId(typeof(VCFileConfiguration), "ExcludedFromBuild"); dispId_VCCLCompilerTool_UsePrecompiledHeader = GetPropertyDispId(typeof(VCCLCompilerTool), "UsePrecompiledHeader"); dispId_VCCLCompilerTool_PrecompiledHeaderThrough = GetPropertyDispId(typeof(VCCLCompilerTool), "PrecompiledHeaderThrough"); dispId_VCCLCompilerTool_PreprocessorDefinitions = GetPropertyDispId(typeof(VCCLCompilerTool), "PreprocessorDefinitions"); dispId_VCCLCompilerTool_AdditionalIncludeDirectories = GetPropertyDispId(typeof(VCCLCompilerTool), "AdditionalIncludeDirectories"); InitializeVCProjects(); }
/// <summary> /// Subscribe to all events necessary for correct operation of this /// Visual Studio extension /// </summary> /// <param name="dteEvents"><see cref="DTE2.Events"/> property</param> public void SubscribeTo(Events2 dteEvents) { // Keep references to objects with events that will be subscribed // to: otherwise they can go out of scope and be garbage collected _projectItemsEvents = dteEvents.ProjectItemsEvents; _solutionEvents = dteEvents.SolutionEvents; _windowEvents = dteEvents.WindowEvents; _windowEvents.WindowActivated += WindowEventsWindowActivated; _windowEvents.WindowClosing += WindowEventsWindowClosing; _windowEvents.WindowCreated += WindowEventsWindowCreated; _projectItemsEvents.ItemRemoved += ProjectItemsEventsItemRemoved; _projectItemsEvents.ItemRenamed += ProjectItemsEventsItemRenamed; _solutionEvents.AfterClosing += SolutionEventsAfterClosing; _solutionEvents.BeforeClosing += _solutionEvents_BeforeClosing; _solutionEvents.Opened += SolutionEventsOpened; _solutionEvents.ProjectAdded += SolutionEventsProjectAdded; _solutionEvents.ProjectRenamed += SolutionEventsProjectRenamed; }
private void Initialize() { if (m_DTE == null) { return; } m_SolutionEvents = m_DTE.Events.SolutionEvents; m_SolutionEvents.Opened += SolutionEvents_Opened; m_SolutionEvents.ProjectAdded += SolutionEvents_ProjectAdded; m_SolutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved; m_SolutionEvents.QueryCloseSolution += SolutionEvents_QueryCloseSolution; m_ProjectItemsEvents = m_DTE.Events.MiscFilesEvents; m_ProjectItemsEvents.ItemAdded += ProjectItemsEvents_ItemAdded; m_ProjectItemsEvents.ItemRemoved += ProjectItemsEvents_ItemRemoved; m_DocumentEvents = m_DTE.Events.DocumentEvents; m_DocumentEvents.DocumentSaved += DocumentEvents_DocumentSaved; this.ParseFiles(); }
protected override void Initialize() { Logger.Initialize(this, Constants.VSIX_NAME); _dte = GetService(typeof(DTE)) as DTE2; _dispatcher = Dispatcher.CurrentDispatcher; Package = this; Events2 events = _dte.Events as Events2; _events = events.SolutionEvents; _events.AfterClosing += () => { ErrorList.CleanAllErrors(); }; _events.ProjectRemoved += (project) => { ErrorList.CleanAllErrors(); }; CreateConfig.Initialize(this); Recompile.Initialize(this); CompileOnBuild.Initialize(this); RemoveConfig.Initialize(this); CompileAllFiles.Initialize(this); base.Initialize(); }
public AutoAddDelete(Plugin plugin) : base("AutoAddDelete", "Automatically adds and deletes files matching project add/delete") { m_plugin = plugin; m_projectEvents = ((EnvDTE80.Events2)m_plugin.App.Events).ProjectItemsEvents; m_solutionEvents = ((EnvDTE80.Events2)m_plugin.App.Events).SolutionEvents; if (((Config)m_plugin.Options).autoAdd) { Log.Info("Adding handlers for automatically add files to perforce as you add them to the project"); m_projectEvents.ItemAdded += new _dispProjectItemsEvents_ItemAddedEventHandler(OnItemAdded); m_solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(OnProjectAdded); } if (((Config)m_plugin.Options).autoDelete) { Log.Info("Adding handlers for automatically deleting files from perforce as you remove them from the project"); m_projectEvents.ItemRemoved += new _dispProjectItemsEvents_ItemRemovedEventHandler(OnItemRemoved); m_solutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(OnProjectRemoved); } }
private async Task InitializeAsync() { await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); HttpHandlerResourceV3.CredentialService = _credentialServiceProvider.GetCredentialService(); _vsSolution = _serviceProvider.GetService <SVsSolution, IVsSolution>(); _vsMonitorSelection = _serviceProvider.GetService <SVsShellMonitorSelection, IVsMonitorSelection>(); var solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid; _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie); uint cookie; var hr = _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); ErrorHandler.ThrowOnFailure(hr); var dte = _serviceProvider.GetDTE(); // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events. _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.BeforeClosing += OnBeforeClosing; _solutionEvents.AfterClosing += OnAfterClosing; _solutionEvents.ProjectAdded += OnEnvDTEProjectAdded; _solutionEvents.ProjectRemoved += OnEnvDTEProjectRemoved; _solutionEvents.ProjectRenamed += OnEnvDTEProjectRenamed; var vSStd97CmdIDGUID = VSConstants.GUID_VSStandardCommandSet97.ToString("B"); var solutionSaveID = (int)VSConstants.VSStd97CmdID.SaveSolution; var solutionSaveAsID = (int)VSConstants.VSStd97CmdID.SaveSolutionAs; _solutionSaveEvent = dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveID]; _solutionSaveAsEvent = dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveAsID]; _solutionSaveEvent.BeforeExecute += SolutionSaveAs_BeforeExecute; _solutionSaveEvent.AfterExecute += SolutionSaveAs_AfterExecute; _solutionSaveAsEvent.BeforeExecute += SolutionSaveAs_BeforeExecute; _solutionSaveAsEvent.AfterExecute += SolutionSaveAs_AfterExecute; _projectSystemCache.CacheUpdated += NuGetCacheUpdate_After; }); }
internal OnBuildPackageRestorer(ISolutionManager solutionManager, IPackageRestoreManager packageRestoreManager, IServiceProvider serviceProvider, ISourceRepositoryProvider sourceRepositoryProvider, ISettings settings, INuGetProjectContext nuGetProjectContext) { SolutionManager = solutionManager; SourceRepositoryProvider = sourceRepositoryProvider; Settings = settings; NuGetProjectContext = nuGetProjectContext; PackageRestoreManager = packageRestoreManager; _dte = ServiceLocator.GetInstance <DTE>(); _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.AfterClosing += SolutionEvents_AfterClosing; _errorListProvider = new ErrorListProvider(serviceProvider); }
/// <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() { OpenFileCustomCommand.Initialize(this); base.Initialize(); UnadviseSolutionEvents(); AdviseSolutionEvents(); DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; // set up listeners for solution modified events solutionEvents = dte2.Events.SolutionEvents; solutionEvents.ProjectAdded += SolutionEvents_ProjectAdded; solutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved; solutionEvents.ProjectRenamed += SolutionEvents_ProjectRenamed; // set up listeners for project modified events projectItemsEvents = ((Events2)dte2.Events).ProjectItemsEvents; projectItemsEvents.ItemAdded += ProjectItemsEvents_ItemAdded; projectItemsEvents.ItemRemoved += ProjectItemsEvents_ItemRemoved; projectItemsEvents.ItemRenamed += ProjectItemsEvents_ItemRenamed; }
private void Init() { dte = Package.GetGlobalService(typeof(DTE)) as DTE2; if (dte != null) { events = dte.Events as Events2; if (events != null) { dteEvents = events.DTEEvents; solutionEvents = events.SolutionEvents; dteEvents.OnBeginShutdown += ShutDown; solutionEvents.Opened += () => SwitchStartupDir("\n====== Solution opening Detected ======\n"); } } terminalController.SetShell(optionMgr.Shell); terminalController.Init(GetProjectPath()); terminalController.InvokeCmd("\n[Global Init Script ...]\n", optionMgr.getGlobalScript()); }
/// <summary> /// Init constructor. /// Registers for solution events inside Visual Studio IDE. /// </summary> public SolutionEventsListener(DTE2 dte) { appObject = dte; dteEvents = (Events2)dte.Events; solutionEvents = dteEvents.SolutionEvents; // mount even handlers, they will be detached during Dispose() method call: try { solutionEvents.Opened += SolutionEvents_Opened; solutionEvents.AfterClosing += SolutionEvents_AfterClosing; solutionEvents.ProjectAdded += SolutionEvents_ProjectAdded; solutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved; solutionEvents.ProjectRenamed += SolutionEvents_ProjectRenamed; solutionEvents.QueryCloseSolution += SolutionEvents_QueryCloseSolution; } catch (Exception ex) { Trace.WriteLine(ex.Message); Trace.WriteLine(ex.StackTrace); } }
/// <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() { TruffleMenu.Initialize(this); base.Initialize(); this.TrufflePane = new OutputPane(this, "Truffle"); this.TestRPCPane = new OutputPane(this, "TestRPC"); // Documentation says this is Microsoft Interal Use Only. // How else do we determine the solution that's opened? this._dte = (DTE)this.GetService(typeof(DTE)); this._solutionEvents = ((Events)this._dte.Events).SolutionEvents; this._solutionEvents.Opened += SolutionOpened; this._solutionEvents.AfterClosing += SolutionClosed; TestRPCPane.runner.OnStart += () => { this.RecheckEnvironment(); }; // Set all variables as not in a solution initially. SolutionClosed(); }
/// <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() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); Dte = this.GetService(typeof(_DTE)) as _DTE; buildEvents = Dte.Events.BuildEvents; solutionEvents = Dte.Events.SolutionEvents; projectItemsEvents = ((EnvDTE80.Events2)Dte.Events).ProjectItemsEvents; ConnectEvents(); base.Initialize(); System.Threading.Tasks.Task.Run(() => { telemetry = new TelemetryClient(); telemetry.InstrumentationKey = "d5013fa4-b253-4166-9071-5b6c874acd0f"; telemetry.Context.Session.Id = Guid.NewGuid().ToString(); telemetry.Context.Device.OperatingSystem = Environment.OSVersion.ToString(); telemetry.Context.Device.Model = "VSIX"; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(typeof(Mubiquity).Assembly.Location); telemetry.Context.Device.Type = fvi.FileVersion; }); }
/// <summary> /// Disconnect from <see cref="DocumentEvents"/>. /// </summary> private void DisconnectFromVsEvents() { if (this.documentEvents != null) { this.documentEvents.DocumentSaved -= this.OnDocumentSaved; this.documentEvents.DocumentClosing -= this.OnDocumentClosing; this.documentEvents = null; } if (this.buildEvents != null) { this.buildEvents.OnBuildBegin -= this.OnBuildBegin; this.buildEvents.OnBuildDone -= this.OnBuildDone; this.buildEvents = null; } if (this.solutionEvents != null) { this.solutionEvents.Opened -= this.OnOpenedSolution; this.solutionEvents.BeforeClosing -= this.OnBeforeClosingSolution; this.solutionEvents = null; } }
private SolutionManager(DTE dte) { if (dte == null) { throw new ArgumentNullException("dte"); } _dte = dte; // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events. _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.Opened += OnSolutionOpened; _solutionEvents.BeforeClosing += OnBeforeClosing; _solutionEvents.AfterClosing += OnAfterClosing; _solutionEvents.ProjectAdded += OnProjectAdded; _solutionEvents.ProjectRemoved += OnProjectRemoved; _solutionEvents.ProjectRenamed += OnProjectRenamed; if (_dte.Solution.IsOpen) { OnSolutionOpened(); } }
/// <summary> /// Release used VS IDE resources. /// </summary> public void Dispose() { if (solution != null && solutionEventsCookie != 0) { GC.SuppressFinalize(this); solution.UnadviseSolutionEvents(solutionEventsCookie); solutionEventsCookie = 0; solution = null; } if (solutionEvents != null) { solutionEvents.Opened -= SolutionEvents_Opened; solutionEvents.AfterClosing -= SolutionEvents_AfterClosing; solutionEvents.ProjectAdded -= SolutionEvents_ProjectAdded; solutionEvents.ProjectRemoved -= SolutionEvents_ProjectRemoved; solutionEvents.ProjectRenamed -= SolutionEvents_ProjectRenamed; solutionEvents.QueryCloseSolution -= SolutionEvents_QueryCloseSolution; solutionEvents = null; dteEvents = null; appObject = null; } }
/// <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 async System.Threading.Tasks.Task InitializeAsync(System.Threading.CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { this.GetLogger().LogInformation(this.GetPackageName(), "Initializing."); await base.InitializeAsync(cancellationToken, progress); try { System.Windows.Application.Current.Deactivated += this.HandleCurrentApplicationDeactivated; var dte = (DTE)this.GetService(typeof(DTE)); this.solutionEvents = dte.Events.SolutionEvents; this.solutionEvents.BeforeClosing += this.HandleBeforeClosingSolution; this.solutionEvents.Opened += this.HandleSolutionOpened; this.solutionOpen = dte.Solution != null; this.GetLogger().LogInformation(this.GetPackageName(), "Initialized."); } catch (Exception exception) { this.GetLogger().LogError(this.GetPackageName(), "Exception during initialization", exception); } }
public async Task CloseSolutionAsync(bool saveIfExists = false) { await JoinableTaskFactory.SwitchToMainThreadAsync(); var solution = (IVsSolution)ServiceProvider.GetService(typeof(SVsSolution)); if (!await IsSolutionOpenAsync()) { return; } if (saveIfExists) { await SaveSolutionAsync(); } using (var semaphore = new SemaphoreSlim(1)) using (var solutionEvents = new SolutionEvents(TestServices, solution)) { await semaphore.WaitAsync(); solutionEvents.AfterCloseSolution += HandleAfterCloseSolution; try { ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_DeleteProject | (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave, pHier: null, docCookie: 0)); await semaphore.WaitAsync(); } finally { solutionEvents.AfterCloseSolution -= HandleAfterCloseSolution; } // Local functions void HandleAfterCloseSolution(object sender, EventArgs e) => semaphore.Release(); } }
protected override int QueryClose(out bool canClose) { int result = base.QueryClose(out canClose); if (!canClose) { return(result); } if (_solutionEvents != null) { _solutionEvents.ProjectRemoved -= ProjectRemoved; _solutionEvents = null; } if (_buildEvents != null) { _buildEvents.OnBuildBegin -= OnBuildBegin; _buildEvents = null; } if (_documentEvents != null) { _documentEvents.DocumentSaved -= DocumentSaved; _documentEvents = null; } if (_projectItemsEvents != null) { _projectItemsEvents.ItemAdded -= ItemAdded; _projectItemsEvents.ItemRemoved -= ItemRemoved; _projectItemsEvents.ItemRenamed -= ItemRenamed; } if (_controller != null) { _controller.Dispose(); } return(result); }
public DTE2EventListener(AWPackage package) { this._package = package; var dte2Events = this._package.DTE2Service.Events; _buildEv = dte2Events.BuildEvents; _documentEv = dte2Events.DocumentEvents; _selectionEv = dte2Events.SelectionEvents; _solutionEv = dte2Events.SolutionEvents; _windowEv = dte2Events.WindowEvents; _buildEv.OnBuildBegin += buildEvents_OnBuildBegin; _buildEv.OnBuildDone += buildEvents_OnBuildDone; _documentEv.DocumentOpened += documentEv_DocumentOpened; _documentEv.DocumentSaved += documentEv_DocumentSaved; _documentEv.DocumentClosing += documentEv_DocumentClosing; _selectionEv.OnChange += selectionEv_OnChange; _solutionEv.Opened += solutionEvents_Opened; _solutionEv.BeforeClosing += solutionEv_BeforeClosing; _windowEv.WindowActivated += windowEv_WindowActivated; _windowEv.WindowClosing += windowEv_WindowClosing; _windowEv.WindowCreated += windowEv_WindowCreated; _windowEv.WindowMoved += windowEv_WindowMoved; }
protected override void Initialize() { _dte = GetService(typeof(DTE)) as DTE2; _dispatcher = Dispatcher.CurrentDispatcher; Package = this; Logger.Initialize(this, Constants.VSIX_NAME); Telemetry.SetDeviceName(_dte.Edition); Events2 events = _dte.Events as Events2; _solutionEvents = events.SolutionEvents; _solutionEvents.AfterClosing += () => { ErrorList.CleanAllErrors(); }; _solutionEvents.ProjectRemoved += (project) => { ErrorList.CleanAllErrors(); }; CreateBundle.Initialize(this); UpdateBundle.Initialize(this); UpdateAllFiles.Initialize(this); BundleOnBuild.Initialize(this); RemoveBundle.Initialize(this); base.Initialize(); }
internal SolutionManager(DTE dte, IVsSolution vsSolution, IVsMonitorSelection vsMonitorSelection) { if (dte == null) { throw new ArgumentNullException("dte"); } _dte = dte; _vsSolution = vsSolution; _vsMonitorSelection = vsMonitorSelection; // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events. _solutionEvents = _dte.Events.SolutionEvents; // can be null in unit tests if (vsMonitorSelection != null) { Guid solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid; _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie); uint cookie; int hr = _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); ErrorHandler.ThrowOnFailure(hr); } _solutionEvents.BeforeClosing += OnBeforeClosing; _solutionEvents.AfterClosing += OnAfterClosing; _solutionEvents.ProjectAdded += OnProjectAdded; _solutionEvents.ProjectRemoved += OnProjectRemoved; _solutionEvents.ProjectRenamed += OnProjectRenamed; if (_dte.Solution.IsOpen) { OnSolutionOpened(); } }