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 DocumentWatcher(HandlerSet handlerSet, IServiceProvider serviceProvider)
        {
            hs = handlerSet;
            dt = (IVsRunningDocumentTable)serviceProvider.GetService(typeof(SVsRunningDocumentTable));

            dt.AdviseRunningDocTableEvents(this, out rdtCookie);
        }
        internal RunningDocumentTableEvents()
        {
            rdt = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable));

            uint cookie;
            rdt.AdviseRunningDocTableEvents(this, out cookie);
            sinkCookie = cookie;
        }
예제 #4
0
 private void AdviseRunningDocumentTableEvents()
 {
     runningDocumentTable = Package.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
     if (runningDocumentTable != null)
     {
         ErrorHandler.ThrowOnFailure(runningDocumentTable.AdviseRunningDocTableEvents(this, out runningDocumentTableCookie));
     }
 }
 public void Dispose()
 {
     if (rdt != null)
     {
         rdt.UnadviseRunningDocTableEvents(cookie);
         rdt = null;
         GC.SuppressFinalize(this);
     }
 }
 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);
 }
예제 #7
0
 public SaveEventsService(
     IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
     ICommandHandlerServiceFactory commandHandlerServiceFactory,
     SVsServiceProvider serviceProvider)
 {
     _editorAdaptersFactoryService = editorAdaptersFactoryService;
     _commandHandlerServiceFactory = commandHandlerServiceFactory;
     _runningDocumentTable = (IVsRunningDocumentTable)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
     _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));
 }
        public SaveListener(IVsRunningDocumentTable rdt)
        {
            if (rdt == null)
            {
                throw new ArgumentNullException("rdt");
            }

            _rdt = rdt;
            ErrorHandler.ThrowOnFailure(rdt.AdviseRunningDocTableEvents(this, out _pdwCookie));
        }
        private CommandGroupHandler(UnconfiguredProject project, IThreadHandling threadHandler, IProjectLockService lockService, 
            [ImportMany] IEnumerable<IDeployTargetUI> targetUIs, [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            this.threadHandler = threadHandler;
            threadHandler.VerifyOnUIThread();
            this.project = project;
            uiShell = (IVsUIShell)serviceProvider.GetService(typeof(IVsUIShell));
            docTable = (IVsRunningDocumentTable)serviceProvider.GetService(typeof(IVsRunningDocumentTable));

            ProjectHierarchies = new OrderPrecedenceImportCollection<IVsHierarchy>(projectCapabilityCheckProvider: project);
            this.lockService = lockService;
            this.targetUIs = targetUIs;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SolutionFilesChangeManager"/> class.
 /// </summary>
 /// <param name="serviceProvider">The service provider.</param>
 /// <param name="patterns">The patterns.</param>
 public SolutionFilesChangeManager(IServiceProvider serviceProvider, params string[] patterns)
 {
     Guard.ArgumentNotNull(serviceProvider, "serviceProvider");
     Guard.ArgumentNotNull(patterns, "patterns");
     Rules = new List<ObserveRule>();
     foreach (var pattern in patterns)
     {
         Rules.Add(new ObserveRule(pattern));
     }
     _serviceProvider = serviceProvider;
     _runningDocumentTableService = serviceProvider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
     _runningDocumentTableService.AdviseRunningDocTableEvents(this, out _rdtCookie);
 }
예제 #11
0
        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));

        }
예제 #12
0
파일: TextManager.cs 프로젝트: aesire/VsVim
 internal TextManager(
     IVsAdapter adapter,
     ITextDocumentFactoryService textDocumentFactoryService,
     ITextBufferFactoryService textBufferFactoryService,
     ISharedService sharedService,
     SVsServiceProvider serviceProvider)
 {
     _vsAdapter = adapter;
     _serviceProvider = serviceProvider;
     _textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
     _textDocumentFactoryService = textDocumentFactoryService;
     _textBufferFactoryService = textBufferFactoryService;
     _runningDocumentTable = _serviceProvider.GetService<SVsRunningDocumentTable, IVsRunningDocumentTable>();
     _sharedService = sharedService;
 }
예제 #13
0
        /// <summary>
        /// Appelée lors du déchargement de la stratégie
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        public override void OnUnloading(object sender, EventArgs eventArgs)
        {
            base.OnUnloading(sender, eventArgs);

            IVsRunningDocumentTable rdtEvents = GetService <IVsRunningDocumentTable>(typeof(SVsRunningDocumentTable));

            if (rdtEvents != null && _rdtEventsCookie != 0)
            {
                try
                {
                    rdtEvents.UnadviseRunningDocTableEvents(_rdtEventsCookie);
                }
                catch
                {
                }
                _configFolders.Clear();
            }
        }
예제 #14
0
        protected virtual void UnlockRDTEntry()
        {
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }
            // First we see if someone else has opened the requested view of the file.
            IVsRunningDocumentTable rdt = this.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (rdt != null && this.DocCookie != (int)ShellConstants.VSDOCCOOKIE_NIL)
            {
                _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_EditLock;

                ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)flags, (uint)this.DocCookie));
            }

            this.DocCookie = (int)ShellConstants.VSDOCCOOKIE_NIL;
        }
