示例#1
0
        int IVsHierarchy.Close()
        {
            _hierarchyClosed = true;
            this.Close();

            if (cookie != 0)
            {
                // Unsubscribe to events
                IVsTrackProjectDocuments2 trackDocuments = GetTrackProjectDocuments();
                trackDocuments.UnadviseTrackProjectDocumentsEvents(cookie);
                cookie = 0;
            }

            if (this._menuService != null)
            {
                OleMenuCommandService tempService = this._menuService;
                this._menuService = null;
                tempService.Dispose();
            }

            if (_inExecCommand == 0)
            {
                FreeInterfaces();
            }

            return(VSConstants.S_OK);
        }
        public TestFileAddRemoveListener(IServiceProvider serviceProvider, Guid projectGuid) {
            ValidateArg.NotNull(serviceProvider, "serviceProvider");

            _testProjectGuid = projectGuid;

            _projectDocTracker = serviceProvider.GetService<IVsTrackProjectDocuments2>(typeof(SVsTrackProjectDocuments));
        }
        public VsSourceControlTracker(
            ISolutionManager solutionManager,
            ISourceControlManagerProvider sourceControlManagerProvider,
            IVsTrackProjectDocuments2 projectTracker,
            Configuration.ISettings vsSettings)
        {
            if (projectTracker == null)
            {
                throw new ArgumentNullException("projectTracker");
            }

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

            _solutionManager = solutionManager;
            _projectTracker  = projectTracker;
            _sourceControlManagerProvider = sourceControlManagerProvider;
            _vsSettings = vsSettings;
            _projectDocumentListener = new TrackProjectDocumentEventListener(this);

            _solutionManager.SolutionOpened += OnSolutionOpened;
            _solutionManager.SolutionClosed += OnSolutionClosed;

            if (_solutionManager.IsSolutionOpen)
            {
                StartTracking();
            }
        }
示例#4
0
        public void Dispose()
        {
            // Unregister from receiving solution events
            if (VSConstants.VSCOOKIE_NIL != _vsSolutionEventsCookie)
            {
                IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution));
                sol.UnadviseSolutionEvents(_vsSolutionEventsCookie);
                _vsSolutionEventsCookie = VSConstants.VSCOOKIE_NIL;
            }

            // Unregister from receiving project documents
            if (VSConstants.VSCOOKIE_NIL != _tpdTrackProjectDocumentsCookie)
            {
                IVsTrackProjectDocuments2 tpdService = (IVsTrackProjectDocuments2)_sccProvider.GetService(typeof(SVsTrackProjectDocuments));
                tpdService.UnadviseTrackProjectDocumentsEvents(_tpdTrackProjectDocumentsCookie);
                _tpdTrackProjectDocumentsCookie = VSConstants.VSCOOKIE_NIL;
            }

            // Unregister from storrage events
            _sccStatusTracker.HGStatusChanged -= new HGLib.HGStatusChangedEvent(SetNodesGlyphsDirty);

            IVsSolutionBuildManager buildManagerService = _sccProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager;

            buildManagerService.UnadviseUpdateSolutionEvents(_dwBuildManagerCooky);
        }
