예제 #1
0
        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);
        }
예제 #2
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));
        }
예제 #3
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();
        }
예제 #4
0
파일: VsVimHost.cs 프로젝트: 0-F/VsVim
        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);
        }
예제 #5
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);
            }
        }
        public VisualStudioDocumentTrackingService(IServiceProvider serviceProvider)
        {
            _visibleFrames = ImmutableList<FrameListener>.Empty;

            _monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));
            _monitorSelection.AdviseSelectionEvents(this, out _cookie);
        }
 public CSharpResetInteractiveMenuCommand(
     OleMenuCommandService menuCommandService,
     IVsMonitorSelection monitorSelection,
     IComponentModel componentModel)
     : base(ContentTypeNames.CSharpContentType, menuCommandService, monitorSelection, componentModel)
 {
 }
        protected override void Initialize()
        {
            base.Initialize();

            vsMonitorSelection = (IVsMonitorSelection)GetService(typeof(IVsMonitorSelection));
            dte = GetService(typeof(SDTE)) as DTE;

            if (provider == null)
            {
                var preferences = new PreferencesProvider("VisualStudio2010");
                provider = new CloudFoundryProvider(preferences);
            }

            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if (null != mcs)
            {
                mcs.AddCommand(new MenuCommand(CloudFoundryExplorer,
                               new CommandID(GuidList.guidCloudFoundryCmdSet,
                               (int)PkgCmdIDList.cmdidCloudFoundryExplorer)));

                mcs.AddCommand(new MenuCommand(PushApplication,
                               new CommandID(GuidList.guidCloudFoundryCmdSet,
                               (int)PkgCmdIDList.cmdidPushCloudFoundryApplication)));

                mcs.AddCommand(new MenuCommand(UpdateApplication,
                               new CommandID(GuidList.guidCloudFoundryCmdSet,
                               (int)PkgCmdIDList.cmdidUpdateCloudFoundryApplication)));
            }
        }
        public void Register()
        {
            if (vsMonitorSelection == null)
                vsMonitorSelection = GetMonitorSelection();

            if(vsMonitorSelection != null)
                vsMonitorSelection.AdviseSelectionEvents(this, out selectionEventsCookie);
        }
예제 #10
0
 internal VsResetInteractive(DTE dte, IComponentModel componentModel, IVsMonitorSelection monitorSelection, IVsSolutionBuildManager buildManager, Func<string, string> createReference, Func<string, string> createImport)
     : base(createReference, createImport)
 {
     _dte = dte;
     _componentModel = componentModel;
     _monitorSelection = monitorSelection;
     _buildManager = buildManager;
 }
        public void Unregister()
        {
            if (vsMonitorSelection == null)
                vsMonitorSelection = GetMonitorSelection();

            if (vsMonitorSelection != null)
                vsMonitorSelection.UnadviseSelectionEvents(selectionEventsCookie);
        }