예제 #15
0
        void UnregisterRDTEvents()
        {
            if (0 == _runningDocTableCookie)
            {
                return;
            }

            IVsRunningDocumentTable rdt =
                _provider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (null != rdt)
            {
                // Do not throw in case of error.
                rdt.UnadviseRunningDocTableEvents(_runningDocTableCookie);
            }

            _runningDocTableCookie = 0;
        }
예제 #16
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            //string projectId = "cmp3060m-csw";
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await EnableDisableDataCollectorCommand.InitializeAsync(this);

            await RDTClass.InitializeAsync(this);

            IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)
                                          await GetServiceAsync(typeof(SVsRunningDocumentTable));

            Assumes.Present(rdt);
            rdt.AdviseRunningDocTableEvents(RDTClass.mRDTClass, out RDTClass.rdtCookie);
            //CloudAuth.AuthImplicit(projectId);
            ErrorHandler.Initialize(this);
            ErrorHandler.AddMessage("Data Collector Extension Running.");
        }
예제 #17
0
        private object FetchDocument()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if ((_flags & RDT_PendingInitialization) != 0)
            {
                return(null);
            }

            _fetchedRaw = true;

            // Normally when a document is open we get a handle via the opendocument tracker; but we might be to soon
            IVsRunningDocumentTable rd = GetService <IVsRunningDocumentTable>(typeof(SVsRunningDocumentTable));

            if (rd == null)
            {
                return(null);
            }

            uint         id;
            IVsHierarchy hier;
            IntPtr       data;
            uint         cookie; // We can't store the cookie, as that would mean it is in the lookup table

            if (VSErr.Succeeded(rd.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, Name, out hier, out id, out data, out cookie)))
            {
                if (hier != null)
                {
                    Hierarchy = hier;
                }
                if ((id != 0) && id != VSItemId.Nil)
                {
                    ItemId = id;
                }

                if (data != IntPtr.Zero)
                {
                    _rawDocument = Marshal.GetUniqueObjectForIUnknown(data);
                    Marshal.Release(data);
                }
            }

            return(_rawDocument);
        }
        /// <summary>
        /// Open a file in a document window with a std editor
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="frame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public int Open(bool newFile, bool openWith, Guid logicalView, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project");
            if (rdt == null)
            {
                return(VSConstants.E_FAIL);
            }

            // First we see if someone else has opened the requested view of the file.
            _VSRDTFLAGS  flags = _VSRDTFLAGS.RDT_NoLock;
            uint         itemid;
            IntPtr       docData = IntPtr.Zero;
            IVsHierarchy ivsHierarchy;
            uint         docCookie;
            string       path        = this.GetFullPathForDocument();
            int          returnValue = VSConstants.S_OK;

            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)flags, path, out ivsHierarchy, out itemid, out docData, out docCookie));
                ErrorHandler.ThrowOnFailure(this.Open(newFile, openWith, ref logicalView, docData, out frame, windowFrameAction));
            }
            catch (COMException e)
            {
                XSettings.LogException(e, "Open");
                returnValue = e.ErrorCode;
            }
            finally
            {
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }

            return(returnValue);
        }
예제 #19
0
파일: VsVimHost.cs 프로젝트: akamud/VsVim
        internal VsVimHost(
            IVsAdapter adapter,
            ITextBufferFactoryService textBufferFactoryService,
            ITextEditorFactoryService textEditorFactoryService,
            ITextDocumentFactoryService textDocumentFactoryService,
            ITextBufferUndoManagerProvider undoManagerProvider,
            IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
            IEditorOperationsFactoryService editorOperationsFactoryService,
            ISmartIndentationService smartIndentationService,
            ITextManager textManager,
            ISharedServiceFactory sharedServiceFactory,
            IVimApplicationSettings vimApplicationSettings,
            IExtensionAdapterBroker extensionAdapterBroker,
            IProtectedOperations protectedOperations,
            IMarkDisplayUtil markDisplayUtil,
            IControlCharUtil controlCharUtil,
            SVsServiceProvider serviceProvider,
            IClipboardDevice clipboardDevice)
            : base(textBufferFactoryService, textEditorFactoryService, textDocumentFactoryService, editorOperationsFactoryService)
        {
            _vsAdapter = adapter;
            _editorAdaptersFactoryService = editorAdaptersFactoryService;
            _dte                     = (_DTE)serviceProvider.GetService(typeof(_DTE));
            _vsExtensibility         = (IVsExtensibility)serviceProvider.GetService(typeof(IVsExtensibility));
            _textManager             = textManager;
            _sharedService           = sharedServiceFactory.Create();
            _vsMonitorSelection      = serviceProvider.GetService <SVsShellMonitorSelection, IVsMonitorSelection>();
            _vimApplicationSettings  = vimApplicationSettings;
            _smartIndentationService = smartIndentationService;
            _extensionAdapterBroker  = extensionAdapterBroker;
            _runningDocumentTable    = serviceProvider.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>();
            _vsShell                 = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            _protectedOperations     = protectedOperations;
            _clipboardDevice         = clipboardDevice;

            _vsMonitorSelection.AdviseSelectionEvents(this, out uint selectionCookie);
            _runningDocumentTable.AdviseRunningDocTableEvents(this, out uint runningDocumentTableCookie);

            InitOutputPane();

            _settingsSync = new SettingsSync(vimApplicationSettings, markDisplayUtil, controlCharUtil, _clipboardDevice);
            _settingsSync.SyncFromApplicationSettings();
        }
