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)); }
protected override void Initialize() { base.Initialize(); //绑定textView事件 IVsMonitorSelection monitorSelection = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection)); ErrorHandler.ThrowOnFailure(monitorSelection.AdviseSelectionEvents(textViewEvent, out selectionEventCookie)); //绑定RunningDocTable事件 IVsRunningDocumentTable DocTables = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable)); DocTables.AdviseRunningDocTableEvents(docTableEvent, out runningDocEventCookie); // And we can query for the text manager service as we're surely running in // interactive mode. So this is the right time to register for text manager events. IConnectionPointContainer textManager = (IConnectionPointContainer)GetService(typeof(SVsTextManager)); Guid interfaceGuid = typeof(IVsTextManagerEvents).GUID; textManager.FindConnectionPoint(ref interfaceGuid, out tmConnectionPoint); tmConnectionPoint.Advise(TextManagerEventSink, out tmConnectionCookie); //todo:通过win32形式检测键盘输入 hookVs.InitHook(); }
internal VsVimHost( IVsAdapter adapter, ITextBufferFactoryService textBufferFactoryService, ITextEditorFactoryService textEditorFactoryService, ITextDocumentFactoryService textDocumentFactoryService, ITextBufferUndoManagerProvider undoManagerProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, IWordUtilFactory wordUtilFactory, ITextManager textManager, ISharedServiceFactory sharedServiceFactory, SVsServiceProvider serviceProvider) : base(textBufferFactoryService, textEditorFactoryService, textDocumentFactoryService, editorOperationsFactoryService) { _vsAdapter = adapter; _editorAdaptersFactoryService = editorAdaptersFactoryService; _wordUtilFactory = wordUtilFactory; _dte = (_DTE)serviceProvider.GetService(typeof(_DTE)); _vsExtensibility = (IVsExtensibility)serviceProvider.GetService(typeof(IVsExtensibility)); _textManager = textManager; _sharedService = sharedServiceFactory.Create(); _vsMonitorSelection = serviceProvider.GetService<SVsShellMonitorSelection, IVsMonitorSelection>(); uint cookie; _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); }
public VSSolutionManager() { _dte = ServiceLocator.GetInstance <DTE>(); _vsSolution = ServiceLocator.GetGlobalService <SVsSolution, IVsSolution>(); _vsMonitorSelection = ServiceLocator.GetGlobalService <SVsShellMonitorSelection, IVsMonitorSelection>(); // 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 += OnEnvDTEProjectAdded; _solutionEvents.ProjectRemoved += OnEnvDTEProjectRemoved; _solutionEvents.ProjectRenamed += OnEnvDTEProjectRenamed; }
internal VsVimHost( IVsAdapter adapter, ITextBufferFactoryService textBufferFactoryService, ITextEditorFactoryService textEditorFactoryService, ITextDocumentFactoryService textDocumentFactoryService, ITextBufferUndoManagerProvider undoManagerProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, ISmartIndentationService smartIndentationService, ITextManager textManager, ISharedServiceFactory sharedServiceFactory, IVimApplicationSettings vimApplicationSettings, IExtensionAdapterBroker extensionAdapterBroker, SVsServiceProvider serviceProvider, ITelemetryProvider telemetryProvider) : base(textBufferFactoryService, textEditorFactoryService, textDocumentFactoryService, editorOperationsFactoryService) { _vsAdapter = adapter; _editorAdaptersFactoryService = editorAdaptersFactoryService; _dte = (_DTE)serviceProvider.GetService(typeof(_DTE)); _vsExtensibility = (IVsExtensibility)serviceProvider.GetService(typeof(IVsExtensibility)); _textManager = textManager; _sharedService = sharedServiceFactory.Create(); _vsMonitorSelection = serviceProvider.GetService <SVsShellMonitorSelection, IVsMonitorSelection>(); _vimApplicationSettings = vimApplicationSettings; _smartIndentationService = smartIndentationService; _extensionAdapterBroker = extensionAdapterBroker; _vsMonitorSelection.AdviseSelectionEvents(this, out uint cookie); InitTelemetry(telemetryProvider.GetOrCreate(vimApplicationSettings, _dte), vimApplicationSettings); }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); _dte = (DTE2) await GetServiceAsync(typeof(EnvDTE.DTE)); Active = true; await this.JoinableTaskFactory.SwitchToMainThreadAsync(); _buildEvents = _dte.Events.BuildEvents; const string VSStd97CmdIDGuid = "{5efc7975-14bc-11cf-9b2b-00aa00573819}"; _buildCancel = _dte.Events.get_CommandEvents(VSStd97CmdIDGuid, (int)VSConstants.VSStd97CmdID.CancelBuild); _buildCancel.BeforeExecute += buildCancel_BeforeExecute; //Since Visual Studio 2012 has parallel builds, we only want to cancel the build process once. //This makes no difference for older versions of Visual Studio. _buildEvents.OnBuildBegin += delegate { _canExecute = true; }; _buildEvents.OnBuildDone += delegate { _canExecute = false; }; _buildEvents.OnBuildProjConfigDone += OnProjectBuildFinished; _selectionMonitor = (IVsMonitorSelection)GetGlobalService(typeof(SVsShellMonitorSelection)); var solutionHasMultipleProjects = VSConstants.UICONTEXT.SolutionHasMultipleProjects_guid; _selectionMonitor.GetCmdUIContextCookie(ref solutionHasMultipleProjects, out _solutionHasMultipleProjectsCookie); _selectionMonitor.AdviseSelectionEvents(this, out _selectionEventsCookie); InitializeMenuItem(); }
public VisualStudioDocumentTrackingService(IServiceProvider serviceProvider) { _visibleFrames = ImmutableList <FrameListener> .Empty; _monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection)); _monitorSelection.AdviseSelectionEvents(this, out _cookie); }
internal SelectionData() { ThreadHelper.ThrowIfNotOnUIThread(); selectionMonitor = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; InitializeSelectionItems(); InitializeContextDictionary(); IVsSettingsManager userSettings = Package.GetGlobalService(typeof(SVsSettingsManager)) as IVsSettingsManager; userSettings.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_UserSettings, out var settingsStore); LoadContextIDList(settingsStore, FavoriteContexts, "Favorites"); // at the point where we are created, we don't know what contexts are live so we need to look // for all of them that we know about. foreach (uint contextID in contextIDNames.Keys) { if (ErrorHandler.Succeeded(selectionMonitor.IsCmdUIContextActive(contextID, out var active)) && active != 0) { // Add the item to the live contexts LiveContexts.Add(contextIDNames[contextID]); contextIDNames[contextID].Enabled = true; } } selectionMonitor.AdviseSelectionEvents(this, out selectionEventsCookie); }
internal SelectionEvents() { ThreadHelper.ThrowIfNotOnUIThread(); IVsMonitorSelection monitor = VS.GetRequiredService <SVsShellMonitorSelection, IVsMonitorSelection>(); monitor.AdviseSelectionEvents(this, out _); }
internal VsVimHost( IVsAdapter adapter, ITextBufferFactoryService textBufferFactoryService, ITextEditorFactoryService textEditorFactoryService, ITextDocumentFactoryService textDocumentFactoryService, ITextBufferUndoManagerProvider undoManagerProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, ISmartIndentationService smartIndentationService, ITextManager textManager, ISharedServiceFactory sharedServiceFactory, IVimApplicationSettings vimApplicationSettings, SVsServiceProvider serviceProvider) : base(textBufferFactoryService, textEditorFactoryService, textDocumentFactoryService, editorOperationsFactoryService) { _vsAdapter = adapter; _editorAdaptersFactoryService = editorAdaptersFactoryService; _dte = (_DTE)serviceProvider.GetService(typeof(_DTE)); _vsExtensibility = (IVsExtensibility)serviceProvider.GetService(typeof(IVsExtensibility)); _textManager = textManager; _sharedService = sharedServiceFactory.Create(); _vsMonitorSelection = serviceProvider.GetService<SVsShellMonitorSelection, IVsMonitorSelection>(); _fontProperties = new TextEditorFontProperties(serviceProvider); _vimApplicationSettings = vimApplicationSettings; _smartIndentationService = smartIndentationService; uint cookie; _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); }
internal VsVimHost( IVsAdapter adapter, ITextBufferFactoryService textBufferFactoryService, ITextEditorFactoryService textEditorFactoryService, ITextDocumentFactoryService textDocumentFactoryService, ITextBufferUndoManagerProvider undoManagerProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, IWordUtilFactory wordUtilFactory, ITextManager textManager, ISharedServiceFactory sharedServiceFactory, SVsServiceProvider serviceProvider) : base(textBufferFactoryService, textEditorFactoryService, textDocumentFactoryService, editorOperationsFactoryService) { _vsAdapter = adapter; _editorAdaptersFactoryService = editorAdaptersFactoryService; _wordUtilFactory = wordUtilFactory; _dte = (_DTE)serviceProvider.GetService(typeof(_DTE)); _vsExtensibility = (IVsExtensibility)serviceProvider.GetService(typeof(IVsExtensibility)); _textManager = textManager; _sharedService = sharedServiceFactory.Create(); _vsMonitorSelection = serviceProvider.GetService <SVsShellMonitorSelection, IVsMonitorSelection>(); uint cookie; _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); }
protected override void Initialize() { base.Initialize(); _dte = (DTE2)GetGlobalService(typeof(DTE)); Active = true; _buildEvents = _dte.Events.BuildEvents; const string VSStd97CmdIDGuid = "{5efc7975-14bc-11cf-9b2b-00aa00573819}"; _buildCancel = _dte.Events.get_CommandEvents(VSStd97CmdIDGuid, (int)VSConstants.VSStd97CmdID.CancelBuild); _buildCancel.BeforeExecute += buildCancel_BeforeExecute; //Since Visual Studio 2012 has parallel builds, we only want to cancel the build process once. //This makes no difference for older versions of Visual Studio. _buildEvents.OnBuildBegin += delegate { _canExecute = true; }; _buildEvents.OnBuildDone += delegate { _canExecute = false; }; _buildEvents.OnBuildProjConfigDone += OnProjectBuildFinished; _selectionMonitor = (IVsMonitorSelection)GetGlobalService(typeof(SVsShellMonitorSelection)); var solutionHasMultipleProjects = VSConstants.UICONTEXT.SolutionHasMultipleProjects_guid; _selectionMonitor.GetCmdUIContextCookie(ref solutionHasMultipleProjects, out _solutionHasMultipleProjectsCookie); _selectionMonitor.AdviseSelectionEvents(this, out _selectionEventsCookie); InitializeMenuItem(); }
public void Register() { if (_vsMonitorSelection != null) { _vsMonitorSelection.AdviseSelectionEvents(this, out _selectionEventsCookie); } }
public VisualStudioDocumentTrackingService(SVsServiceProvider serviceProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService) { _editorAdaptersFactoryService = editorAdaptersFactoryService; _monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection)); _monitorSelection.AdviseSelectionEvents(this, out _cookie); }
public VisualStudioDocumentTrackingService(IServiceProvider serviceProvider) { _visibleFrames = ImmutableList<FrameListener>.Empty; _monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection)); _monitorSelection.AdviseSelectionEvents(this, out _cookie); }
public async Task RegisterAsync(IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken) { _vsMonitorSelection ??= await serviceProvider.GetServiceAsync <SVsShellMonitorSelection, IVsMonitorSelection>(_threadingContext.JoinableTaskFactory, throwOnFailure : false).ConfigureAwait(false); await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _vsMonitorSelection?.AdviseSelectionEvents(this, out _selectionEventsCookie); }
public Listener(MonitorSelectionService service, SVsServiceProvider serviceProvider) { Contract.Requires <ArgumentNullException>(service != null, "service"); Contract.Requires <ArgumentNullException>(serviceProvider != null, "serviceProvider"); _service = service; _monitorSelection = serviceProvider.GetMonitorSelection(); _monitorSelection.AdviseSelectionEvents(this, out _adviseCookie); }
/// <include file='doc\ShellDocumentManager.uex' path='docs/doc[@for="ShellDocumentManager.ShellDocumentManager"]/*' /> /// <devdoc> /// Public constructor. /// </devdoc> public ShellDocumentManager(IServiceProvider dsp) : base(dsp) { monitorSelectionService = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection)); if (monitorSelectionService != null) { selectionEventsCookie = monitorSelectionService.AdviseSelectionEvents(this); } }
public void Register() { IVsMonitorSelection vsMonitorSelection = GetMonitorSelection(); if (vsMonitorSelection != null) { vsMonitorSelection.AdviseSelectionEvents(this, out _selectionEventsCookie); } }
public Listener([NotNull] MonitorSelectionService service, [NotNull] SVsServiceProvider serviceProvider) { Requires.NotNull(service, nameof(service)); Requires.NotNull(serviceProvider, nameof(serviceProvider)); _service = service; _monitorSelection = serviceProvider.GetMonitorSelection(); _monitorSelection.AdviseSelectionEvents(this, out _adviseCookie); }
protected override void OnInitialize() { IVsMonitorSelection monitor = GetService <IVsMonitorSelection>(); if (monitor != null) { Marshal.ThrowExceptionForHR(monitor.AdviseSelectionEvents(this, out _cookie)); } }
/// <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() { try { base.Initialize(); SetTheme(); IVsMonitorSelection monitorSelection = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection)); monitorSelection.AdviseSelectionEvents(this, out cookie); // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { _handlers = new PackageHandlers(); _handlers.Register(mcs); _handlers.SwitchToSettings = new RelayCommand((o) => SwitchToSettings((o as PackageHandlers.ChoiceCommandParameters).Selected as ProfileSelection), (o) => HasProjectAvailableProfiles()); _handlers.ShowWorkItemView = new RelayCommand((o) => ShowWorkItemView()); _handlers.ShowChangesetView = new RelayCommand((o) => ShowChangesetView()); _handlers.RefreshBranches = new RelayCommand((o) => RefreshBranches()); _handlers.ShowVMergeHelp = new RelayCommand((o) => ShowVMergeHelp()); _handlers.SetTargetBranchChoiceHandler( (args) => GetAvailableMergeTargetBranches()); _handlers.TargetBranch = new RelayCommand((o) => MergeToTarget((o as PackageHandlers.ChoiceCommandParameters).Selected as MergeSelection)); _handlers.SetTargetBranch2ChoiceHandler( (args) => GetAvailableMergeTargetBranches()); _handlers.TargetBranch2 = new RelayCommand((o) => OpenChangesetView((o as PackageHandlers.ChoiceCommandParameters).Selected as MergeSelection)); _handlers.SetMatchingProfilesChoiceHandler( (args) => GetMatchingProfilesForBranch()); _handlers.MatchingProfiles = new RelayCommand((o) => LoadProfileAndMerge((o as PackageHandlers.ChoiceCommandParameters).Selected as ProfileSelection)); _handlers.SetSwitchToSettingsChoiceHandler( (args) => GetMatchingProfilesForProject()); _handlers.SetSwitchToSettingsGetSelectedChoiceHandler( (args) => GetActiveProfile()); } var dte = GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; _events = dte.Events as EnvDTE80.Events2; _events.WindowVisibilityEvents.WindowHiding += WindowVisibilityEvents_WindowHiding; _events.WindowVisibilityEvents.WindowShowing += WindowVisibilityEvents_WindowShowing; ((VsTfsUIInteractionProvider)Repository.Instance.TfsUIInteractionProvider).UIShell = GetService(typeof(SVsUIShell)) as IVsUIShell; Microsoft.VisualStudio.PlatformUI.VSColorTheme.ThemeChanged += (a) => SetTheme(); } catch (Exception ex) { SimpleLogger.Log(ex); throw; } }
public ActiveDocumentTracker([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, ITextDocumentProvider textDocumentProvider) { this.textDocumentProvider = textDocumentProvider; RunOnUIThread.Run(() => { monitorSelection = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; monitorSelection.AdviseSelectionEvents(this, out cookie); }); }
public VsSelectionEvents(IVsMonitorSelection vsMonitorSelection) { _vsMonitorSelection = vsMonitorSelection; // get the solution exists and fully loaded cookie Guid rguidCmdUI = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid; _vsMonitorSelection.GetCmdUIContextCookie(ref rguidCmdUI, out this._solutionExistsAndFullyLoadedContextCookie); ErrorHandler.ThrowOnFailure(_vsMonitorSelection.AdviseSelectionEvents(this, out _selectionEventsCookie)); }
private async Task InitializeAsync() { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _vsSolution = await _asyncServiceProvider.GetServiceAsync <SVsSolution, IVsSolution>(); var dte = await _asyncServiceProvider.GetDTEAsync(); UserAgent.SetUserAgentString( new UserAgentStringBuilder(VSNuGetClientName).WithVisualStudioSKU(dte.GetFullVsVersionString())); HttpHandlerResourceV3.CredentialService = new Lazy <ICredentialService>(() => { return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { return await _credentialServiceProvider.GetCredentialServiceAsync(); })); }); TelemetryActivity.NuGetTelemetryService = new NuGetVSTelemetryService(); _vsMonitorSelection = await _asyncServiceProvider.GetServiceAsync <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); // 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; }
/// <summary> /// Initialize. /// </summary> /// <remarks> /// Connects to the IVsMonitorSelection Service. /// </remarks> protected override void Initialize() { base.Initialize(); IVsMonitorSelection monitorSelectionService = this.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; uint cookie = 0; monitorSelectionService.AdviseSelectionEvents(this, out cookie); this.toolWindowIDList = GetToolWindowIdList(); }
public SolutionEventsListener(IServiceProvider serviceProvider) { solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution; solution?.AdviseSolutionEvents(this, out solutionEventsCookie); buildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager3; buildManager?.AdviseUpdateSolutionEvents3(this, out updateSolutionEventsCookie); monitorSelection = serviceProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; monitorSelection?.AdviseSelectionEvents(this, out selectionEventsCoockie); }
protected override void Initialize() { base.Initialize(); IVsMonitorSelection selMon = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection)); ErrorHandler.ThrowOnFailure(selMon.AdviseSelectionEvents(this, out selectionMonCookie)); Guid cmdGuid = new Guid(GuidList.guidAutoHideToolbarExampleCmdSetString); ErrorHandler.ThrowOnFailure(selMon.GetCmdUIContextCookie(ref cmdGuid, out this.cmdUIContextCookie)); }
private uint SubscribeToSelectionEvents() { uint cookie; var hr = _monitorSelection.AdviseSelectionEvents(this, out cookie); if (hr != VSConstants.S_OK) { Marshal.ThrowExceptionForHR(hr); } return(cookie); }
internal WindowActivationWatcher(IVsMonitorSelection monitorSelection) { //ThreadHelper.ThrowIfNotOnUIThread(); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; Validate.IsNotNull(monitorSelection, "monitorSelection"); _monitorSelection = monitorSelection; _monitorSelection?.AdviseSelectionEvents(this, out _monSelCookie); }
public UIContextHandler(AlcantareaPackage host) { m_host = host; IVsMonitorSelection service = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (service != null) { service.GetCmdUIContextCookie(VSConstants.UICONTEXT.SolutionExists_guid, out m_cookie_solution); service.GetCmdUIContextCookie(VSConstants.UICONTEXT.Debugging_guid, out m_cookie_debugging); service.GetCmdUIContextCookie(VSConstants.UICONTEXT.DesignMode_guid, out m_cookie_design); service.AdviseSelectionEvents(this, out m_cookie); } }
private void Open() { CheckOnUIThread(); if (!(this is IVsSelectionEvents)) { return; } IVsMonitorSelection monitorSelection = this._serviceProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; if (monitorSelection == null) { return; } monitorSelection.AdviseSelectionEvents(this as IVsSelectionEvents, out this._selectionEventsCookie); }
public VSSolutionManager() { _dte = ServiceLocator.GetInstance <DTE>(); _vsSolution = ServiceLocator.GetGlobalService <SVsSolution, IVsSolution>(); _vsMonitorSelection = ServiceLocator.GetGlobalService <SVsShellMonitorSelection, IVsMonitorSelection>(); // 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); } // Allow this constructor to be invoked from either the UI or a worker thread. This JTF call should be // cheap (minimal context switch cost) when we are already on the UI thread. ThreadHelper.JoinableTaskFactory.Run(async delegate { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); UserAgent.SetUserAgentString( new UserAgentStringBuilder().WithVisualStudioSKU(VSVersionHelper.GetFullVsVersionString())); }); _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; }
protected DocumentFrameMgr(IXmlDesignerPackage package) { _package = package; _editingContextMgr = new EditingContextManager(package); _package.FileNameChanged += OnAfterFileNameChanged; IServiceProvider sp = _package; _rdt = sp.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable; if (_rdt != null) { NativeMethods.ThrowOnFailure(_rdt.AdviseRunningDocTableEvents(this, out _rdtEventsCookie)); } _sel = sp.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; if (_sel != null) { _sel.AdviseSelectionEvents(this, out _selEventsCookie); } }
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(); } }
public Listener(MonitorSelectionService service, SVsServiceProvider serviceProvider) { Contract.Requires<ArgumentNullException>(service != null, "service"); Contract.Requires<ArgumentNullException>(serviceProvider != null, "serviceProvider"); _service = service; _monitorSelection = serviceProvider.GetMonitorSelection(); _monitorSelection.AdviseSelectionEvents(this, out _adviseCookie); }
protected override void Initialize() { base.Initialize(); _dte = (DTE2) GetGlobalService(typeof (DTE)); Active = true; _buildEvents = _dte.Events.BuildEvents; const string VSStd97CmdIDGuid = "{5efc7975-14bc-11cf-9b2b-00aa00573819}"; _buildCancel = _dte.Events.get_CommandEvents(VSStd97CmdIDGuid, (int)VSConstants.VSStd97CmdID.CancelBuild); _buildCancel.BeforeExecute += buildCancel_BeforeExecute; //Since Visual Studio 2012 has parallel builds, we only want to cancel the build process once. //This makes no difference for older versions of Visual Studio. _buildEvents.OnBuildBegin += delegate { _canExecute = true; }; _buildEvents.OnBuildDone += delegate { _canExecute = false; }; _buildEvents.OnBuildProjConfigDone += OnProjectBuildFinished; _selectionMonitor = (IVsMonitorSelection) GetGlobalService(typeof (SVsShellMonitorSelection)); var solutionHasMultipleProjects = VSConstants.UICONTEXT.SolutionHasMultipleProjects_guid; _selectionMonitor.GetCmdUIContextCookie(ref solutionHasMultipleProjects, out _solutionHasMultipleProjectsCookie); _selectionMonitor.AdviseSelectionEvents(this, out _selectionEventsCookie); InitializeMenuItem(); }
protected override void Initialize() { base.Initialize(); _dte = (DTE2) GetGlobalService(typeof (DTE)); Active = true; _buildEvents = _dte.Events.BuildEvents; //Since Visual Studio 2012 has parallel builds, we only want to cancel the build process once. //This makes no difference for older versions of Visual Studio. _buildEvents.OnBuildBegin += delegate { _canExecute = true; }; _buildEvents.OnBuildDone += delegate { _canExecute = false; }; _buildEvents.OnBuildProjConfigDone += OnProjectBuildFinished; _selectionMonitor = (IVsMonitorSelection) GetGlobalService(typeof (SVsShellMonitorSelection)); var solutionHasMultipleProjects = VSConstants.UICONTEXT.SolutionHasMultipleProjects_guid; _selectionMonitor.GetCmdUIContextCookie(ref solutionHasMultipleProjects, out _solutionHasMultipleProjectsCookie); _selectionMonitor.AdviseSelectionEvents(this, out _selectionEventsCookie); InitializeMenuItem(); }