예제 #12
0
		public VsHierarchySelection (
			[Import (typeof (SVsServiceProvider))] IServiceProvider services,
			IAsyncManager asyncManager)
		{
			solution = services.GetService<SVsSolution, IVsHierarchy> ();
			monitorSelection = services.GetService<SVsShellMonitorSelection, IVsMonitorSelection> ();
			this.asyncManager = asyncManager;
		}
        public IList <IVsHierarchy> GetSelectedProjects()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            List <IVsHierarchy> rslt = null;
            IVsMonitorSelection vsMonitorSelection = GetVsMonitorSelection();

            if (vsMonitorSelection != null)
            {
                bool success = PackageHelper.Success(vsMonitorSelection.GetCurrentSelection(out IntPtr hierarchyPtr, out uint itemId, out IVsMultiItemSelect multiSelect, out IntPtr containerPtr));

                if (IntPtr.Zero != containerPtr)
                {
                    Marshal.Release(containerPtr);
                }

                if (success)
                {
                    rslt = new List <IVsHierarchy>();

                    if (itemId == (uint)VSConstants.VSITEMID.Selection && multiSelect != null)
                    {
                        success = PackageHelper.Success(multiSelect.GetSelectionInfo(out uint itemCount, out int fSingleHierarchy));

                        if (success)
                        {
                            VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount];

                            success = PackageHelper.Success(multiSelect.GetSelectedItems(0, itemCount, items));

                            if (success)
                            {
                                foreach (VSITEMSELECTION item in items)
                                {
                                    if (item.pHier == null || rslt.Contains(item.pHier))
                                    {
                                        continue;
                                    }

                                    rslt.Add(item.pHier);
                                }
                            }
                        }
                    }
                    else if (hierarchyPtr != IntPtr.Zero)
                    {
                        object uniqueObjectForIUnknown = Marshal.GetUniqueObjectForIUnknown(hierarchyPtr);

                        if (uniqueObjectForIUnknown != null && uniqueObjectForIUnknown is IVsHierarchy)
                        {
                            IVsHierarchy hierarchy = (IVsHierarchy)uniqueObjectForIUnknown;
                            rslt.Add(hierarchy);
                        }
                    }
                }
            }
            return(rslt);
        }
        public static EnvDTE.Project GetActiveProject(this IVsMonitorSelection vsMonitorSelection)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IntPtr             ppHier = IntPtr.Zero;
            uint               pitemid;
            IVsMultiItemSelect ppMIS;
            IntPtr             ppSC = IntPtr.Zero;

            try
            {
                IVsHierarchy hierarchy = null;

                vsMonitorSelection.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC);
                if (ppHier == IntPtr.Zero)
                {
                    return(null);
                }

                // multiple items are selected.
                if (pitemid == (uint)VSConstants.VSITEMID.Selection)
                {
                    VSITEMSELECTION[] vsItemSelections = ppMIS.GetSelectedItemsInSingleHierachy();
                    if (vsItemSelections != null && vsItemSelections.Length > 0)
                    {
                        VSITEMSELECTION sel = vsItemSelections[0];
                        hierarchy = sel.pHier;
                    }
                }
                else
                {
                    hierarchy = Marshal.GetTypedObjectForIUnknown(ppHier, typeof(IVsHierarchy)) as IVsHierarchy;
                }

                if (hierarchy != null)
                {
                    object project;
                    if (hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out project) >= 0)
                    {
                        return(project as EnvDTE.Project);
                    }
                }

                return(null);
            }
            finally
            {
                if (ppHier != IntPtr.Zero)
                {
                    Marshal.Release(ppHier);
                }
                if (ppSC != IntPtr.Zero)
                {
                    Marshal.Release(ppSC);
                }
            }
        }
예제 #15
0
        public MonitoringSelectionService(IVsMonitorSelection monitorSelection)
        {
            if (monitorSelection == null)
            {
                throw new ArgumentNullException("monitorSelection");
            }

            m_monitorSelection = monitorSelection;
        }
        public ActiveDocumentLocator([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, ITextDocumentProvider textDocumentProvider)
        {
            this.textDocumentProvider = textDocumentProvider;

            RunOnUIThread.Run(() =>
            {
                monitorSelection = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
            });
        }
예제 #17
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()
        {
            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;
            }
        }
        /// <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);
            }
        }
