示例#1
0
        /// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.OpenDocumentWithSpecificEditor1"]/*' />
        public static void OpenDocumentWithSpecificEditor(IServiceProvider provider, string fullPath, Guid editorType, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame) {
            windowFrame = null;
            itemID = NativeMethods.VSITEMID_NIL;
            hierarchy = null;
            //open document
            IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            RunningDocumentTable pRDT = new RunningDocumentTable(provider);
            string physicalView = null;
            if (shellOpenDoc != null) {
                NativeMethods.ThrowOnFailure(shellOpenDoc.MapLogicalView(ref editorType, ref logicalView, out physicalView));
                // See if the requested editor is already open with the requested view.
                uint docCookie;
                IVsHierarchy ppIVsHierarchy;
                object docData = pRDT.FindDocument(fullPath, out ppIVsHierarchy, out itemID, out docCookie);
                if (docData != null) {
                    int pfOpen;
                    uint flags = (uint)__VSIDOFLAGS.IDO_ActivateIfOpen;
                    int hr = shellOpenDoc.IsSpecificDocumentViewOpen((IVsUIHierarchy)ppIVsHierarchy, itemID, fullPath, ref editorType, physicalView, flags, out hierarchy, out itemID, out windowFrame, out pfOpen);
                    if (NativeMethods.Succeeded(hr) && pfOpen == 1) {
                        return;
                    }
                }

                IOleServiceProvider psp;
                uint editorFlags = (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_UseEditor | (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen;
                NativeMethods.ThrowOnFailure(shellOpenDoc.OpenDocumentViaProjectWithSpecific(fullPath, editorFlags, ref editorType, physicalView, ref logicalView, out psp, out hierarchy, out itemID, out windowFrame));
                if (windowFrame != null)
                    NativeMethods.ThrowOnFailure(windowFrame.Show());
                psp = null;
            }
        }
示例#2
0
        /// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.RenameDocument"]/*' />
        public static void RenameDocument(IServiceProvider site, string oldName, string newName) {
            RunningDocumentTable pRDT = new RunningDocumentTable(site);

            IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IVsUIShell uiShell = site.GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (doc == null || uiShell == null) return;

            IVsHierarchy pIVsHierarchy;
            uint itemId;
            uint uiVsDocCookie;
            object docData = pRDT.FindDocument(oldName, out pIVsHierarchy, out itemId, out uiVsDocCookie);

            if (docData != null) {
                pRDT.RenameDocument(oldName, newName, pIVsHierarchy, itemId);
                
                string newCaption = Path.GetFileName(newName);
                // now we need to tell the windows to update their captions.
                IEnumWindowFrames ppenum;
                NativeMethods.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out ppenum));
                IVsWindowFrame[] rgelt = new IVsWindowFrame[1];
                uint fetched;
                while (ppenum.Next(1, rgelt, out fetched) == NativeMethods.S_OK && fetched == 1) {
                    IVsWindowFrame windowFrame = rgelt[0];
                    object data;
                    NativeMethods.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out data));
                    if (IsSameCOMObject(data, docData)) {
                        NativeMethods.ThrowOnFailure(windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, newCaption));
                    }
                }
            }
        }
示例#3
0
 /// <include file='doc\Utilities.uex' path='docs/doc[@for="VsShell.IsDocumentOpen"]/*' />
 /// Returns true and item hierarchy and window frame if the document is open with the given
 /// logical view.  If logicalView is Guid.Empty, then it returns true if any view is open.
 public static bool IsDocumentOpen(IServiceProvider provider, string fullPath, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame) {
     windowFrame = null;
     itemID = NativeMethods.VSITEMID_NIL;
     hierarchy = null;
     //open document
     IVsUIShellOpenDocument shellOpenDoc = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
     RunningDocumentTable pRDT = new RunningDocumentTable(provider);
     if (shellOpenDoc != null) {
         uint docCookie;
         uint[] pitemid = new uint[1];
         IVsHierarchy ppIVsHierarchy;
         object docData = pRDT.FindDocument(fullPath, out ppIVsHierarchy, out pitemid[0], out docCookie);
         if (docData == null) {
             return false;
         } else {
             int pfOpen;
             uint flags = (logicalView == Guid.Empty) ? (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView : 0;
             NativeMethods.ThrowOnFailure(shellOpenDoc.IsDocumentOpen((IVsUIHierarchy)ppIVsHierarchy, pitemid[0], fullPath, ref logicalView, flags, out hierarchy, pitemid, out windowFrame, out pfOpen));
             if (windowFrame != null) {
                 itemID = pitemid[0];
                 return (pfOpen == 1);
             }
         }
     }
     return false;
 }
示例#4
0
        public void Suspend() {
            if (this.fSuspending)
                return;

            try {
                RunningDocumentTable pRDT = new RunningDocumentTable(this.site);
                IVsFileChangeEx vsFileChange;
                uint uiVsDocCookie;

                object docData = pRDT.FindDocument(this.strDocumentFileName, out uiVsDocCookie);
           
                if ((uiVsDocCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || docData == null)
                    return;

                vsFileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;

                if (vsFileChange != null) {
                    this.fSuspending = true;
                    NativeMethods.ThrowOnFailure(vsFileChange.IgnoreFile(0, this.strDocumentFileName, (int)1));
                    if (docData is IVsDocDataFileChangeControl) {
                        // if interface is not supported, return null
                        IVsPersistDocData ppIVsPersistDocData = (IVsPersistDocData)docData;
                        if (ppIVsPersistDocData is IVsDocDataFileChangeControl){
                            this.fileChangeControl = (IVsDocDataFileChangeControl)ppIVsPersistDocData;
                            if (this.fileChangeControl != null) {
                                NativeMethods.ThrowOnFailure(this.fileChangeControl.IgnoreFileChanges(1));
                            }
                        }
                    }
                }                
            } catch {
            }
            return;
        }