예제 #20
0
파일: Extensions.cs 프로젝트: vvmk/VsVim
        /// <summary>
        /// Get the document cookies for the documents in the running document table
        /// </summary>
        /// <remarks>
        /// This method simple asks for the cookies and hence won't force the document to be loaded
        /// if it is being loaded in a lazy fashion
        /// </remarks>
        public static List <uint> GetRunningDocumentCookies(this IVsRunningDocumentTable runningDocumentTable)
        {
            var list = new List <uint>();

            if (!ErrorHandler.Succeeded(runningDocumentTable.GetRunningDocumentsEnum(out IEnumRunningDocuments enumDocuments)))
            {
                return(list);
            }

            uint[] array        = new uint[1];
            uint   pceltFetched = 0;

            while (ErrorHandler.Succeeded(enumDocuments.Next(1, array, out pceltFetched)) && (pceltFetched == 1))
            {
                list.Add(array[0]);
            }

            return(list);
        }
예제 #21
0
        public IEditorInterfaces GetOrOpenDocument(string path)
        {
            OpenFileInEditor(path);
            IVsRunningDocumentTable runningDocumentTable = (IVsRunningDocumentTable)visualStudio.ServiceProvider.GetService(typeof(SVsRunningDocumentTable));

            IVsHierarchy hierarchy;
            uint         itemId;
            IntPtr       documentData = IntPtr.Zero;
            uint         cookie;

            try
            {
                int hr = runningDocumentTable.FindAndLockDocument(
                    (uint)_VSRDTFLAGS.RDT_NoLock,
                    path,
                    out hierarchy,
                    out itemId,
                    out documentData,
                    out cookie);

                if (hr == NativeMethods.S_OK && documentData != IntPtr.Zero)
                {
                    IVsTextBuffer vsTextBuffer = Marshal.GetObjectForIUnknown(documentData) as IVsTextBuffer;
                    if (vsTextBuffer != null)
                    {
                        IVsEditorAdaptersFactoryService editorAdaptersFactory = visualStudio.ComponentModel.GetService <IVsEditorAdaptersFactoryService>();
                        ITextBuffer   buffer   = editorAdaptersFactory.GetDocumentBuffer(vsTextBuffer);
                        ITextDocument document = buffer.Properties.GetProperty <ITextDocument>(typeof(ITextDocument));

                        return(new EditorInterfaces(buffer, document, vsTextBuffer));
                    }
                }

                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.FailedToOpenFile, path));
            }
            finally
            {
                if (documentData != IntPtr.Zero)
                {
                    Marshal.Release(documentData);
                }
            }
        }
        public string GetTextOfFileIfOpenInIde(string filePath)
        {
            IVsRunningDocumentTable rdt = _serviceProvider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            IVsHierarchy hierarchy  = null;
            uint         itemid     = 0;
            IntPtr       docDataUnk = IntPtr.Zero;
            uint         lockCookie = 0;

            int hr = rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, filePath, out hierarchy, out itemid, out docDataUnk, out lockCookie);

            try
            {
                if (hr == VSConstants.S_OK)
                {
                    IVsTextLines textLines = Marshal.GetUniqueObjectForIUnknown(docDataUnk) as IVsTextLines;

                    if (textLines != null)
                    {
                        string text     = null;
                        int    endLine  = 0;
                        int    endIndex = 0;

                        hr = textLines.GetLastLineIndex(out endLine, out endIndex);
                        Debug.Assert(hr == VSConstants.S_OK, "GetLastLineIndex did not return S_OK.");

                        hr = textLines.GetLineText(0, 0, endLine, endIndex, out text);
                        Debug.Assert(hr == VSConstants.S_OK, "GetLineText did not return S_OK.");

                        return(text);
                    }
                }

                return(null);
            }
            finally
            {
                if (lockCookie != 0)
                {
                    rdt.UnlockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, lockCookie);
                }
            }
        }
예제 #23
0
        public bool Register(EnvDTE.DTE dte, GanjiContext context)
        {
            table = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable));
            // Listen to show/hide events of docs to register activate/deactivate cursor listeners.
            table.AdviseRunningDocTableEvents(this, out m_rdtCookie);
            // In turn, cursor events will register a IVsTextViewEvents indexed by the IVsTextView.

            provider = new GitProviderLibGit2Sharp();
            provider.ContextRepository     = context.RepositoryPath;
            provider.SolutionBaseDirectory = context.SolutionPath;
            provider.Open(context.RepositoryPath);

            // Mixing in Find events with click events.
            m_dte                  = dte;
            m_findEvents           = dte.Events.FindEvents;
            m_findEvents.FindDone += new EnvDTE._dispFindEvents_FindDoneEventHandler(m_findEvents_FindDone);

            return(true);
        }
