protected virtual void LockRDTEntry() { // Define flags for the nested project document _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_ProjSlnDocument;; // Request the RDT service IVsRunningDocumentTable rdt = this.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) { throw new InvalidOperationException(); } // First we see if someone else has opened the requested view of the file. uint itemid; IntPtr docData = IntPtr.Zero; IVsHierarchy ivsHierarchy; uint docCookie; IntPtr projectPtr = IntPtr.Zero; try { ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)flags, this.projectPath, out ivsHierarchy, out itemid, out docData, out docCookie)); flags |= _VSRDTFLAGS.RDT_EditLock; if (ivsHierarchy != null && docCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL) { if (docCookie != this.DocCookie) { this.DocCookie = docCookie; } } else { // get inptr for hierarchy projectPtr = Marshal.GetIUnknownForObject(this.nestedHierarchy); Debug.Assert(projectPtr != IntPtr.Zero, " Project pointer for the nested hierarchy has not been initialized"); ErrorHandler.ThrowOnFailure(rdt.RegisterAndLockDocument((uint)flags, this.projectPath, this.ProjectMgr, this.ID, projectPtr, out docCookie)); this.DocCookie = docCookie; Debug.Assert(this.DocCookie != (uint)ShellConstants.VSDOCCOOKIE_NIL, "Invalid cookie when registering document in the running document table."); //we must also set the doc cookie on the nested hier this.SetDocCookieOnNestedHier(this.DocCookie); } } finally { // Release all Inptr's that that were given as out pointers if (docData != IntPtr.Zero) { Marshal.Release(docData); } if (projectPtr != IntPtr.Zero) { Marshal.Release(projectPtr); } } }
public uint RegisterAndLockDocument(_VSRDTFLAGS lockType, string mkDocument, IVsHierarchy hierarchy, uint itemid, IntPtr docData) { uint cookie; NativeMethods.ThrowOnFailure(rdt.RegisterAndLockDocument((uint)lockType, mkDocument, hierarchy, itemid, docData, out cookie)); return(cookie); }
/// <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; 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 { 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) { Trace.WriteLine("Exception :" + e.Message); returnValue = e.ErrorCode; } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } return(returnValue); }
///------------------------------------------------------------------------------------------------------------- /// <summary> /// If the document is open, it returns the IntPtr to the doc data. /// (This is ref-counted and must be released with Marshal.Release()) /// </summary> ///------------------------------------------------------------------------------------------------------------- public IntPtr GetRunningDocData() { IntPtr docData = IntPtr.Zero; if (IsFile()) { string fullPath = FullPath(); if (!string.IsNullOrEmpty(fullPath)) { IVsRunningDocumentTable rdt = GetService <IVsRunningDocumentTable>(); if (rdt != null) { _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_NoLock; uint itemid; IVsHierarchy hierarchy; uint docCookie; rdt.FindAndLockDocument ( (uint)flags, fullPath, out hierarchy, out itemid, out docData, out docCookie ); } } } return(docData); }
public DocInfo(_VSRDTFLAGS _VSRDTFLAGS, string pszMkDocument, IVsHierarchy pHier, uint itemid, IntPtr punkDocData, uint p) { Flags = _VSRDTFLAGS; Document = pszMkDocument; Hierarchy = pHier; ItemId = itemid; DocData = punkDocData; Cookie = p; }
public DocInfo(_VSRDTFLAGS _VSRDTFLAGS, string pszMkDocument, IVsHierarchy pHier, uint itemid, IntPtr punkDocData, uint p) { Flags = _VSRDTFLAGS; Document = pszMkDocument; Hierarchy = pHier; ItemId = itemid; DocData = punkDocData; Cookie = p; }
public void SetFlags(_VSRDTFLAGS flags) { _flags = flags; bool isVirtual = ((flags & (_VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_ProjSlnDocument)) == _VSRDTFLAGS.RDT_VirtualDocument); if (_isFileDocument && isVirtual) { HookFileChanges(false); _isFileDocument = false; _fullPath = null; } }
public void OnAttributeChange(__VSRDTATTRIB attributes, TryDocumentDirtyPoller poller) { if (0 != (attributes & RDTA_DocumentInitialized)) { _flags = (_VSRDTFLAGS)((int)_flags & ~(int)RDT_PendingInitialization); } if (0 != (attributes & RDTA_HierarchyInitialized)) { _flags = (_VSRDTFLAGS)((int)_flags & ~(int)RDT_PendingHierarchyInitialization); } if (0 != (attributes & __VSRDTATTRIB.RDTA_DocDataReloaded)) { _reloadTick++; _saving = null; if (_initialUpdateCompleted && _isFileDocument) { IFileStatusMonitor monitor = GetService <IFileStatusMonitor>(); if (monitor != null) { bool wasDirty = _isDirty; _isDirty = false; bool dirty = PollDirty(poller); if (wasDirty != IsDirty) { _isDirty = wasDirty; SetDirty(IsDirty); } monitor.ScheduleGlyphUpdate(FullPath); } } else { _initialUpdateCompleted = true; } } if (0 != (attributes & __VSRDTATTRIB.RDTA_DocDataIsDirty)) { _initialUpdateCompleted = true; SetDirty(true); } else if (0 != (attributes & __VSRDTATTRIB.RDTA_DocDataIsNotDirty)) { _initialUpdateCompleted = true; SetDirty(false); } }
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; }
public static object GetDocData(IServiceProvider site, string documentPath, _VSRDTFLAGS lockFlags, out uint docCookie) { if (site == null) { VSErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED); } var rdtService = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; IVsHierarchy hierarchy; uint itemId; var docDataPtr = IntPtr.Zero; docCookie = VSConstants.VSCOOKIE_NIL; object ret = null; try { if ( ErrorHandler.Succeeded( rdtService.FindAndLockDocument( (uint)lockFlags, documentPath, out hierarchy, out itemId, out docDataPtr, out docCookie)) && docDataPtr != IntPtr.Zero) { ret = Marshal.GetObjectForIUnknown(docDataPtr); } } finally { if (docDataPtr != IntPtr.Zero) { Marshal.Release(docDataPtr); } } return(ret); }
public void UnlockDocument(_VSRDTFLAGS lockType) { NativeMethods.ThrowOnFailure(RunningDocumentTable.RdtInstance. UnlockDocument((uint)lockType, DocumentCookie)); }
public void UnlockDocument(_VSRDTFLAGS lockType) { NativeMethods.ThrowOnFailure(RunningDocumentTable.RdtInstance. UnlockDocument((uint)lockType, DocumentCookie)); }
public void UnlockDocument(_VSRDTFLAGS lockType, uint cookie) { NativeMethods.ThrowOnFailure(rdt.UnlockDocument((uint)lockType, cookie)); }
/// <summary> /// Formats lock type for display. Parses bits and identifies them. /// </summary> /// <returns>Returns the formatted lock type.</returns> public string GetLockType() { string s = ""; _VSRDTFLAGS mask = (_VSRDTFLAGS)dwRDTLockType; if ((mask & _VSRDTFLAGS.RDT_DontSave) != 0 && (mask & _VSRDTFLAGS.RDT_DontSaveAs) != 0) { s += "CantSave "; } else { if ((mask & _VSRDTFLAGS.RDT_DontSave) != 0) { s += "DontSave "; } if ((mask & _VSRDTFLAGS.RDT_DontSaveAs) != 0) { s += "DontSaveAs "; } } if ((mask & _VSRDTFLAGS.RDT_ReadLock) != 0) { s += "ReadLock "; } if ((mask & _VSRDTFLAGS.RDT_EditLock) != 0) { s += "EditLock "; } if ((mask & _VSRDTFLAGS.RDT_RequestUnlock) != 0) { s += "RequestUnlock "; } if ((mask & _VSRDTFLAGS.RDT_NonCreatable) != 0) { s += "NonCreatable "; } if ((mask & _VSRDTFLAGS.RDT_DontAutoOpen) != 0) { s += "DontAutoOpen "; } if ((mask & _VSRDTFLAGS.RDT_CaseSensitive) != 0) { s += "CaseSensitive "; } if ((mask & _VSRDTFLAGS.RDT_Unlock_NoSave) != 0) { s += "Unlock_NoSave "; } if ((mask & _VSRDTFLAGS.RDT_Unlock_SaveIfDirty) != 0) { s += "Unlock_SaveIfDirty "; } if ((mask & _VSRDTFLAGS.RDT_Unlock_PromptSave) != 0) { s += "Unlock_PromptSave "; } if ((mask & _VSRDTFLAGS.RDT_VirtualDocument) != 0) { s += "VirtualDocument "; } if ((mask & _VSRDTFLAGS.RDT_ProjSlnDocument) != 0) { s += "ProjSlnDocument "; } if ((mask & _VSRDTFLAGS.RDT_PlaceHolderDoc) != 0) { s += "PlaceHolderDoc "; } if ((mask & _VSRDTFLAGS.RDT_CanBuildFromMemory) != 0) { s += "CanBuildFromMemory "; } if ((mask & _VSRDTFLAGS.RDT_DontAddToMRU) != 0) { s += "DontAddToMRU "; } return(string.Format(CultureInfo.CurrentCulture, "0x{0:X} ", dwRDTLockType) + s); }
public static object GetDocData(IServiceProvider site, string documentPath, _VSRDTFLAGS lockFlags, out uint docCookie) { if (site == null) { VSErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED); } var rdtService = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; IVsHierarchy hierarchy; uint itemId; var docDataPtr = IntPtr.Zero; docCookie = VSConstants.VSCOOKIE_NIL; object ret = null; try { if ( ErrorHandler.Succeeded( rdtService.FindAndLockDocument( (uint)lockFlags, documentPath, out hierarchy, out itemId, out docDataPtr, out docCookie)) && docDataPtr != IntPtr.Zero) { ret = Marshal.GetObjectForIUnknown(docDataPtr); } } finally { if (docDataPtr != IntPtr.Zero) { Marshal.Release(docDataPtr); } } return ret; }