예제 #19
0
        public static SortCommandState GetCommandState(IVsMonitorSelection monitorSelection)
        {
            IntPtr             hierarchyPointer, selectionContainerPointer;
            IVsMultiItemSelect multiItemSelect;
            uint itemId;

            monitorSelection.GetCurrentSelection(out hierarchyPointer,
                                                 out itemId,
                                                 out multiItemSelect,
                                                 out selectionContainerPointer);

            var selectedHierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPointer, typeof(IVsHierarchy)) as IVsHierarchy;

            Marshal.Release(hierarchyPointer);

            object selectedObject;

            selectedHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject);

            var projectItems = new List <ProjectItem>();
            var activeDocumentProjectItem = selectedObject as ProjectItem;

            // Context menu invoked on the active document or on an item in Solution Explorer
            if (activeDocumentProjectItem != null)
            {
                projectItems.Add(activeDocumentProjectItem);
            }

            // Context menu was invoked on multiple selected items in Solution Explorer
            else if (multiItemSelect != null)
            {
                uint itemCount;
                int  isSingleHierarchy;

                multiItemSelect.GetSelectionInfo(out itemCount, out isSingleHierarchy);
                var selectedItems = new VSITEMSELECTION[itemCount];
                multiItemSelect.GetSelectedItems(0, itemCount, selectedItems);

                foreach (var item in selectedItems)
                {
                    selectedHierarchy.GetProperty(item.itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject);

                    var projectItem = selectedObject as ProjectItem;
                    if (projectItem != null)
                    {
                        projectItems.Add(projectItem);
                    }
                }
            }

            return(new SortCommandState
            {
                IsVisible = (projectItems.Count > 0) && projectItems.TrueForAll(DocumentHelper.IsResXProjectItem),
                IsEnabled = (projectItems.Count > 0) && projectItems.TrueForAll(item => item.Document?.ReadOnly != true),
                SelectedFiles = projectItems.Select(item => item.FileNames[0]).ToArray()
            });
        }
        public VisualStudioDocumentTrackingService(IServiceProvider serviceProvider)
        {
            _tracker = new NonRoslynTextBufferTracker(this);

            _visibleFrames = ImmutableList <FrameListener> .Empty;

            _monitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));
            _monitorSelection.AdviseSelectionEvents(this, out _cookie);
        }
예제 #21
0
        public void Register()
        {
            IVsMonitorSelection vsMonitorSelection = GetMonitorSelection();

            if (vsMonitorSelection != null)
            {
                vsMonitorSelection.AdviseSelectionEvents(this, out _selectionEventsCookie);
            }
        }
예제 #22
0
            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);
            }
예제 #23
0
        /// <summary>
        /// Constructs and Registers ("Advises") for Project retargeting events if the IVsTrackProjectRetargeting service is available
        /// Otherwise, it simply exits
        /// </summary>
        /// <param name="dte"></param>
        public ProjectRetargetingHandler(DTE dte, ISolutionManager solutionManager, IServiceProvider serviceProvider)
        {
            if (dte == null)
            {
                throw new ArgumentNullException(nameof(dte));
            }

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

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

            var vsTrackProjectRetargeting = serviceProvider.GetService(typeof(SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting;

            if (vsTrackProjectRetargeting != null)
            {
                _vsMonitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(IVsMonitorSelection));
                Debug.Assert(_vsMonitorSelection != null);
                _errorListProvider = new ErrorListProvider(serviceProvider);
                _dte                       = dte;
                _solutionManager           = solutionManager;
                _vsTrackProjectRetargeting = vsTrackProjectRetargeting;

                // Register for ProjectRetargetingEvents
                if (_vsTrackProjectRetargeting.AdviseTrackProjectRetargetingEvents(this, out _cookieProjectRetargeting) == VSConstants.S_OK)
                {
                    Debug.Assert(_cookieProjectRetargeting != 0);
                    _dte.Events.BuildEvents.OnBuildBegin    += BuildEvents_OnBuildBegin;
                    _dte.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing;
                }
                else
                {
                    _cookieProjectRetargeting = 0;
                }

                // Register for BatchRetargetingEvents. Using BatchRetargetingEvents, we need to detect platform retargeting
                if (_vsTrackProjectRetargeting.AdviseTrackBatchRetargetingEvents(this, out _cookieBatchRetargeting) == VSConstants.S_OK)
                {
                    Debug.Assert(_cookieBatchRetargeting != 0);
                    if (_cookieProjectRetargeting == 0)
                    {
                        // Register for dte Events only if they are not already registered for
                        _dte.Events.BuildEvents.OnBuildBegin    += BuildEvents_OnBuildBegin;
                        _dte.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing;
                    }
                }
                else
                {
                    _cookieBatchRetargeting = 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);
 }
예제 #25
0
            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);
            }
