internal Result <ITextBuffer> GetTextBufferForDocCookie(uint cookie) { var info = _table.GetDocumentInfo(cookie); var obj = info.DocData; var vsTextLines = obj as IVsTextLines; var vsTextBufferProvider = obj as IVsTextBufferProvider; ITextBuffer textBuffer; if (vsTextLines != null) { textBuffer = _editorAdaptersFactoryService.GetDataBuffer(vsTextLines); } else if (vsTextBufferProvider != null && ErrorHandler.Succeeded(vsTextBufferProvider.GetTextBuffer(out vsTextLines)) && vsTextLines != null) { textBuffer = _editorAdaptersFactoryService.GetDataBuffer(vsTextLines); } else { textBuffer = null; } return(Result.CreateSuccessNonNull(textBuffer)); }
private Document FindDocument(uint docCookie) { var documentInfo = _runningDocumentTable.GetDocumentInfo(docCookie); var documentPath = documentInfo.Moniker; return(_dte.Documents.Cast <Document>().FirstOrDefault(doc => doc.FullName == documentPath)); }
private void GetDocumentInfo(uint cookie, ref IVsProject project, ref uint item, ref string path) { string pbstrMkDocument = ""; IVsProject pProject = null; uint pitemid = 0; ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); uint pgrfRDTFlags; uint pdwReadLocks; uint pdwEditLocks; IVsHierarchy ppHier; IntPtr ppunkDocData; ErrorHandler.ThrowOnFailure(RunningDocumentTable.GetDocumentInfo( cookie, out pgrfRDTFlags, out pdwReadLocks, out pdwEditLocks, out pbstrMkDocument, out ppHier, out pitemid, out ppunkDocData)); pProject = ppHier as IVsProject; }); project = pProject; path = pbstrMkDocument; item = pitemid; }
int IVsRunningDocTableEvents.OnAfterFirstDocumentLock(uint docCookie, uint dwRDTLockType, uint dwReadLocksRemaining, uint dwEditLocksRemaining) { // Please note that this event is called multiple times when a document // is opened for editing. // This code tries to only call the Open Event once // if (dwEditLocksRemaining == 1 && dwReadLocksRemaining == 0) { if (Opened != null) { string file = _rdt.GetDocumentInfo(docCookie).Moniker; Opened.Invoke(file); } } return(VSConstants.S_OK); }
/// <summary> /// Base class for all other RDT event wrappers. Each event wrapper /// stores event-specific information and formats it for display /// in the Properties window. /// </summary> /// <param name="rdt">Running Document Table instance</param> /// <param name="message">Message to be displayed in the grid</param> /// <param name="cookie">Cookie to unadvise RDT events</param> public GenericEvent(RunningDocumentTable rdt, string message, uint cookie) { this.message = message; if (rdt == null || cookie == 0) return; rdi = rdt.GetDocumentInfo(cookie); docNameShort = GetShortDocName(rdi.Moniker); }
public int OnAfterSave(uint docCookie) { var info = _runningDocumentTable.GetDocumentInfo(docCookie); var path = info.Moniker; DocumentSaved?.Invoke(this, path); return(VSConstants.S_OK); }
public int OnBeforeSave(uint docCookie) { ThreadHelper.ThrowIfNotOnUIThread(); var documentInfo = _runningDocumentTable.GetDocumentInfo(docCookie); var documentPath = documentInfo.Moniker; _commands.EditFile(documentPath); return(VSConstants.S_OK); }
private void RunningDocTableEventsOnDocumentOpened(object sender, VsDocumentEventArgs e) { var path = e.Path; var info = _runningDocumentTable.GetDocumentInfo(path.Value); // Call handlers var document = GetTextDocument(info); if (document != null) { document.FileActionOccurred += TextDocumentOnFileActionOccurred; // Add to table lock (_openDocumentsLock) { _openDocuments[path] = document; } // Call handlers OnTextDocumentOpened(new TextDocumentEventArgs(document)); } }
private bool TryGetDocumentInfo(uint cookie, out string name, out uint flags, out IVsHierarchy hier, out uint itemId, out object document) { ThreadHelper.ThrowIfNotOnUIThread(); if (!_documentInfo_init) { _documentInfo_init = true; DocumentInfoInit(); } if (GetDocumentMoniker_cb != null) { // Allow VS2013 to delayload windows try { name = GetDocumentMoniker_cb(cookie); flags = GetDocumentFlags_cb(cookie); hier = null; itemId = VSItemId.Nil; document = null; return(true); } catch { } } IntPtr ppunkDocData; uint locks; uint editLocks; if (VSErr.Succeeded(RunningDocumentTable.GetDocumentInfo(cookie, out flags, out locks, out editLocks, out name, out hier, out itemId, out ppunkDocData))) { if (ppunkDocData != IntPtr.Zero) { document = Marshal.GetUniqueObjectForIUnknown(ppunkDocData); Marshal.Release(ppunkDocData); } else { document = null; } return(true); } else { hier = null; itemId = VSItemId.Nil; document = null; return(false); } }
private Document FindDocumentByCookie(uint docCookie) { var documentInfo = _runningDocumentTable.GetDocumentInfo(docCookie); return(_environmentService.JoinableTaskFactory.Run(async() => { await _environmentService.JoinableTaskFactory.SwitchToMainThreadAsync(); #pragma warning disable VSTHRD010 return _environmentService.Dte.Documents.Cast <Document>().FirstOrDefault(doc => doc.FullName == documentInfo.Moniker); })); }
/// <summary> /// Base class for all other RDT event wrappers. Each event wrapper /// stores event-specific information and formats it for display /// in the Properties window. /// </summary> /// <param name="rdt">Running Document Table instance</param> /// <param name="message">Message to be displayed in the grid</param> /// <param name="cookie">Cookie to unadvise RDT events</param> public GenericEvent(RunningDocumentTable rdt, string message, uint cookie) { this.message = message; if (rdt == null || cookie == 0) { return; } rdi = rdt.GetDocumentInfo(cookie); docNameShort = GetShortDocName(rdi.Moniker); }
private string GetDocFullname(uint docCookie) { uint pgrfRDTFlags; uint pdwReadLocks; uint pdwEditLocks; string pbstrMkDocument; IVsHierarchy ppHier; uint pitemid; IntPtr ppunkDocData; RunningDocumentTable.GetDocumentInfo(docCookie, out pgrfRDTFlags, out pdwReadLocks, out pdwEditLocks, out pbstrMkDocument, out ppHier, out pitemid, out ppunkDocData); return(pbstrMkDocument); }
private void ReloadXmlDoCompletionData(uint docCookie) { var doc = _rdt.GetDocumentInfo(docCookie); // var docTextBufferAdapter = doc.DocData as IVsTextBuffer; var textLines = doc.DocData as IVsTextLines; IVsUserData userData = textLines as IVsUserData; if (userData != null) { Guid id = typeof(XmlKeyRefCompletionCommandHandler).GUID; userData.GetData(ref id, out var cmdHandler); (cmdHandler as XmlKeyRefCompletionCommandHandler)?.DocumentDataLoader.ScheduleReloading(XmlDocumentLoader.InitTimeout); } }
private Document FindDocumentByCookie(uint docCookie) { Document document = null; try { var documentInfo = mRunningDocumentTable.GetDocumentInfo(docCookie); document = mDte.Documents.Cast <Document>().FirstOrDefault(doc => doc.FullName == documentInfo.Moniker); } catch (Exception) { } return(document); }
protected override void OnBeforeHandleXmlModelTransactionCompleted(object sender, XmlTransactionEventArgs args) { base.OnBeforeHandleXmlModelTransactionCompleted(sender, args); #if DEBUG var rDT = new RunningDocumentTable(PackageManager.Package); uint cookie = 0; rDT.FindDocument(Uri.LocalPath, out cookie); var info = rDT.GetDocumentInfo(cookie); Debug.Print( string.Format( CultureInfo.CurrentCulture, "There are now {0} Edit Locks, and {1} Read Locks.", info.EditLocks, info.ReadLocks)); #endif }
public int OnAfterAttributeChangeEx( uint docCookie, uint grfAttribs, IVsHierarchy pHierOld, uint itemidOld, string pszMkDocumentOld, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew) { // We only need to worry about linked undo for artifacts that are not cached code gen models, since code gen artifacts don't exist // when the designer is open if (!IsCodeGenArtifact) { // First check to see if this is our document and it's being reloaded if (!_disabledBufferUndo && (grfAttribs & (uint)__VSRDTATTRIB.RDTA_DocDataReloaded) == (uint)__VSRDTATTRIB.RDTA_DocDataReloaded) { var rdt = new RunningDocumentTable(Services.ServiceProvider); var rdi = rdt.GetDocumentInfo(docCookie); if (rdi.Moniker.Equals(Uri.LocalPath, StringComparison.OrdinalIgnoreCase)) { // DocData is XmlModelDocData var textBufferProvider = rdi.DocData as IVsTextBufferProvider; Debug.Assert( textBufferProvider != null, "The XML Model DocData over the diagram file is not IVsTextBufferProvider. Linked undo may not work correctly"); if (textBufferProvider != null) { IVsTextLines textLines; var hr = textBufferProvider.GetTextBuffer(out textLines); Debug.Assert( textLines != null, "The IVsTextLines could not be found from the IVsTextBufferProvider. Linked undo may not work correctly"); if (NativeMethods.Succeeded(hr) && textLines != null) { IOleUndoManager bufferUndoMgr; hr = textLines.GetUndoManager(out bufferUndoMgr); Debug.Assert( bufferUndoMgr != null, "Couldn't find the buffer undo manager. Linked undo may not work correctly"); if (NativeMethods.Succeeded(hr) && bufferUndoMgr != null) { bufferUndoMgr.Enable(0); _disabledBufferUndo = true; } } } } } } return(VSConstants.S_OK); }
public int OnAfterAttributeChangeEx( uint docCookie, uint grfAttribs, IVsHierarchy pHierOld, uint itemidOld, string pszMkDocumentOld, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew) { // We only need to worry about linked undo for artifacts that are not cached code gen models, since code gen artifacts don't exist // when the designer is open if (!IsCodeGenArtifact) { // First check to see if this is our document and it's being reloaded if (!_disabledBufferUndo && (grfAttribs & (uint)__VSRDTATTRIB.RDTA_DocDataReloaded) == (uint)__VSRDTATTRIB.RDTA_DocDataReloaded) { var rdt = new RunningDocumentTable(Services.ServiceProvider); var rdi = rdt.GetDocumentInfo(docCookie); if (rdi.Moniker.Equals(Uri.LocalPath, StringComparison.OrdinalIgnoreCase)) { // DocData is XmlModelDocData var textBufferProvider = rdi.DocData as IVsTextBufferProvider; Debug.Assert( textBufferProvider != null, "The XML Model DocData over the diagram file is not IVsTextBufferProvider. Linked undo may not work correctly"); if (textBufferProvider != null) { IVsTextLines textLines; var hr = textBufferProvider.GetTextBuffer(out textLines); Debug.Assert( textLines != null, "The IVsTextLines could not be found from the IVsTextBufferProvider. Linked undo may not work correctly"); if (NativeMethods.Succeeded(hr) && textLines != null) { IOleUndoManager bufferUndoMgr; hr = textLines.GetUndoManager(out bufferUndoMgr); Debug.Assert( bufferUndoMgr != null, "Couldn't find the buffer undo manager. Linked undo may not work correctly"); if (NativeMethods.Succeeded(hr) && bufferUndoMgr != null) { bufferUndoMgr.Enable(0); _disabledBufferUndo = true; } } } } } } return VSConstants.S_OK; }
Document FindDocument(uint docCookie) { ThreadHelper.ThrowIfNotOnUIThread(); var documentInfo = _runningDocumentTable.GetDocumentInfo(docCookie); var documentPath = documentInfo.Moniker; foreach (Document doc in Dte.Documents) { if (doc.FullName == documentPath) { return(doc); } } return(null); }
private Document FindDocumentByCookie(uint docCookie) { Document document = null; try { var documentInfo = mRunningDocumentTable.GetDocumentInfo(docCookie); if (VsServiceProvider.TryGetService(typeof(DTE), out object dte)) { document = (dte as DTE).Documents.Cast <Document>().FirstOrDefault(doc => doc.FullName == documentInfo.Moniker); } } catch (Exception) { } return(document); }
public void OpenFile(string filePath, bool isReadOnly) { ThreadHelper.ThrowIfNotOnUIThread(); var rdt = new RunningDocumentTable(_serviceProvider); IVsWindowFrame?windowFrame = null; try { // Open the document. VsShellUtilities.OpenDocument( _serviceProvider, filePath, VSConstants.LOGVIEWID_Primary, out _, out _, out windowFrame); // Set it as read only if necessary. if (isReadOnly) { RunningDocumentInfo rdtInfo = rdt.GetDocumentInfo(filePath); // Set it as read only if necessary. if (rdtInfo.DocData is IVsTextBuffer textBuffer) { textBuffer.GetStateFlags(out uint flags); textBuffer.SetStateFlags(flags | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); } } // Show the document window if (windowFrame != null) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } } catch (Exception ex) when(!ex.IsCritical()) { windowFrame?.CloseFrame(0); } }
private Document FindDocumentByCookie(uint docCookie) { Document document = null; try { var documentInfo = mRunningDocumentTable.GetDocumentInfo(docCookie); if (VsServiceProvider.TryGetService(typeof(DTE), out object dte)) { document = (dte as DTE).Documents.Cast <Document>().FirstOrDefault(doc => doc.FullName == documentInfo.Moniker); } } catch (Exception) { //TODO find solution for DTE not intialized correctly sometimes // MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(document); }
private void GetDocumentInfo(uint cookie, ref IVsProject project, ref uint item, ref string path) { uint pgrfRDTFlags; uint pdwReadLocks; uint pdwEditLocks; string pbstrMkDocument; IVsHierarchy ppHier; uint pitemid; IntPtr ppunkDocData; ErrorHandler.ThrowOnFailure(RunningDocumentTable.GetDocumentInfo( cookie, out pgrfRDTFlags, out pdwReadLocks, out pdwEditLocks, out pbstrMkDocument, out ppHier, out pitemid, out ppunkDocData)); project = ppHier as IVsProject; path = pbstrMkDocument; item = pitemid; }
public bool TryGetTextBufferForDocCookie(uint cookie, out ITextBuffer buffer) { var info = _table.GetDocumentInfo(cookie); var obj = info.DocData; var vsTextLines = obj as IVsTextLines; var vsTextBufferProvider = obj as IVsTextBufferProvider; if (vsTextLines != null) { buffer = _editorAdaptersFactoryService.GetDataBuffer(vsTextLines); } else if (vsTextBufferProvider != null && ErrorHandler.Succeeded(vsTextBufferProvider.GetTextBuffer(out vsTextLines)) && vsTextLines != null) { buffer = _editorAdaptersFactoryService.GetDataBuffer(vsTextLines); } else { buffer = null; } return(buffer != null); }
public Task <bool> TryHandleCommandAsync(IImmutableSet <IProjectTree> items, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) { if (IsOpenCommand(commandId) && items.All(CanOpenFile)) { OpenItems(); return(TaskResult.True); } return(TaskResult.False); void OpenItems() { Assumes.NotNull(_configuredProject.UnconfiguredProject.Services.HostObject); var hierarchy = (IVsUIHierarchy)_configuredProject.UnconfiguredProject.Services.HostObject; var rdt = new RunningDocumentTable(_serviceProvider); // Open all items. RunAllAndAggregateExceptions(items, OpenItem); void OpenItem(IProjectTree item) { IVsWindowFrame?windowFrame = null; try { // Open the document. Guid logicalView = IsOpenWithCommand(commandId) ? LOGVIEWID_UserChooseView : LOGVIEWID.Primary_guid; IntPtr docData = IntPtr.Zero; ErrorHandler.ThrowOnFailure( _uiShellOpenDocument.Value.OpenStandardEditor( (uint)__VSOSEFLAGS.OSE_ChooseBestStdEditor, item.FilePath, ref logicalView, item.Caption, hierarchy, item.GetHierarchyId(), docData, _oleServiceProvider.Value, out windowFrame)); RunningDocumentInfo rdtInfo = rdt.GetDocumentInfo(item.FilePath); // Set it as read only if necessary. bool isReadOnly = item.Flags.Contains(ImportTreeProvider.ProjectImportImplicit); if (isReadOnly && rdtInfo.DocData is IVsTextBuffer textBuffer) { textBuffer.GetStateFlags(out uint flags); textBuffer.SetStateFlags(flags | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY); } // Detach the document from this project. // Ignore failure. It may be that we've already transferred the item to Miscellaneous Files. _externalFilesManager.Value.TransferDocument(item.FilePath, item.FilePath, windowFrame); // Show the document window if (windowFrame != null) { ErrorHandler.ThrowOnFailure(windowFrame.Show()); } } catch { windowFrame?.CloseFrame(0); throw; } } } }
public string GetDocumentName(uint docCookie) { return(_table.GetDocumentInfo(docCookie).Moniker); }
private Document FindDocumentByCookie(uint docCookie) { var documentInfo = mRunningDocumentTable.GetDocumentInfo(docCookie); return(mDte.Documents.Cast <Document>().FirstOrDefault(doc => doc.FullName == documentInfo.Moniker)); }
public IRunningDocumentInfo GetDocumentInfo(uint docCookie) => new RunningDocumentInfoWrapper( runningDocumentTable.GetDocumentInfo(docCookie));
protected override void OnBeforeHandleXmlModelTransactionCompleted(object sender, XmlTransactionEventArgs args) { base.OnBeforeHandleXmlModelTransactionCompleted(sender, args); #if DEBUG var rDT = new RunningDocumentTable(PackageManager.Package); uint cookie = 0; rDT.FindDocument(Uri.LocalPath, out cookie); var info = rDT.GetDocumentInfo(cookie); Debug.Print( string.Format( CultureInfo.CurrentCulture, "There are now {0} Edit Locks, and {1} Read Locks.", info.EditLocks, info.ReadLocks)); #endif }