Пример #1
0
        protected override void Initialize()
        {
            base.Initialize();

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CoAppApplication.ResolveAssembly);

            _vsMonitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection));
            Module.DTE = (DTE)GetService(typeof(DTE));

            // get the solution exists/not building/not debugging cookie
            var solutionExistsAndNotBuildingAndNotDebuggingContextGuid = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid;
            _vsMonitorSelection.GetCmdUIContextCookie(ref solutionExistsAndNotBuildingAndNotDebuggingContextGuid, out _solutionExistsAndNotBuildingAndNotDebuggingContextCookie);

            // get the solution exists and fully loaded cookie
            var solutionExistsAndFullyLoadedContextGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid;
            _vsMonitorSelection.GetCmdUIContextCookie(ref solutionExistsAndFullyLoadedContextGuid, out _solutionExistsAndFullyLoadedContextCookie);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            AddMenuCommandHandlers();

            Module.Initialize();
            Module.OnStartup(null, null);

            DTEEvents = Module.DTE.Events.DTEEvents;
            DTEEvents.OnBeginShutdown += () => Module.OnExit(null, null);

            var timer = new DispatcherTimer();
            timer.Tick += (o, a) => TrackSolution();
            timer.Interval += new TimeSpan(0, 0, 0, 1);
            timer.Start();
        }
        private async Task SubscribeAsync(Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            _serviceProvider = serviceProvider;

            var commandService = await serviceProvider.GetServiceAsync <IMenuCommandService, IMenuCommandService>(throwOnFailure : false);

            var menuCommandId = new CommandID(CommandSet, CommandId);
            var menuItem      = new OleMenuCommand(
                OnRestorePackages, null, BeforeQueryStatusForPackageRestore, menuCommandId);

            commandService.AddCommand(menuItem);

            _vsMonitorSelection = await serviceProvider.GetServiceAsync <IVsMonitorSelection, IVsMonitorSelection>();

            Assumes.Present(_vsMonitorSelection);

            // get the solution not building and not debugging cookie
            var guidCmdUI = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid;

            _vsMonitorSelection.GetCmdUIContextCookie(
                ref guidCmdUI, out _solutionExistsAndFullyLoadedContextCookie);

            guidCmdUI = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid;
            _vsMonitorSelection.GetCmdUIContextCookie(
                ref guidCmdUI, out _solutionNotBuildingAndNotDebuggingContextCookie);
        }
Пример #3
0
        /// <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();

            // get the UI context cookie for the debugging mode
            _vsMonitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection));
            // get debugging context cookie
            Guid debuggingContextGuid = VSConstants.UICONTEXT_Debugging;
            _vsMonitorSelection.GetCmdUIContextCookie(ref debuggingContextGuid, out _debuggingContextCookie);

            // get the solution building cookie
            Guid solutionBuildingContextGuid = VSConstants.UICONTEXT_SolutionBuilding;
            _vsMonitorSelection.GetCmdUIContextCookie(ref solutionBuildingContextGuid, out _solutionBuildingContextCookie);

            _dte = ServiceLocator.GetInstance<DTE>();
            _consoleStatus = ServiceLocator.GetInstance<IConsoleStatus>();
            _packageRestoreManager = ServiceLocator.GetInstance<IPackageRestoreManager>();
            Debug.Assert(_packageRestoreManager != null);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            AddMenuCommandHandlers();

            // when NuGet loads, if the current solution has package 
            // restore mode enabled, we make sure every thing is set up correctly.
            // For example, projects which were added outside of VS need to have
            // the <Import> element added.
            if (_packageRestoreManager.IsCurrentSolutionEnabledForRestore)
            {
                _packageRestoreManager.EnableCurrentSolutionForRestore(quietMode: true);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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();
        }
        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));
        }
        internal IssueVisualizationToolWindowCommand(IToolWindowService toolWindowService, IMenuCommandService commandService, IVsMonitorSelection monitorSelection, ILogger logger)
        {
            this.toolWindowService = toolWindowService ?? throw new ArgumentNullException(nameof(toolWindowService));
            this.monitorSelection  = monitorSelection ?? throw new ArgumentNullException(nameof(monitorSelection));
            this.logger            = logger ?? throw new ArgumentNullException(nameof(logger));

            if (commandService == null)
            {
                throw new ArgumentNullException(nameof(commandService));
            }

            var menuCommandId = new CommandID(CommandSet, ViewToolWindowCommandId);
            var menuItem      = new MenuCommand(Execute, menuCommandId);

            commandService.AddCommand(menuItem);

            menuCommandId = new CommandID(CommandSet, ErrorListCommandId);
            // We're showing the command in two places in the UI, but we only do a status check when it's called from the Error List context menu.
            ErrorListMenuItem = new OleMenuCommand(Execute, null, ErrorListQueryStatus, menuCommandId);
            commandService.AddCommand(ErrorListMenuItem);

            var uiContextGuid = new Guid(Constants.UIContextGuid);

            monitorSelection.GetCmdUIContextCookie(ref uiContextGuid, out uiContextCookie);
        }