예제 #26
0
        public void Unregister()
        {
            IVsMonitorSelection vsMonitorSelection = GetMonitorSelection();

            if (vsMonitorSelection != null)
            {
                vsMonitorSelection.UnadviseSelectionEvents(_selectionEventsCookie);
            }
        }
예제 #27
0
        protected override void OnInitialize()
        {
            IVsMonitorSelection monitor = GetService <IVsMonitorSelection>();

            if (monitor != null)
            {
                Marshal.ThrowExceptionForHR(monitor.AdviseSelectionEvents(this, out _cookie));
            }
        }
 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);
 }
예제 #29
0
 internal ResetInteractive(DTE dte, IComponentModel componentModel, IVsMonitorSelection monitorSelection, IVsSolutionBuildManager buildManager, Func <string, string> createReference, Func <string, string> createImport)
 {
     _dte              = dte;
     _componentModel   = componentModel;
     _monitorSelection = monitorSelection;
     _buildManager     = buildManager;
     _createReference  = createReference;
     _createImport     = createImport;
 }
예제 #30
0
        private IVsMonitorSelection GetMonitorSelection()
        {
            if (_vsMonitorSelection == null)
            {
                _vsMonitorSelection = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
            }

            return(_vsMonitorSelection);
        }
예제 #31
0
 public EnvironmentSwitcherManager(IServiceProvider serviceProvider)
 {
     _serviceProvider  = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     _optionsService   = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>();
     _registryService  = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>();
     _monitorSelection = serviceProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
     _shell            = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
     _workspaceService = serviceProvider.GetComponentModel().GetService <IVsFolderWorkspaceService>();
     AllFactories      = Enumerable.Empty <IPythonInterpreterFactory>();
 }
예제 #32
0
        protected SelectionListener(ServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.monSel = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            if(this.monSel == null)
            {
                throw new InvalidOperationException();
            }
        }
예제 #33
0
        /// <summary>
        /// Changes the UI state to a busy state. The pattern to use this method is to assign the result value
        /// to a variable in a using statement.
        /// </summary>
        /// <returns>An implementation of <seealso cref="IDisposable"/> that will cleanup the state change on dispose.</returns>
        public static IDisposable SetShellUIBusy()
        {
            IVsMonitorSelection monitorSelection = GetMonitorSelectionService();

            SetUIContext(monitorSelection, VSConstants.UICONTEXT.SolutionBuilding_guid, true);
            SetUIContext(monitorSelection, VSConstants.UICONTEXT.NotBuildingAndNotDebugging_guid, false);
            SetUIContext(monitorSelection, VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid, false);

            return(new Disposable(SetShellNormal));
        }
예제 #34
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));
            }
        }
         public void Dispose() {
            if (vsMonitorSelection != null) {
               vsMonitorSelection = null;
            }

            if (baseCommandTarget != null) {
               baseCommandTarget = null;
            }

         }
예제 #36
0
        protected SelectionListener(ServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.monSel          = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            if (this.monSel == null)
            {
                throw new InvalidOperationException();
            }
        }
        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);
            });
        }
예제 #38
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));
            }
        }
예제 #39
0
        public static async Task InitializeAsync(UXXPackage package)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;

            IVsMonitorSelection monitorSelection = await package.GetServiceAsync(typeof(IVsMonitorSelection)) as IVsMonitorSelection;

            Instance = new Commands(package, monitorSelection, commandService);
        }
예제 #40
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;
 }
예제 #41
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));
        }
예제 #42
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;
        }
예제 #43
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);
            }
        }
예제 #44
0
        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);
        }
        public void Dispose()
        {
            if (_monSelCookie != 0U && _monitorSelection != null)
            {
                _monitorSelection.UnadviseSelectionEvents(_monSelCookie);
            }

            _monitorSelection = null;

            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
        }
		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;
		}