예제 #24
0
        /// <summary>
        /// Returns TRUE if open and dirty. Note that documents can be open without a
        /// window frame so be careful. Returns the DocData and doc cookie if requested
        /// </summary>
        /// <param name="document">document path</param>
        /// <param name="pHier">hierarchy</param>
        /// <param name="ppDocData">doc data associated with document</param>
        /// <param name="cookie">item cookie</param>
        /// <returns>True if FIle is dirty</returns>
        protected bool VerifyFileDirtyInRdt(string document, out IVsHierarchy pHier, out IVsPersistDocData ppDocData, out uint cookie)
        {
            int ret = 0;

            pHier     = null;
            ppDocData = null;
            cookie    = 0;
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsRunningDocumentTable rdt = this.projectMgr.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (rdt != null)
            {
                IntPtr       docData;
                uint         dwCookie = 0;
                IVsHierarchy srpHier;
                uint         itemid = VSConstants.VSITEMID_NIL;

                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, document, out srpHier, out itemid, out docData, out dwCookie));
                IVsPersistHierarchyItem srpIVsPersistHierarchyItem = srpHier as IVsPersistHierarchyItem;
                if (srpIVsPersistHierarchyItem != null)
                {
                    // Found in the RDT. See if it is dirty
                    try
                    {
                        ErrorHandler.ThrowOnFailure(srpIVsPersistHierarchyItem.IsItemDirty(itemid, docData, out ret));
                        cookie    = dwCookie;
                        ppDocData = Marshal.GetObjectForIUnknown(docData) as IVsPersistDocData;
                    }
                    finally
                    {
                        if (docData != IntPtr.Zero)
                        {
                            Marshal.Release(docData);
                        }

                        pHier = srpHier;
                    }
                }
            }
            return(ret == 1);
        }
예제 #25
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);
            }
        }
예제 #26
0
        public static void Create(System.IServiceProvider serviceProvider, Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleServiceProvider)
        {
            OLEServiceProvider = oleServiceProvider;
            ServiceProvider    = serviceProvider;

            InvisibleEditorManager = (IVsInvisibleEditorManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsInvisibleEditorManager));
            RunningDocumentTable   = (IVsRunningDocumentTable)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsRunningDocumentTable));
            var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));

            if (componentModel != null)
            {
                EditorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();
                TextEditorFactoryService     = componentModel.GetService <ITextEditorFactoryService>();
            }

            if (_Instance == null)
            {
                _Instance = new EditorService();
            }
        }
예제 #27
0
        /// <summary>
        /// gets the filename associated with document cookie
        /// </summary>
        public static string GetDocumentFileName(this IVsRunningDocumentTable RDT, uint docCookie)
        {
            if (RDT == null)
            {
                return(null);
            }

            uint   flags, readlocks, editlocks;
            string fileName; IVsHierarchy hier;
            uint   itemid; IntPtr docData;

            RDT.GetDocumentInfo(docCookie, out flags, out readlocks, out editlocks, out fileName, out hier, out itemid, out docData);

            if (string.IsNullOrWhiteSpace(fileName))
            {
                return(null);
            }

            return(fileName);
        }
            private bool TryNavigateToPosition()
            {
                IVsRunningDocumentTable docTable = (IVsRunningDocumentTable)_serviceProvider.GetService(typeof(SVsRunningDocumentTable));

                IntPtr       bufferPtr;
                IVsHierarchy hierarchy;
                uint         cookie;
                uint         itemid;

                if (docTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, _filePath, out hierarchy, out itemid, out bufferPtr, out cookie) != VSConstants.S_OK)
                {
                    return(false);
                }

                try
                {
                    var lines = Marshal.GetObjectForIUnknown(bufferPtr) as IVsTextLines;
                    if (lines == null)
                    {
                        return(false);
                    }

                    var textManager = (IVsTextManager)_serviceProvider.GetService(typeof(SVsTextManager));
                    if (textManager == null)
                    {
                        return(false);
                    }

                    return(textManager.NavigateToLineAndColumn(
                               lines, VSConstants.LOGVIEWID.TextView_guid,
                               _lineNumber, _charOffset,
                               _lineNumber, _charOffset) == VSConstants.S_OK);
                }
                finally
                {
                    if (bufferPtr != IntPtr.Zero)
                    {
                        Marshal.Release(bufferPtr);
                    }
                }
            }
예제 #29
0
        /// <summary>
        /// Open the file using the current document state scope
        /// </summary>
        private static IVsWindowFrame OpenDocumentInCurrentScope(IServiceProvider provider, string file)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsUIShellOpenDocument  openDoc         = SdkUIUtilities.GetService <SVsUIShellOpenDocument, IVsUIShellOpenDocument>(provider);
            IVsRunningDocumentTable runningDocTable = SdkUIUtilities.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>(provider);

            if (openDoc == null || runningDocTable == null)
            {
                throw Marshal.GetExceptionForHR(VSConstants.E_FAIL);
            }

            uint cookieDocLock = FindDocument(runningDocTable, file);

            IVsWindowFrame windowFrame;
            Guid           textViewGuid = VSConstants.LOGVIEWID_TextView;
            // Unused variables
            IVsUIHierarchy uiHierarchy;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider;
            uint itemId;
            int  hr = openDoc.OpenDocumentViaProject(file, ref textViewGuid, out serviceProvider, out uiHierarchy, out itemId, out windowFrame);

            if (ErrorHandler.Failed(hr))
            {
                throw Marshal.GetExceptionForHR(hr);
            }

            if (cookieDocLock == 0) // Document was not open earlier, and should be open now.
            {
                cookieDocLock = FindDocument(runningDocTable, file);
            }

            if (windowFrame != null)
            {
                // This will make the document visible to the user and switch focus to it. ShowNoActivate doesn't help because for tabbed documents they
                // are not brought to the front if they are already opened.
                windowFrame.Show();
            }
            return(windowFrame);
        }