Пример #8
0
        private CoreRegistersWindowCommand(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            this.package = package;

            ThreadHelper.ThrowIfNotOnUIThread( );
            SelectionService = ( IVsMonitorSelection )Package.GetGlobalService(typeof(SVsShellMonitorSelection));
            if (SelectionService == null)
            {
                return;
            }

            OleMenuCommandService commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                return;
            }

            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem      = new OleMenuCommand(ShowToolWindow, menuCommandID);

            commandService.AddCommand(menuItem);

            menuItem.BeforeQueryStatus += MenuItem_BeforeQueryStatus;
            Guid tempGuid = VSConstants.UICONTEXT.Debugging_guid;

            ErrorHandler.ThrowOnFailure(SelectionService.GetCmdUIContextCookie(ref tempGuid, out DebuggingContextCookie));
        }
        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();
        }
Пример #10
0
        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));
        }
Пример #11
0
        private void NotifyLoaded(bool started)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // We set the user context AnkhLoadCompleted active when we are loaded
            // This event can be used to trigger loading other packages that depend on AnkhSVN
            //
            // When the use:
            // [ProvideAutoLoad(AnkhId.AnkhLoadCompleted)]
            // On their package, they load automatically when we are completely loaded
            //

            IVsMonitorSelection ms = GetService <IVsMonitorSelection>();

            if (ms != null)
            {
                Guid gAnkhLoaded = new Guid(started ? AnkhId.AnkhRuntimeStarted : AnkhId.AnkhServicesAvailable);

                uint cky;
                if (VSErr.Succeeded(ms.GetCmdUIContextCookie(ref gAnkhLoaded, out cky)))
                {
                    ms.SetCmdUIContext(cky, 1);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Returns the AppId setting for the given AppId guid
        /// </summary>
        internal static bool GetAppidSetting(IServiceProvider provider, Guid setting)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            int isActive = 0;

            // Get the command UI context from the monitor service
            IVsMonitorSelection monitor = provider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            if (monitor != null)
            {
                uint cookie = 0;
                if (monitor.GetCmdUIContextCookie(ref setting, out cookie) == VSConstants.S_OK)
                {
                    int hr = monitor.IsCmdUIContextActive(cookie, out isActive);
                    if (VSConstants.S_OK != hr)
                    {
                        Debug.Fail("IVsMonitorSelection.IsCmdUIContextActive failed.");
                        // If the call fails then default to the context not being active.
                        isActive = 0;
                    }
                }
            }

            return(isActive != 0);
        }
Пример #13
0
        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;
        }
        public ActiveSolutionBoundTracker(IHost host, IActiveSolutionTracker activeSolutionTracker, ILogger logger)
        {
            extensionHost   = host ?? throw new ArgumentNullException(nameof(host));
            solutionTracker = activeSolutionTracker ?? throw new ArgumentNullException(nameof(activeSolutionTracker));
            this.logger     = logger ?? throw new ArgumentNullException(nameof(logger));

            vsMonitorSelection = host.GetService <SVsShellMonitorSelection, IVsMonitorSelection>();
            vsMonitorSelection.GetCmdUIContextCookie(ref BoundSolutionUIContext.Guid, out boundSolutionContextCookie);

            configurationProvider = extensionHost.GetService <IConfigurationProviderService>();
            configurationProvider.AssertLocalServiceIsNotNull();

            errorListInfoBarController = extensionHost.GetService <IErrorListInfoBarController>();
            errorListInfoBarController.AssertLocalServiceIsNotNull();

            // The user changed the binding through the Team Explorer
            extensionHost.VisualStateManager.BindingStateChanged += OnBindingStateChanged;

            // The solution changed inside the IDE
            solutionTracker.ActiveSolutionChanged += OnActiveSolutionChanged;

            CurrentConfiguration = configurationProvider.GetConfiguration();

            SetBoundSolutionUIContext();
        }
