private string GetDocumentName(uint docCookie, IVsWindowFrame pFrame)
        {
            string documentName = null;
            IVsRunningDocumentTable runningDocTable = SdkUIUtilities.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>(ServiceProvider);

            if (runningDocTable != null)
            {
                uint         grfRDTFlags;
                uint         dwReadLocks;
                uint         dwEditLocks;
                IVsHierarchy pHier;
                uint         itemId;
                IntPtr       docData = IntPtr.Zero;
                try
                {
                    int hr = runningDocTable.GetDocumentInfo(docCookie,
                                                             out grfRDTFlags,
                                                             out dwReadLocks,
                                                             out dwEditLocks,
                                                             out documentName,
                                                             out pHier,
                                                             out itemId,
                                                             out docData);
                }
                finally
                {
                    if (docData != IntPtr.Zero)
                    {
                        Marshal.Release(docData);
                    }
                }
            }
            return(documentName);
        }
Пример #2
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);
        }