예제 #47
0
            public CmdStateCacheItem(IVsMonitorSelection monitor, uint cookie)
            {
                if (monitor == null)
                {
                    throw new ArgumentNullException("monitor");
                }

                _cookie = cookie;

                Reload(monitor);
            }
예제 #48
0
        protected SelectionListener(ServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.monSel = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            Debug.Assert(this.monSel != null, "Could not get the IVsMonitorSelection object from the services exposed by this project");

            if (this.monSel == null)
            {
                throw new InvalidOperationException();
            }
        }
예제 #49
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;
         }
     }
 }
예제 #50
0
        protected SelectionListener(ServiceProvider serviceProviderParameter)
        {
            if (serviceProviderParameter == null) {
                throw new ArgumentNullException("serviceProviderParameter");
            }

            this.serviceProvider = serviceProviderParameter;
            this.monSel = this.serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            if (this.monSel == null) {
                throw new InvalidOperationException();
            }
        }
예제 #51
0
        /// <summary>
        /// Constructs and Registers ("Advises") for Project retargeting events if the IVsTrackProjectRetargeting service is available
        /// Otherwise, it simply exits
        /// </summary>
        /// <param name="dte"></param>
        public ProjectRetargetingHandler(DTE dte, IServiceProvider serviceProvider)
        {
            if (dte == null)
            {
                throw new ArgumentNullException("dte");
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            IVsTrackProjectRetargeting vsTrackProjectRetargeting = serviceProvider.GetService(typeof(SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting;
            if (vsTrackProjectRetargeting != null)
            {
                _vsMonitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(IVsMonitorSelection));
                Debug.Assert(_vsMonitorSelection != null);
                _errorListProvider = new ErrorListProvider(serviceProvider);
                _dte = dte;
                _vsTrackProjectRetargeting = vsTrackProjectRetargeting;

                // Register for ProjectRetargetingEvents
                if (_vsTrackProjectRetargeting.AdviseTrackProjectRetargetingEvents(this, out _cookieProjectRetargeting) == VSConstants.S_OK)
                {
                    Debug.Assert(_cookieProjectRetargeting != 0);
                    _dte.Events.BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
                    _dte.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing;
                }
                else
                {
                    _cookieProjectRetargeting = 0;
                }

                // Register for BatchRetargetingEvents. Using BatchRetargetingEvents, we need to detect platform retargeting
                if (_vsTrackProjectRetargeting.AdviseTrackBatchRetargetingEvents(this, out _cookieBatchRetargeting) == VSConstants.S_OK)
                {
                    Debug.Assert(_cookieBatchRetargeting != 0);
                    if (_cookieProjectRetargeting == 0)
                    {
                        // Register for dte Events only if they are not already registered for
                        _dte.Events.BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
                        _dte.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing;
                    }
                }
                else
                {
                    _cookieBatchRetargeting = 0;
                }
            }
        }
예제 #52
0
        public static Project GetActiveProject(IVsMonitorSelection vsMonitorSelection)
        {
            IntPtr ppHier = IntPtr.Zero;
            uint pitemid;
            IVsMultiItemSelect ppMIS;
            IntPtr ppSC = IntPtr.Zero;

            try
            {
                vsMonitorSelection.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC);

                if (ppHier == IntPtr.Zero)
                {
                    return null;
                }

                // multiple items are selected.
                if (pitemid == (uint) VSConstants.VSITEMID.Selection)
                {
                    return null;
                }

                IVsHierarchy hierarchy =
                    Marshal.GetTypedObjectForIUnknown(ppHier, typeof (IVsHierarchy)) as IVsHierarchy;
                if (hierarchy != null)
                {
                    object project;
                    if (
                        hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int) __VSHPROPID.VSHPROPID_ExtObject,
                            out project) >= 0)
                    {
                        return (Project) project;
                    }
                }

                return null;
            }
            finally
            {
                if (ppHier != IntPtr.Zero)
                {
                    Marshal.Release(ppHier);
                }
                if (ppSC != IntPtr.Zero)
                {
                    Marshal.Release(ppSC);
                }
            }
        }