Пример #15
0
        /// <summary>
        /// Creates custom UICONTEXT for MenuCommand visibility tracking.
        /// For example,it is possible to set the restriction to add new view only in Views folder and its subfolders
        /// </summary>
        /// <returns>cookie of the registered custom UICONTEXT</returns>
        private uint RegisterContext()
        {
            uint retVal;
            Guid uiContext = GuidList.UICONTEXT_ViewsSelected;

            SelectionService.GetCmdUIContextCookie(ref uiContext, out retVal);
            return(retVal);
        }
Пример #16
0
 private void UpdateCommandVisibilityContext(bool enabled)
 {
     IVsMonitorSelection selMon = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection));
     uint cmdUIContextXenko;
     var cmdSet = GuidList.guidXenko_VisualStudio_PackageCmdSet;
     if (selMon.GetCmdUIContextCookie(ref cmdSet, out cmdUIContextXenko) == VSConstants.S_OK)
         selMon.SetCmdUIContext(cmdUIContextXenko, enabled ? 1 : 0);
 }
 public UDNDocRunningTableMonitor(IVsRunningDocumentTable rdt, IVsMonitorSelection ms, IVsEditorAdaptersFactoryService eafs, IVsUIShell uiShell, MarkdownPackage package)
 {
     this.RunningDocumentTable         = rdt;
     this.MonitorSelection             = ms;
     this.EditorAdaptersFactoryService = eafs;
     this.UIShell = uiShell;
     this.package = package;
     ms.GetCmdUIContextCookie(GuidList.guidMarkdownUIContext, out MarkdownModeUIContextCookie);
 }
 public UDNDocRunningTableMonitor(IVsRunningDocumentTable rdt, IVsMonitorSelection ms, IVsEditorAdaptersFactoryService eafs, IVsUIShell uiShell, MarkdownPackage package)
 {
     this.RunningDocumentTable = rdt;
     this.MonitorSelection = ms;
     this.EditorAdaptersFactoryService = eafs;
     this.UIShell = uiShell;
     this.package = package;
     ms.GetCmdUIContextCookie(GuidList.guidMarkdownUIContext, out MarkdownModeUIContextCookie);
 }
Пример #19
0
 /// <summary>
 /// Is Visual Studio in design mode.
 /// </summary>
 /// <param name="site">The service provider.</param>
 /// <returns>true if visual studio is in design mode</returns>
 public static bool IsVisualStudioInDesignMode(IServiceProvider site)
 {
     IVsMonitorSelection selectionMonitor = site.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
     uint cookie = 0;
     int active = 0;
     Guid designContext = VSConstants.UICONTEXT_DesignMode;
     ErrorHandler.ThrowOnFailure(selectionMonitor.GetCmdUIContextCookie(ref designContext, out cookie));
     ErrorHandler.ThrowOnFailure(selectionMonitor.IsCmdUIContextActive(cookie, out active));
     return active != 0;
 }
Пример #20
0
        private static void SetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid, bool value)
        {
            uint cookie = 0;

            ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie));
            if (cookie != 0)
            {
                ErrorHandler.ThrowOnFailure(monitorSelection.SetCmdUIContext(cookie, value ? 1 : 0));
            }
        }