예제 #30
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            dte = await GetServiceAsync(typeof(DTE)) as DTE;

            rdt = GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            rdt.AdviseRunningDocTableEvents(this, out cookie);

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

            //Assumes.Present(commandService);

            OleMenuCommand command = new OleMenuCommand(FormatDocumentCall, null, OnBeforeQueryStatus, new CommandID(new Guid("497A6C02-150A-4169-A09B-8592571306B9"), 0x0100));

            commandService.AddCommand(command);

            generalOptionsPage = GetDialogPage(typeof(GeneralOptionsPage)) as GeneralOptionsPage;
            csOptionsPage      = GetDialogPage(typeof(CSharpOptionsPage)) as AStyleOptionsPage;
            cppOptionsPage     = GetDialogPage(typeof(COptionsPage)) as AStyleOptionsPage;
        }
        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);
            }
        }
예제 #32
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation
        #region Package Members

        /// <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()
        {
            Logger.DeleteLogFile();
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            rdtObj = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable));
            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the tool window
                CommandID   toolwndCommandID = new CommandID(GuidList.guidSymbolBrowserCmdSet, (int)PkgCmdIDList.cmdidMyTool);
                MenuCommand menuToolWin      = new MenuCommand(ShowToolWindow, toolwndCommandID);
                mcs.AddCommand(menuToolWin);
            }

            // Obtain a reference to DTE2 type object.
            dteObj = GetService(typeof(DTE)) as DTE2;
        }
예제 #33
0
        /// <summary>
        /// Advises the file events.
        /// </summary>
        /// <param name="folderPath">The folder path.</param>
        private void AdviseFileEvents(string folderPath)
        {
            // Abonnement aux événements de modif
            if (_rdtEventsCookie == 0)
            {
                IVsRunningDocumentTable rdtEvents =
                    GetService <IVsRunningDocumentTable>(typeof(SVsRunningDocumentTable));
                if (rdtEvents != null)
                {
                    rdtEvents.AdviseRunningDocTableEvents(this, out _rdtEventsCookie);
                }
            }

            folderPath = folderPath.ToLower().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

            // Stockage des répertoires de config
            if (!_configFolders.Contains(folderPath))
            {
                _configFolders.Add(folderPath);
            }
        }
        internal static bool IsOurFile(string fileName)
        {
            var serviceProvider = XSharpEditorFactory.GetServiceProvider();

            if (serviceProvider == null)
            {
                return(false);
            }
            // Find the document in the Running Document Table and Get Its hierarchy object
            // so we can ask for a property that we can use to see if this is 'Ours'
            IVsRunningDocumentTable rdt = serviceProvider.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
            uint         itemID;
            IVsHierarchy hierarchy;
            IntPtr       unkDocData;
            uint         cookie;

            rdt.FindAndLockDocument((uint)(_VSRDTFLAGS.RDT_NoLock), fileName, out hierarchy, out itemID, out unkDocData, out cookie);
            if (unkDocData != IntPtr.Zero)
            {
                Marshal.Release(unkDocData);
            }
            object result;
            bool   ours = false;

            // Ask for the Language. X# returns the product name
            // the implementation for this property is inside XSharpFileNode.
            if (hierarchy != null)
            {
                hierarchy.GetProperty(itemID, (int)__VSHPROPID8.VSHPROPID_DiagHubLanguage, out result);
                ours = (result is string && (string)result == Constants.Product);
            }
            if (!ours)
            {
                // this could be a XAML generated source file that is not in the hierarchy
                // in that case it is part of the XSolution and we should be able to find its XAML parent
                var file = XSharpModel.XSolution.FindFullPath(fileName);
                ours = (file != null);
            }
            return(ours);
        }
예제 #35
0
        public void NotifyChanges()
        {
            if (_serviceProvider == null)
            {
                return;
            }

            // Get a reference to the Running Document Table
            IVsRunningDocumentTable runningDocTable = (IVsRunningDocumentTable)_serviceProvider.GetService(typeof(SVsRunningDocumentTable));

            // Lock the document
            uint         docCookie;
            IVsHierarchy hierarchy;
            uint         itemID;
            IntPtr       docData;
            int          hr = runningDocTable.FindAndLockDocument(
                (uint)_VSRDTFLAGS.RDT_ReadLock,
                base.Name,
                out hierarchy,
                out itemID,
                out docData,
                out docCookie
                );

            ErrorHandler.ThrowOnFailure(hr);

            IVsUIShell shell = _serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;

            if (shell != null)
            {
                shell.UpdateDocDataIsDirtyFeedback(docCookie, (_dirty == true) ? 1 : 0);
            }

            // Unlock the document.
            // Note that we have to unlock the document even if the previous call failed.
            runningDocTable.UnlockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, docCookie);

            // Check ff the call to NotifyDocChanged failed.
            //ErrorHandler.ThrowOnFailure(hr);
        }