예제 #53
0
 internal VsAdapter(
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
     IEditorOptionsFactoryService editorOptionsFactoryService,
     IIncrementalSearchFactoryService incrementalSearchFactoryService,
     SVsServiceProvider serviceProvider)
 {
     _incrementalSearchFactoryService = incrementalSearchFactoryService;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
     _editorOptionsFactoryService = editorOptionsFactoryService;
     _serviceProvider = serviceProvider;
     _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
     _table = new RunningDocumentTable(_serviceProvider);
     _uiShell = _serviceProvider.GetService<SVsUIShell, IVsUIShell>();
     _monitorSelection = _serviceProvider.GetService<SVsShellMonitorSelection, IVsMonitorSelection>();
 }
 public AbstractResetInteractiveMenuCommand(
     string contentType,
     OleMenuCommandService menuCommandService,
     IVsMonitorSelection monitorSelection,
     IComponentModel componentModel)
 {
     _contentType = contentType;
     _menuCommandService = menuCommandService;
     _monitorSelection = monitorSelection;
     _componentModel = componentModel;
     _resetInteractiveCommand = _componentModel.DefaultExportProvider
         .GetExports<IResetInteractiveCommand, ContentTypeMetadata>()
         .Where(resetInteractiveService => resetInteractiveService.Metadata.ContentTypes.Contains(_contentType))
         .SingleOrDefault();
 }
예제 #55
0
파일: VsAdapter.cs 프로젝트: jieah/VsVim
 internal VsAdapter(
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
     IEditorOptionsFactoryService editorOptionsFactoryService,
     IIncrementalSearchFactoryService incrementalSearchFactoryService,
     IPowerToolsUtil powerToolsUtil,
     SVsServiceProvider vsServiceProvider)
 {
     _incrementalSearchFactoryService = incrementalSearchFactoryService;
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
     _editorOptionsFactoryService = editorOptionsFactoryService;
     _serviceProvider = vsServiceProvider;
     _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
     _table = new RunningDocumentTable(_serviceProvider);
     _uiShell = _serviceProvider.GetService<SVsUIShell, IVsUIShell>();
     _monitorSelection = _serviceProvider.GetService<SVsShellMonitorSelection, IVsMonitorSelection>();
     _powerToolsUtil = powerToolsUtil;
     _visualStudioVersion = vsServiceProvider.GetVisualStudioVersion();
 }
예제 #56
0
        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);
            }
        }
예제 #57
0
        public CommandController(DTE dte,
            Func<EventHandler, MenuCommand> initBreakOnAllCommand,
            IVsMonitorSelection monitorSelection,
            ExceptionBreakManager breakManager,
            IDiagnosticLogger logger)
        {
            _monitorSelection = monitorSelection;
            _breakManager = breakManager;
            _logger = logger;
            _breakOnAllCommand = initBreakOnAllCommand(breakOnAllCommand_Callback);

            _requiredUiContextCookies = new HashSet<uint>(RequiredUIContexts.Select(ConvertToUIContextCookie));

            UpdateCommandAvailability();
            _selectionEventsCookie = SubscribeToSelectionEvents();

            UpdateCommandCheckedState();
            _breakManager.CurrentStateChanged += breakManager_CurrentStateChanged;

            _debugExceptionsEvents = SubscribeToDebugExceptionsCommand(dte);
        }
예제 #58
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();
        }
예제 #60
0
            public CmdStateCacheItem(IVsMonitorSelection monitor, uint cookie)
            {
                if (monitor == null)
                    throw new ArgumentNullException("monitor");

                _cookie = cookie;

                int active;
                _active = ErrorHandler.Succeeded(monitor.IsCmdUIContextActive(_cookie, out active)) && active != 0;
            }