Пример #21
0
        private void SetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid, bool value)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out uint cookie));
            if (cookie != 0)
            {
                ErrorHandler.ThrowOnFailure(monitorSelection.SetCmdUIContext(cookie, value ? 1 : 0));
            }
        }
Пример #22
0
        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 static uint RegisterContext()
		{
			// Initialize the selection service
			SelectionService = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection));
			// Get a cookie for our UI Context. This “registers” our
			// UI context with the selection service so we can set it again later.
			uint retVal;
			Guid uiContext = GuidList.guid_UICONTEXT_underSourceControl;
			SelectionService.GetCmdUIContextCookie(ref uiContext, out retVal);
			return retVal;
		}
Пример #24
0
        /// <summary>
        /// Create VS UI context
        /// </summary>
        /// <param name="guid">UI context guid</param>
        /// <returns>DWORD representation of the GUID identifying the command UI context</returns>
        public static uint CreateUiContext(Guid guid)
        {
            uint uiContextCookie = 0;

            if (_monitorSelectionService != null)
            {
                _monitorSelectionService.GetCmdUIContextCookie(guid, out uiContextCookie);
            }

            return(uiContextCookie);
        }
Пример #25
0
        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;
        }
Пример #26
0
        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));
        }
        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));
        }
Пример #28
0
        private static uint RegisterContext()
        {
            // Initialize the selection service
            SelectionService = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection));
            // Get a cookie for our UI Context. This “registers” our
            // UI context with the selection service so we can set it again later.
            uint retVal;
            Guid uiContext = GuidList.guid_UICONTEXT_underSourceControl;

            SelectionService.GetCmdUIContextCookie(ref uiContext, out retVal);
            return(retVal);
        }
Пример #29
0
        private bool GetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out uint cookie));
            if (cookie != 0)
            {
                ErrorHandler.ThrowOnFailure(monitorSelection.IsCmdUIContextActive(cookie, out int isActive));
                return(isActive != 0);
            }

            return(false);
        }
Пример #30
0
        private uint ConvertToUIContextCookie(Guid guid)
        {
            uint cookie;
            var  hr = _monitorSelection.GetCmdUIContextCookie(ref guid, out cookie);

            if (hr != VSConstants.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            _logger.WriteLine("Mapped UI context {0} to cookie {1}.", guid, cookie);
            return(cookie);
        }
Пример #31
0
        private static bool GetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid)
        {
            uint cookie   = 0;
            int  isActive = 0;

            ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie));
            if (cookie != 0)
            {
                ErrorHandler.ThrowOnFailure(monitorSelection.IsCmdUIContextActive(cookie, out isActive));
            }

            return(isActive != 0);
        }
Пример #32
0
        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // get the UI context cookie for the debugging mode
            _vsMonitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection));
            // get debugging context cookie
            Guid debuggingContextGuid = VSConstants.UICONTEXT_Debugging;

            _vsMonitorSelection.GetCmdUIContextCookie(ref debuggingContextGuid, out _debuggingContextCookie);

            // get the solution building cookie
            Guid solutionBuildingContextGuid = VSConstants.UICONTEXT_SolutionBuilding;

            _vsMonitorSelection.GetCmdUIContextCookie(ref solutionBuildingContextGuid, out _solutionBuildingContextCookie);

            _dte           = ServiceLocator.GetInstance <DTE>();
            _consoleStatus = ServiceLocator.GetInstance <IConsoleStatus>();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            AddMenuCommandHandlers();
        }
Пример #33
0
 public SourceRScriptCommand(IRInteractiveWorkflow interactiveWorkflow, IActiveWpfTextViewTracker activeTextViewTracker)
     : base(RGuidList.RCmdSetGuid, RPackageCommandId.icmdSourceRScript) {
     _interactiveWorkflow = interactiveWorkflow;
     _activeTextViewTracker = activeTextViewTracker;
     _operations = interactiveWorkflow.Operations;
     _monitorSelection = VsAppShell.Current.GetGlobalService<IVsMonitorSelection>(typeof(SVsShellMonitorSelection));
     if (_monitorSelection != null) {
         var debugUIContextGuid = new Guid(UIContextGuids.Debugging);
         if (ErrorHandler.Failed(_monitorSelection.GetCmdUIContextCookie(ref debugUIContextGuid, out _debugUIContextCookie))) {
             _monitorSelection = null;
         }
     }
 }