예제 #36
0
        /// <summary>
        /// Saves the file for an open document.
        /// </summary>
        /// <param name="fileName"></param>
        public static void SaveDocument(IServiceProvider serviceProvider, string fileName)
        {
            // Get document cookie and hierarchy for the file
            IVsRunningDocumentTable runningDocumentTableService = (IVsRunningDocumentTable)serviceProvider.GetService(typeof(IVsRunningDocumentTable));
            uint         docCookie;
            IntPtr       docData;
            IVsHierarchy hierarchy;
            uint         itemId;

            runningDocumentTableService.FindAndLockDocument(
                (uint)Microsoft.VisualStudio.Shell.Interop._VSRDTFLAGS.RDT_NoLock,
                fileName,
                out hierarchy,
                out itemId,
                out docData,
                out docCookie);

            // Save the document
            IVsSolution solutionService = (IVsSolution)serviceProvider.GetService(typeof(IVsSolution));

            solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, hierarchy, docCookie);
        }
예제 #37
0
        private static void MarkDocumentAsTemporary(string moniker)
        {
            IVsRunningDocumentTable docTable = (IVsRunningDocumentTable)
                                               ServiceProvider.GlobalProvider.GetService(typeof(SVsRunningDocumentTable));

            uint lockType = (uint)_VSRDTFLAGS.RDT_DontAddToMRU
                            | (uint)_VSRDTFLAGS.RDT_NonCreatable
                            | (uint)_VSRDTFLAGS.RDT_VirtualDocument
                            | (uint)_VSRDTFLAGS.RDT_PlaceHolderDoc;

            int hr = docTable.FindAndLockDocument(
                dwRDTLockType: lockType,
                pszMkDocument: moniker,
                ppHier: out IVsHierarchy hierarchy,
                pitemid: out uint itemid,
                ppunkDocData: out IntPtr docData,
                pdwCookie: out uint documentCookie
                );

            CheckError(hr, "FindAndLockDocument");
            docTable.ModifyDocumentFlags(documentCookie, lockType, 1);
        }
예제 #38
0
        /// <summary>
        /// Save an open document.
        /// </summary>
        /// <param name="documentMoniker">
        /// for filebased documents this is the full path to the document
        /// </param>
        public static void SaveDocument(string documentMoniker)
        {
            // Get document cookie and hierarchy for the file
            IVsRunningDocumentTable runningDocumentTableService = (IVsRunningDocumentTable)VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsRunningDocumentTable));
            uint         docCookie;
            IntPtr       docData;
            IVsHierarchy hierarchy;
            uint         itemId;

            runningDocumentTableService.FindAndLockDocument(
                (uint)_VSRDTFLAGS.RDT_NoLock,
                documentMoniker,
                out hierarchy,
                out itemId,
                out docData,
                out docCookie);

            // Save the document
            IVsSolution solutionService = (IVsSolution)VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsSolution));

            solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, hierarchy, docCookie);
        }
예제 #39
0
        /// <summary>
        /// Gets an instance of the RunningDocumentTable (RDT) service which manages the set of currently open
        /// documents in the environment and then notifies the client that an open document has changed.
        /// </summary>
        private void NotifyDocChanged()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            // Make sure that we have a file name
            if (fileName.Length == 0)
            {
                return;
            }

            // Get a reference to the Running Document Table
            IVsRunningDocumentTable runningDocTable = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable));

            // Lock the document
            uint         docCookie;
            IVsHierarchy hierarchy;
            uint         itemID;
            IntPtr       docData;
            int          hr = runningDocTable.FindAndLockDocument(
                (uint)_VSRDTFLAGS.RDT_ReadLock,
                fileName,
                out hierarchy,
                out itemID,
                out docData,
                out docCookie
                );

            ErrorHandler.ThrowOnFailure(hr);

            // Send the notification
            hr = runningDocTable.NotifyDocumentChanged(docCookie, (uint)__VSRDTATTRIB.RDTA_DocDataReloaded);

            // Unlock the document.
            // Note that we have to unlock the document even if the previous call failed.
            runningDocTable.UnlockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, docCookie);

            // Check ff the call to NotifyDocChanged failed.
            ErrorHandler.ThrowOnFailure(hr);
        }