示例#5
0
        public TestFileAddRemoveListener([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            ValidateArg.NotNull(serviceProvider, "serviceProvider");

            _projectDocTracker = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
            _documentTable     = Package.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
        }
        public VsSourceControlTracker(
            ISolutionManager solutionManager,
            IFileSystemProvider fileSystemProvider,
            IVsTrackProjectDocuments2 projectTracker,
            ISettings solutionSettings)
        {
            if (projectTracker == null)
            {
                throw new ArgumentNullException("projectTracker");
            }

            _solutionManager         = solutionManager;
            _projectTracker          = projectTracker;
            _fileSystemProvider      = fileSystemProvider;
            _solutionSettings        = solutionSettings;
            _projectDocumentListener = new TrackProjectDocumentEventListener(this);

            _solutionManager.SolutionOpened += OnSolutionOpened;
            _solutionManager.SolutionClosed += OnSolutionClosed;

            if (_solutionManager.IsSolutionOpen)
            {
                StartTracking();
            }
        }
        public VsSourceControlTracker(
            ISolutionManager solutionManager, 
            IFileSystemProvider fileSystemProvider,
            IVsTrackProjectDocuments2 projectTracker,
            ISettings solutionSettings)
        {
            if (projectTracker == null)
            {
                throw new ArgumentNullException("projectTracker");
            }

            _solutionManager = solutionManager;
            _projectTracker = projectTracker;
            _fileSystemProvider = fileSystemProvider;
            _solutionSettings = solutionSettings;
            _projectDocumentListener = new TrackProjectDocumentEventListener(this);

            _solutionManager.SolutionOpened += OnSolutionOpened;
            _solutionManager.SolutionClosed += OnSolutionClosed;

            if (_solutionManager.IsSolutionOpen)
            {
                StartTracking();
            }
        }
        public ProjectItemAddRemoveListener([Import(typeof (SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            ValidateArg.NotNull(serviceProvider, "serviceProvider");

            _projectDocTracker =
                serviceProvider.GetService(typeof (SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
        }
        public TestFileAddRemoveListener([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            ValidateArg.NotNull(serviceProvider, "serviceProvider");

            _projectDocTracker = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
            _documentTable = Package.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
        }
        protected ProjectDocumentsListener(System.IServiceProvider serviceProviderParameter) {
            Utilities.ArgumentNotNull("serviceProviderParameter", serviceProviderParameter);

            this.serviceProvider = serviceProviderParameter;
            this.projectDocTracker = this.serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;

            Utilities.CheckNotNull(this.projectDocTracker, "Could not get the IVsTrackProjectDocuments2 object from the services exposed by this project");
        }
示例#11
0
        public void Hook(bool enableSolution, bool enableProjects)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (enableSolution != _hookedSolution)
            {
                IVsSolution solution = GetService <IVsSolution>(typeof(SVsSolution));

                if (enableSolution && solution != null)
                {
                    Marshal.ThrowExceptionForHR(solution.AdviseSolutionEvents(this, out _documentCookie));
                    _hookedSolution = true;
                }
                else if (_hookedSolution)
                {
                    Marshal.ThrowExceptionForHR(solution.UnadviseSolutionEvents(_documentCookie));
                    _hookedSolution = false;
                }
            }

            if (enableProjects != _hookedProjects)
            {
                IVsTrackProjectDocuments2 tracker = GetService <IVsTrackProjectDocuments2>(typeof(SVsTrackProjectDocuments));

                if (enableProjects && tracker != null)
                {
                    Marshal.ThrowExceptionForHR(tracker.AdviseTrackProjectDocumentsEvents(this, out _projectCookie));

                    _hookedProjects = true;
                }
                else if (_hookedProjects)
                {
                    Marshal.ThrowExceptionForHR(tracker.UnadviseTrackProjectDocumentsEvents(_projectCookie));
                    _hookedProjects = false;
                }

                IAnkhConfigurationService cfg = GetService <IAnkhConfigurationService>();

                if (cfg != null && !cfg.Instance.DontHookSolutionExplorerRefresh)
                {
                    IAnkhGlobalCommandHook cmdHook = GetService <IAnkhGlobalCommandHook>();

                    if (cmdHook != null)
                    {
                        CommandID slnRefresh = new CommandID(VSConstants.VSStd2K, (int)VSConstants.VSStd2KCmdID.SLNREFRESH);
                        if (enableProjects)
                        {
                            cmdHook.HookCommand(slnRefresh, OnSolutionRefreshCommand);
                        }
                        else
                        {
                            cmdHook.UnhookCommand(slnRefresh, OnSolutionRefreshCommand);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Register TrackProjectDocuments2 events.
 /// </summary>
 public void RegisterTrackProjectDocumentsEvents2()
 {
     ProjectDocumentsTracker = Package.GetGlobalService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
     if (ProjectDocumentsTracker != null)
     {
         int hr = ProjectDocumentsTracker.AdviseTrackProjectDocumentsEvents(this, out PdwCookie);
         ErrorHandler.ThrowOnFailure(hr);
     }
 }
示例#13
0
        /// <include file='doc\FlavoredProject.uex' path='docs/doc[@for="FlavoredProject.OnAggregationComplete"]/*' />
        /// <devdoc>
        /// This is called when all object in aggregation have received InitializeForOuter calls.
        /// At this point the aggregation is complete and fully functional.
        /// </devdoc>
        protected virtual void OnAggregationComplete()
        {
            // This will subscribe to the IVsTrackProjectDocumentsEvents.
            // This is not required to flavor a project but makes it easier for derived class
            // to subscribe to these events.
            IVsTrackProjectDocuments2 trackDocuments = GetTrackProjectDocuments();

            ErrorHandler.ThrowOnFailure(trackDocuments.AdviseTrackProjectDocumentsEvents(this, out cookie));
        }
示例#14
0
        /// <devdoc>
        /// Used to subscribe/unsubscribe to those events
        /// </devdoc>
        private IVsTrackProjectDocuments2 GetTrackProjectDocuments()
        {
            IVsTrackProjectDocuments2 trackDocuments = ((System.IServiceProvider) this).GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;

            if (trackDocuments == null)
            {
                throw new ApplicationException(string.Format(Resources.Culture, Resources.Flavor_FailedToGetService, "SVsTrackProjectDocuments"));
            }
            return(trackDocuments);
        }
        /// <summary>
        /// Gets the IVsTrackProjectDocuments2 object by asking the service provider for it.
        /// </summary>
        /// <returns>the IVsTrackProjectDocuments2 object</returns>
        private IVsTrackProjectDocuments2 GetIVsTrackProjectDocuments2()
        {
            Debug.Assert(this.projectMgr != null && !this.projectMgr.IsClosed && this.projectMgr.Site != null);

            IVsTrackProjectDocuments2 documentTracker = this.projectMgr.Site.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;

            Utilities.CheckNotNull(documentTracker);

            return(documentTracker);
        }
示例#16
0
        /// <devdoc>
        /// Used to subscribe/unsubscribe to those events
        /// </devdoc>
        private IVsTrackProjectDocuments2 GetTrackProjectDocuments()
        {
            IVsTrackProjectDocuments2 trackDocuments = ((System.IServiceProvider) this).GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;

            Debug.Assert(trackDocuments != null, "Could not get the IVsTrackProjectDocuments2 object");
            if (trackDocuments == null)
            {
                throw new InvalidOperationException();
            }
            return(trackDocuments);
        }
示例#17
0
        public ProjectDocumentsListener(IServiceProvider serviceProvider)
        {
            ServiceProvider = serviceProvider;

            projectDocumentTracker2 = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
            Debug.Assert(projectDocumentTracker2 != null, "Could not get the IVsTrackProjectDocuments2 object from the services exposed by this project");
            if (projectDocumentTracker2 == null)
            {
                throw new InvalidOperationException();
            }
        }
示例#18
0
 int IVsHierarchy.Close()
 {
     if (cookie != 0)
     {
         // Unsubscribe to events
         IVsTrackProjectDocuments2 trackDocuments = GetTrackProjectDocuments();
         trackDocuments.UnadviseTrackProjectDocumentsEvents(cookie);
         cookie = 0;
     }
     this.Close();
     return(NativeMethods.S_OK);
 }
示例#19
0
        protected ProjectDocumentsListener(ServiceProvider serviceProvider)
        {
            this.serviceProvider   = serviceProvider;
            this.projectDocTracker = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;

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

            if (this.projectDocTracker == null)
            {
                throw new InvalidOperationException();
            }
        }
示例#20
0
 int IVsHierarchy.Close()
 {
     if (cookie != 0)
     {
         // Unsubscribe to events
         IVsTrackProjectDocuments2 trackDocuments = GetTrackProjectDocuments();
         Debug.Assert(ErrorHandler.Succeeded(trackDocuments.UnadviseTrackProjectDocumentsEvents(cookie)), "Failed to UnadviseTrackProjectDocumentsEvents");
         cookie = 0;
     }
     this.Close();
     return(NativeMethods.S_OK);
 }
        protected ProjectDocumentsListener(ServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.projectDocTracker = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;

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

            if (this.projectDocTracker == null)
            {
                throw new InvalidOperationException();
            }
        }
示例#22
0
 private void UnRegisterDocumentEvents()
 {
     if (VSConstants.VSCOOKIE_NIL != _tpdTrackProjectDocumentsCookie)
     {
         ThreadHelper.ThrowIfNotOnUIThread();
         IVsTrackProjectDocuments2 tpdService = (IVsTrackProjectDocuments2)_sccProvider.GetService(typeof(SVsTrackProjectDocuments));
         tpdService.UnadviseTrackProjectDocumentsEvents(_tpdTrackProjectDocumentsCookie);
         _tpdTrackProjectDocumentsCookie = VSConstants.VSCOOKIE_NIL;
     }
     _windowEvents.WindowActivated -= _windowEvents_WindowActivated;
     _solutionEvents.Opened        -= _solutionEvents_Opened;
 }
示例#23
0
		private IVsTrackProjectDocuments2 GetIVsTrackProjectDocuments2()
		{
			Debug.Assert(this.projectMgr != null && !this.projectMgr.IsClosed && this.projectMgr.Site != null);
			
			IVsTrackProjectDocuments2 documentTracker = this.projectMgr.Site.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
			if (documentTracker == null)
			{
				throw new InvalidOperationException();
			}
			
			return  documentTracker;
		}
        public ProjectLinkTracker(IVsTrackProjectDocuments2 documentTracker, IVsSolution solution, ILogger logger, Solution4 dteSolution = null)
        {
            logger?.Log(string.Format(CultureInfo.CurrentCulture, Resources.InitializingProjectTracker));

            _documentTracker = documentTracker;
            _solution        = solution;
            _logger          = logger;
            ErrorHandler.ThrowOnFailure(documentTracker.AdviseTrackProjectDocumentsEvents(this, out _trackProjectDocumentsCookie));
            ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(this, out _solutionCookie));

            RestoreLinks(dteSolution);
        }
        internal void AdviseEvents()
        {

            vsRDT = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable));
            // 1. subscribe to internal file events - events initiated from within VS
            ErrorHandler.ThrowOnFailure(vsRDT.AdviseRunningDocTableEvents(this, out rdtCookie));

            // 2. subscribe to external file events
            foreach (string fileName in codeFiles)
                    AddWatcher(fileName);
            vsTPD = (IVsTrackProjectDocuments2)Package.GetGlobalService(typeof(SVsTrackProjectDocuments));
            ErrorHandler.ThrowOnFailure(vsTPD.AdviseTrackProjectDocumentsEvents(this, out tpdCookie));

        }
        public void UseToolWindow()
        {
            // Create the package
            SccProvider package = new SccProvider();
            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Need to mock a service implementing IVsRegisterScciProvider, because the scc provider will register with it
            IVsRegisterScciProvider registerScciProvider = MockRegisterScciProvider.GetBaseRegisterScciProvider();

            serviceProvider.AddService(typeof(IVsRegisterScciProvider), registerScciProvider, true);

            // Add site support to create and enumerate tool windows
            BaseMock uiShell = MockUiShellProvider.GetWindowEnumerator0();

            serviceProvider.AddService(typeof(SVsUIShell), uiShell, false);

            // Register solution events because the provider will try to subscribe to them
            MockSolution solution = new MockSolution();

            serviceProvider.AddService(typeof(SVsSolution), solution as IVsSolution, true);

            // Register TPD service because the provider will try to subscribe to TPD
            IVsTrackProjectDocuments2 tpd = MockTrackProjectDocumentsProvider.GetTrackProjectDocuments() as IVsTrackProjectDocuments2;

            serviceProvider.AddService(typeof(SVsTrackProjectDocuments), tpd, true);

            // Site the package
            Assert.AreEqual(0, ((IVsPackage)package).SetSite(serviceProvider), "SetSite did not return S_OK");

            // Test that toolwindow can be created
            MethodInfo method = typeof(SccProvider).GetMethod("Exec_icmdViewToolWindow", BindingFlags.NonPublic | BindingFlags.Instance);
            object     result = method.Invoke(package, new object[] { null, null });

            // Test that toolwindow toolbar's command can be executed
            method = typeof(SccProvider).GetMethod("Exec_icmdToolWindowToolbarCommand", BindingFlags.NonPublic | BindingFlags.Instance);
            result = method.Invoke(package, new object[] { null, null });

            // Toggle the toolwindow color back
            method = typeof(SccProvider).GetMethod("Exec_icmdToolWindowToolbarCommand", BindingFlags.NonPublic | BindingFlags.Instance);
            result = method.Invoke(package, new object[] { null, null });

            // Get the window and test the dispose function
            SccProviderToolWindow window = (SccProviderToolWindow)package.FindToolWindow(typeof(SccProviderToolWindow), 0, true);

            method = typeof(SccProviderToolWindow).GetMethod("Dispose", BindingFlags.NonPublic | BindingFlags.Instance);
            result = method.Invoke(window, new object[] { true });
        }
示例#27
0
 private void UnadviseTrackProjectDocumentsEvents()
 {
     if (trackProjectDocuments != null)
     {
         ErrorHandler.ThrowOnFailure(trackProjectDocuments.UnadviseTrackProjectDocumentsEvents(trackProjectDocumentsCookie));
         trackProjectDocuments = null;
     }
 }
示例#28
0
 private void AdviseTrackProjectDocumentsEvents()
 {
     trackProjectDocuments = Package.GetGlobalService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
     if (trackProjectDocuments != null)
     {
         ErrorHandler.ThrowOnFailure(trackProjectDocuments.AdviseTrackProjectDocumentsEvents(this, out trackProjectDocumentsCookie));
     }
 }
示例#29
0
 public ProjectListener([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, ITestLogger logger)
 {
     ValidateArg.NotNull(serviceProvider, "serviceProvider");
     _projectDocTracker = serviceProvider.GetService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
     Logger = new TestLogger(logger, "ProjectListener");
 }
        public TestFileAddRemoveListener([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            ValidateArg.NotNull(serviceProvider, "serviceProvider");

            projectDocTracker = serviceProvider.GetService<IVsTrackProjectDocuments2>(typeof(SVsTrackProjectDocuments));
        }
 public TestableProjectLinkTracker(IVsTrackProjectDocuments2 documentTracker, IVsSolution solution)
     : base(documentTracker, solution, new MockLogger())
 {
 }
 public TestSccProvider(IVsTrackProjectDocuments2 trackDocs) {
     _provider = this;
     _trackDocs = trackDocs;
 }
示例#33
0
 /// <summary>
 /// Register TrackProjectDocuments2 events.
 /// </summary>
 public void RegisterTrackProjectDocumentsEvents2() {
     ProjectDocumentsTracker = Package.GetGlobalService(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2;
     if(ProjectDocumentsTracker != null) {
         int hr = ProjectDocumentsTracker.AdviseTrackProjectDocumentsEvents(this, out PdwCookie);
         ErrorHandler.ThrowOnFailure(hr);
     }
 }
 public DocumentEventHandler(IVsTrackProjectDocuments2 trackProjectDocuments2)
 {
     TrackProjectDocuments2 = trackProjectDocuments2;
 }