Пример #34
0
        /// <summary>
        /// Sets the current UI context.
        /// </summary>
        /// <param name="uiContextGuid">The GUID to uniquely identify the UI context.</param>
        /// <param name="isActive">Determines if the UI context is active or not.</param>
        public async Task SetUIContextAsync(Guid uiContextGuid, bool isActive)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsMonitorSelection svc = await VS.Services.GetMonitorSelectionAsync();

            int cookieResult = svc.GetCmdUIContextCookie(uiContextGuid, out uint cookie);

            ErrorHandler.ThrowOnFailure(cookieResult);

            int setContextResult = svc.SetCmdUIContext(cookie, isActive ? 1 : 0);

            ErrorHandler.ThrowOnFailure(setContextResult);
        }
Пример #35
0
        public static Result <bool> IsCmdUIContextActive(this IVsMonitorSelection selection, Guid cmdId)
        {
            uint cookie;
            var  hresult = selection.GetCmdUIContextCookie(ref cmdId, out cookie);

            if (ErrorHandler.Failed(hresult))
            {
                return(Result.CreateError(hresult));
            }

            int active;

            hresult = selection.IsCmdUIContextActive(cookie, out active);
            return(Result.CreateSuccessOrError(active != 0, hresult));
        }
Пример #36
0
        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;
        }
Пример #37
0
 public SourceRScriptCommand(IRInteractiveWorkflow interactiveWorkflow, IActiveWpfTextViewTracker activeTextViewTracker)
     : base(RGuidList.RCmdSetGuid, RPackageCommandId.icmdSourceRScript)
 {
     _interactiveWorkflow   = interactiveWorkflow;
     _activeTextViewTracker = activeTextViewTracker;
     _operations            = interactiveWorkflow.Operations;
     _monitorSelection      = VsAppShell.Current.GetGlobalService <IVsMonitorSelection>(typeof(SVsShellMonitorSelection));
     if (_monitorSelection != null)
     {
         var debugUIContextGuid = new Guid(UIContextGuids.Debugging);
         if (ErrorHandler.Failed(_monitorSelection.GetCmdUIContextCookie(ref debugUIContextGuid, out _debugUIContextCookie)))
         {
             _monitorSelection = null;
         }
     }
 }
Пример #38
0
        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();
            }
        }
        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();
        }
		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();
		}
        private static void SetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid, bool value)
        {
            uint cookie = 0;

            ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie));
            if (cookie != 0)
            {
                ErrorHandler.ThrowOnFailure(monitorSelection.SetCmdUIContext(cookie, value ? 1 : 0));
            }
        }
        private static bool GetUIContext(IVsMonitorSelection monitorSelection, Guid contextGuid)
        {
            uint cookie = 0;
            int isActive = 0;

            ErrorHandler.ThrowOnFailure(monitorSelection.GetCmdUIContextCookie(contextGuid, out cookie));
            if (cookie != 0)
            {
                ErrorHandler.ThrowOnFailure(monitorSelection.IsCmdUIContextActive(cookie, out isActive));
            }

            return isActive != 0;
        }
Пример #43
0
        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // get the UI context cookie for the debugging mode
            _vsMonitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection));
            // get debugging context cookie
            Guid debuggingContextGuid = VSConstants.UICONTEXT_Debugging;
            _vsMonitorSelection.GetCmdUIContextCookie(ref debuggingContextGuid, out _debuggingContextCookie);

            // get the solution building cookie
            Guid solutionBuildingContextGuid = VSConstants.UICONTEXT_SolutionBuilding;
            _vsMonitorSelection.GetCmdUIContextCookie(ref solutionBuildingContextGuid, out _solutionBuildingContextCookie);

            _dte = ServiceLocator.GetInstance<DTE>();
            _consoleStatus = ServiceLocator.GetInstance<IConsoleStatus>();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            AddMenuCommandHandlers();
        }