예제 #40
0
        private static IVsTextLines GetDocumentTextLines(uint docCookie)
        {
            // Get an instance of the running document table service (RDT).
            IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)VSPackage.Instance.GetService(typeof(SVsRunningDocumentTable));

            IntPtr unkDocData = IntPtr.Zero;

            try
            {
                // Get the information about document docCookie from the RDT.
                uint         flags;
                uint         readLocks;
                uint         editLocks;
                string       mkDocument;
                IVsHierarchy hierarchy;
                uint         itemId;
                ErrorHandler.ThrowOnFailure(rdt.GetDocumentInfo(docCookie,
                                                                out flags, out readLocks, out editLocks, out mkDocument,
                                                                out hierarchy, out itemId, out unkDocData));

                // unkDocData points to additional information about the document.
                // In the case of a text file this is an object that implements IVsTextLines.
                IVsTextLines lines = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;
                return(lines);
            }
            finally
            {
                // The GetDocumentInfo method often returns information in the
                // unkDocData parameter. Since the type is IntPtr the .NET runtime
                // only knows it's some kind of pointer. But we know that it is a
                // pointer to a COM IUnknown interface instance which has to be
                // freed separately by calling the Release method.
                if (unkDocData != IntPtr.Zero)
                {
                    Marshal.Release(unkDocData);
                }
            }
        }
예제 #41
0
        void LoadInitial()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsRunningDocumentTable rdt = RunningDocumentTable;

            if (rdt == null)
            {
                return;
            }

            IEnumRunningDocuments docEnum;

            if (!VSErr.Succeeded(rdt.GetRunningDocumentsEnum(out docEnum)))
            {
                return;
            }

            uint[] cookies = new uint[256];
            uint   nFetched;

            while (VSErr.Succeeded(docEnum.Next((uint)cookies.Length, cookies, out nFetched)))
            {
                if (nFetched == 0)
                {
                    break;
                }

                for (int i = 0; i < nFetched; i++)
                {
                    SccDocumentData data;
                    if (TryGetDocument(cookies[i], out data))
                    {
                        data.OnCookieLoad(_poller);
                    }
                }
            }
        }
예제 #42
0
        public int OnAfterSave(uint docCookie)
        {
            if (_runningDocumentsTable == null)
            {
                _runningDocumentsTable = _visualStudioServiceProvider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            }

            uint         rdtFlags;
            uint         readLocks;
            uint         editLocks;
            string       mkDocument;
            IVsHierarchy hierarchy;
            uint         itemId;
            IntPtr       ppunkDocData;

            if (_runningDocumentsTable.GetDocumentInfo(docCookie, out rdtFlags, out readLocks, out editLocks,
                                                       out mkDocument, out hierarchy, out itemId, out ppunkDocData) == VSConstants.S_OK)
            {
                _eventQueue.Enqueue(new FileChangedEvent(mkDocument));
            }

            return(VSConstants.S_OK);
        }
예제 #43
0
        protected override void Dispose(bool disposing)
        {
            // Remove solution event notifications.
            IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution));

            ErrorHandler.Ignore(solution.UnadviseSolutionEvents(_solutionEventCookie));

            // Remove text manager event notifications.
            if (_tmConnectionPoint != null)
            {
                _tmConnectionPoint.Unadvise(_tmConnectionCookie);
                _tmConnectionPoint = null;
            }

            // Remove running document table (RDT) event notifications.
            // Ignore any errors that might occur since we're shutting down.
            IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable));

            ErrorHandler.Ignore(rdt.UnadviseRunningDocTableEvents(_rdtEventCookie));

            // Forward call to the base class.
            base.Dispose(disposing);
        }
예제 #44
0
        public void Dispose()
        {
            if (!_disposed)
            {
                // shared cleanup logic
                if (_rdt != null)
                {
                    _rdt.UnadviseRunningDocTableEvents(_rdtEventsCookie);
                    _rdt = null;
                    _rdtEventsCookie = 0;
                }

                if (_sel != null)
                {
                    _sel.UnadviseSelectionEvents(_selEventsCookie);
                    _selEventsCookie = 0;
                    _sel = null;
                }

                _package.FileNameChanged -= OnAfterFileNameChanged;

                _disposed = true;
            }
        }
 public RunningDocTableEventsListener(IVsRunningDocumentTable rdt)
 {
     this.rdt = rdt;
     rdt.AdviseRunningDocTableEvents(this, out cookie);
 }
예제 #46
0
 public void Shutdown()
 {
     if (m_RDT != null)
     {
         m_RDT.UnadviseRunningDocTableEvents(m_rdtCookie);
         m_RDT = null;
     }
 }
예제 #47
0
 private void DisposeRunningDocTableEvents()
 {
     if (rdt != null && rdtEventsCookie != 0)
     {
         rdt.UnadviseRunningDocTableEvents(rdtEventsCookie);
         rdtEventsCookie = 0;
     }
     rdt = null;
 }
예제 #48
0
        private uint rdtEventsCookie; // = 0

        private void InitializeRunningDocTableEvents()
        {
            rdt = Common.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            if (rdt != null)
            {
                rdt.AdviseRunningDocTableEvents(this, out rdtEventsCookie);
            }
        }
 public RunningDocumentTableEventSink(IVsRunningDocumentTable runningDocumentTable, IMessageBus messageBus)
 {
     _runningDocumentTable = runningDocumentTable;
     _messageBus = messageBus;
     _runningDocumentTable.AdviseRunningDocTableEvents(this, out _cookie);
 }
 public RunningDocumentTableEventHandler(IVsRunningDocumentTable runningDocumentTable)
 {
     RunningDocumentTable = runningDocumentTable;
 }
예제 #51
0
 private void UnadviseRunningDocumentTableEvents()
 {
     if (runningDocumentTable != null)
     {
         ErrorHandler.ThrowOnFailure(runningDocumentTable.UnadviseRunningDocTableEvents(runningDocumentTableCookie));
         runningDocumentTable = null;
     }
 }
예제 #52
0
 internal SharedServiceVersionFactory(SVsServiceProvider vsServiceProvider)
 {
     _vsRunningDocumentTable = (IVsRunningDocumentTable)vsServiceProvider.GetService(typeof(SVsRunningDocumentTable));
 }
        public static IVsHierarchy GetHierarchyFromDocCookie(IVsRunningDocumentTable table, uint cookie)
        {
            uint pgrfRDTFlags;
            uint pdwReadLocks;
            uint pdwEditLocks;
            string pbstrMkDocument;
            IVsHierarchy hierarchy;
            uint pitemid;
            IntPtr ppunkDocData;

            table.GetDocumentInfo(
                cookie,
                out pgrfRDTFlags,
                out pdwReadLocks,
                out pdwEditLocks,
                out pbstrMkDocument,
                out hierarchy,
                out pitemid,
                out ppunkDocData
                );

            return hierarchy;
        }
예제 #54
0
 /// <include file='doc\Utilities.uex' path='docs/doc[@for="RunningDocumentTable.RunningDocumentTable"]/*' />
 public RunningDocumentTable(IServiceProvider site) {
     this.site = site;
     this.rdt = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
     if (this.rdt == null){
         throw new System.NotSupportedException(typeof(SVsRunningDocumentTable).FullName);
     }
 }
예제 #55
0
 internal SharedService(IVsRunningDocumentTable vsRunningDocumentTable)
 {
     _vsRunningDocumentTable = vsRunningDocumentTable;
 }
예제 #56
0
        public bool Register(EnvDTE.DTE dte, GanjiContext context)
        {
            // Register events for running document table.
            m_RDT = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable));
            m_RDT.AdviseRunningDocTableEvents(this, out m_rdtCookie);

            provider = new GitProviderLibGit2Sharp();
            provider.ContextRepository = context.RepositoryPath;
            provider.SolutionBaseDirectory = context.SolutionPath;
            provider.Open(context.RepositoryPath);

            // I: test if this table is from multiple instances routed here...
            return true;
        }
예제 #57
0
        private static void ReloadDocument(IVsRunningDocumentTable runningDocumentTable, string outputFilePath)
        {
            if (runningDocumentTable == null)
            {
                // SVsRunningDocumentTable service is not available (as in a unit test).
                return;
            }

            IVsHierarchy hierarchy;
            uint itemId;
            IntPtr persistDocDataPointer;
            uint cookie;
            ErrorHandler.ThrowOnFailure(runningDocumentTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, outputFilePath, out hierarchy, out itemId, out persistDocDataPointer, out cookie));
            if (persistDocDataPointer == IntPtr.Zero)
            {
                // Document is not currently opened in Visual Studio editor. 
                return;
            }

            var persistDocData = (IVsPersistDocData)Marshal.GetObjectForIUnknown(persistDocDataPointer);
            ErrorHandler.ThrowOnFailure(persistDocData.ReloadDocData((uint)(_VSRELOADDOCDATA.RDD_IgnoreNextFileChange | _VSRELOADDOCDATA.RDD_RemoveUndoStack)));
        }
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation
        /// <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()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
            base.Initialize();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof (IMenuCommandService)) as OleMenuCommandService;
            if (null != mcs)
            {
                // Create the command for the menu item.
                var menuCommandID = new CommandID(GuidList.guidVSPackageCmdSet,
                                                  (int) PkgCmdIDList.EPiServerLanguageExtensionOptions);
                var menuItem = new MenuCommand(MenuItemCallback, menuCommandID);
                mcs.AddCommand(menuItem);
            }

            _docTable = (IVsRunningDocumentTable) GetService(typeof (SVsRunningDocumentTable));
            _docTable.AdviseRunningDocTableEvents(this, out _docTableCookie);

            // Your package is also a service container
            // The DTE object contains most of the goodies you'll want to play with
            _dte = ((IServiceContainer) this).GetService(typeof (SDTE)) as DTE;

            _solutionEvents = _dte.Events.SolutionEvents;
            _solutionEvents.Opened += SolutionOpened;

            SolutionOpened(); // we have to trigger this manually since in VS2012 Opened event is not triggered when the solution is opened at the same time as Visual Studio is launched (for example by double clicking the solution file in explorer)
        }
예제 #59
0
 public RdtManager(IServiceProvider provider)
 {
     rdt = provider.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
     rdt.AdviseRunningDocTableEvents(this, out cookie);
     var dte = provider.GetService(typeof(DTE)) as DTE;
 }
예제 #60
0
 /// <summary>
 /// Register RunningDocumentTable events.
 /// </summary>
 public void RegisterRunningDocumentTableEvents() {
     DocumentTable = (IVsRunningDocumentTable) Package.GetGlobalService(typeof(SVsRunningDocumentTable));
     if(DocumentTable != null) {
         int hr = DocumentTable.AdviseRunningDocTableEvents(this, out DocumentTableItemId);
         ErrorHandler.ThrowOnFailure(hr);
     }
 }