public void VsTextViewCreated(IVsTextView vsTextView) { if (vsTextView == null) { throw new ArgumentNullException(nameof(vsTextView)); } if (ErrorHandler.Failed(vsTextView.GetBuffer(out var textLines))) { return; } IVsUserData userData = textLines as IVsUserData; if (userData == null) { return; } Guid monikerGuid = typeof(IVsUserData).GUID; if (ErrorHandler.Failed(userData.GetData(ref monikerGuid, out var monikerObj))) { return; } string filePath = monikerObj as string; _rdt.Value.FindDocument(filePath, out var hierarchy, out var itemId, out var docCookie); AbstractProject project = GetXamlProject(hierarchy); if (project == null) { project = new XamlProject( _vsWorkspace.GetProjectTrackerAndInitializeIfNecessary(_serviceProvider), hierarchy, _serviceProvider, _vsWorkspace); } IVisualStudioHostDocument vsDocument = project.GetCurrentDocumentFromPath(filePath); if (vsDocument == null) { if (!TryCreateXamlDocument(project, filePath, out vsDocument)) { return; } project.AddDocument(vsDocument, isCurrentContext: true, hookupHandlers: true); } AttachRunningDocTableEvents(); var wpfTextView = _editorAdaptersFactory.GetWpfTextView(vsTextView); var target = new XamlOleCommandTarget(wpfTextView, CommandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider); target.AttachToVsTextView(); }
private void CancelPendingDocumentInitializationTask(IVisualStudioHostDocument document) { lock (_gate) { CancelPendingDocumentInitializationTask_NoLock(document); } }
private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument) { vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile( project, ImmutableArray <string> .Empty, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType)); return(vsDocument != null); }
private void NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(IVisualStudioHostDocument document, CancellationToken cancellationToken) { AssertIsForeground(); cancellationToken.ThrowIfCancellationRequested(); // Ignore any other unknown kinds of documents var standardDocument = document as StandardTextDocument; if (standardDocument == null) { return; } // If it's already open, then we have nothing more to do here. if (standardDocument.IsOpen) { return; } if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie)) { TryProcessOpenForDocCookie(docCookie, cancellationToken); } cancellationToken.ThrowIfCancellationRequested(); CancelPendingDocumentInitializationTask(document); }
internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument) { // We need to ensure the file is saved, only if a global undo transaction is open var globalUndoService = this.Services.GetService <IGlobalUndoService>(); bool needsSave = globalUndoService.IsGlobalTransactionOpen(this); bool needsUndoDisabled = needsSave && this.Services.GetService <IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id)); return(new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled)); }
private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument) { vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile( project, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType), _ => SpecializedCollections.EmptyReadOnlyList <string>()); return(vsDocument != null); }
private void CancelPendingDocumentInitializationTask_NoLock(IVisualStudioHostDocument document) { // Remove pending initialization task for the document, if any, and dispose the cancellation token source. if (_pendingDocumentInitializationTasks.TryGetValue(document.Id, out var taskAndTokenSource)) { taskAndTokenSource.CancellationTokenSource.Cancel(); taskAndTokenSource.CancellationTokenSource.Dispose(); _pendingDocumentInitializationTasks.Remove(document.Id); } }
private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument) { // We already have an AbstractProject, so the workspace has been created vsDocument = _vsWorkspace.DeferredState.ProjectTracker.DocumentProvider.TryGetDocumentForFile( project, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType), ImmutableArray <string> .Empty); return(vsDocument != null); }
internal void OnFileIncludedInProject(IVisualStudioHostDocument document) { uint docCookie; if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.FilePath, out docCookie)) { TryRemoveDocumentFromMiscellaneousWorkspace(docCookie, document.FilePath); } _filesInProjects.Add(document.Key); }
public void RemoveAdditionalFile(string additionalFilePath) { IVisualStudioHostDocument document = this.GetCurrentDocumentFromPath(additionalFilePath); if (document == null) { throw new InvalidOperationException("The document is not a part of the finalProject."); } RemoveAdditionalDocument(document); }
/// <summary> /// If the document is open in the running document table, this returns the hierarchy in /// which it is currently open. Otherwise, it returns null. /// </summary> private IVsHierarchy GetContextHierarchyFromRunningDocumentTable(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { AssertIsForeground(); if (!runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie)) { return null; } runningDocumentTable.GetDocumentHierarchyItem(docCookie, out var hierarchy, out var itemid); return hierarchy; }
/// <summary> /// If the document is open in the running document table, this returns the hierarchy in /// which it is currently open. Otherwise, it returns null. /// </summary> private IVsHierarchy GetContextHierarchyFromRunningDocumentTable(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { AssertIsForeground(); if (!runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out var docCookie)) { return(null); } runningDocumentTable.GetDocumentHierarchyItem(docCookie, out var hierarchy, out var itemid); return(hierarchy); }
internal void OnFileRemovedFromProject(IVisualStudioHostDocument document) { // Remove the document key from the filesInProjects map first because adding documents // to the misc files workspace requires that they not appear in this map. _filesInProjects.Remove(document.Key); uint docCookie; if (_runningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie)) { AddDocumentToMiscellaneousOrMetadataAsSourceWorkspace(docCookie, document.Key.Moniker); } }
/// <summary> /// Notifies the document provider that this document is now registered in a project. /// If we are on a foregroud thread, then this is done right away. /// Otherwise, we schedule a task on foreground task scheduler. /// </summary> public void NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(IVisualStudioHostDocument document) { if (IsForeground()) { NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(document, cancellationToken: CancellationToken.None); } else { var cts = new CancellationTokenSource(); var task = InvokeBelowInputPriority(() => NotifyDocumentRegisteredToProjectAndStartToRaiseEvents_Core(document, cts.Token), cts.Token); AddPendingDocumentInitializationTask(document, task, cts); } }
private void AddPendingDocumentInitializationTask(IVisualStudioHostDocument document, Task task, CancellationTokenSource cts) { var taskAndTokenSource = new TaskAndTokenSource() { Task = task, CancellationTokenSource = cts }; lock (_gate) { // Add taskAndTokenSource to the pending document initialization tasks. // Check for cancellation before adding as the task might already have been completed/cancelled/faulted before we reached here. if (!cts.IsCancellationRequested && !task.IsCompleted) { _pendingDocumentInitializationTasks.Add(document.Id, taskAndTokenSource); } } }
private void OnDocumentClosed(uint docCookie) { RunningDocumentInfo info = _rdt.Value.GetDocumentInfo(docCookie); AbstractProject project = GetXamlProject(info.Hierarchy); if (project == null) { return; } IVisualStudioHostDocument document = project.GetCurrentDocumentFromPath(info.Moniker); if (document == null) { return; } project.RemoveDocument(document); }
/// <summary> /// If the document is in a Shared Code project, this returns that project's /// SharedItemContextHierarchy. Otherwise, it returns null. /// </summary> private IVsHierarchy GetSharedItemContextHierarchy(IVisualStudioHostDocument document) { AssertIsForeground(); var itemId = document.GetItemId(); if (itemId == (uint)VSConstants.VSITEMID.Nil) { // the document is no longer part of the solution return null; } var sharedHierarchy = GetSharedHierarchyForItem(document.Project.Hierarchy, itemId); if (sharedHierarchy == null) { return null; } return GetSharedItemContextHierarchy(sharedHierarchy); }
private bool TryGetFrame(IVisualStudioHostDocument document, out IVsWindowFrame frame) { frame = null; var itemId = document.GetItemId(); if (itemId == (uint)VSConstants.VSITEMID.Nil) { // If the ItemId is Nil, then then IVsProject would not be able to open the // document using its ItemId. Thus, we must use OpenDocumentViaProject, which only // depends on the file path. uint itemid; IVsUIHierarchy uiHierarchy; OLEServiceProvider oleServiceProvider; return(ErrorHandler.Succeeded(_shellOpenDocument.OpenDocumentViaProject( document.FilePath, VSConstants.LOGVIEWID.TextView_guid, out oleServiceProvider, out uiHierarchy, out itemid, out frame))); } else { // If the ItemId is not Nil, then we should not call IVsUIShellDocument // .OpenDocumentViaProject here because that simply takes a file path and opens the // file within the context of the first project it finds. That would cause problems // if the document we're trying to open is actually a linked file in another // project. So, we get the project's hierarchy and open the document using its item // ID. // It's conceivable that IVsHierarchy might not implement IVsProject. However, // OpenDocumentViaProject itself relies upon this QI working, so it should be OK to // use here. var vsProject = document.Project.Hierarchy as IVsProject; return(vsProject != null && ErrorHandler.Succeeded(vsProject.OpenItem(itemId, VSConstants.LOGVIEWID.TextView_guid, s_docDataExisting_Unknown, out frame))); } }
/// <summary> /// If the document is in a Shared Code project, this returns that project's /// SharedItemContextHierarchy. Otherwise, it returns null. /// </summary> private IVsHierarchy GetSharedItemContextHierarchy(IVisualStudioHostDocument document) { AssertIsForeground(); var itemId = document.GetItemId(); if (itemId == (uint)VSConstants.VSITEMID.Nil) { // the document is no longer part of the solution return(null); } var sharedHierarchy = GetSharedHierarchyForItem(document.Project.Hierarchy, itemId); if (sharedHierarchy == null) { return(null); } return(GetSharedItemContextHierarchy(sharedHierarchy)); }
private void OnDocumentMonikerChanged(IVsHierarchy hierarchy, string oldMoniker, string newMoniker) { // If the moniker change only involves casing differences then the project system will // not remove & add the file again with the new name, so we should not clear any state. // Leaving the old casing in the DocumentKey is safe because DocumentKey equality // checks ignore the casing of the moniker. if (oldMoniker.Equals(newMoniker, StringComparison.OrdinalIgnoreCase)) { return; } // If the moniker change only involves a non-XAML project then ignore it. AbstractProject project = GetXamlProject(hierarchy); if (project == null) { return; } // Managed languages rely on the msbuild host object to add and remove documents during rename. // For XAML we have to do that ourselves. IVisualStudioHostDocument oldDocument = project.GetCurrentDocumentFromPath(oldMoniker); if (oldDocument != null) { project.RemoveDocument(oldDocument); } IVisualStudioHostDocument newDocument = project.GetCurrentDocumentFromPath(newMoniker); Debug.Assert(newDocument == null, "Why does the renamed document already exist in the project?"); if (newDocument == null) { if (TryCreateXamlDocument(project, newMoniker, out newDocument)) { project.AddDocument(newDocument, isCurrentContext: true, hookupHandlers: true); } } }
/// <summary> /// Notifies the document provider that this document is now registered in a project. /// </summary> public void NotifyDocumentRegisteredToProject(IVisualStudioHostDocument document) { // Ignore any other unknown kinds of documents var standardDocument = document as StandardTextDocument; if (standardDocument == null) { return; } // If it's already open, then we have nothing more to do here. if (standardDocument.IsOpen) { return; } uint docCookie; if (RunningDocumentTable.TryGetCookieForInitializedDocument(document.Key.Moniker, out docCookie)) { TryProcessOpenForDocCookie(docCookie); } }
internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument) { // We need to ensure the file is saved, only if a global undo transaction is open var globalUndoService = this.Services.GetService <IGlobalUndoService>(); var needsSave = globalUndoService.IsGlobalTransactionOpen(this); var needsUndoDisabled = false; if (needsSave) { if (this.CurrentSolution.ContainsDocument(hostDocument.Id)) { // Disable undo on generated documents needsUndoDisabled = this.Services.GetService <IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id)); } else { // Enable undo on "additional documents" or if no document can be found. needsUndoDisabled = false; } } return(new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled)); }
internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument) { var globalUndoService = this.Services.GetService <IGlobalUndoService>(); var needsUndoDisabled = false; // Do not save the file if is open and there is not a global undo transaction. var needsSave = globalUndoService.IsGlobalTransactionOpen(this) || !hostDocument.IsOpen; if (needsSave) { if (this.CurrentSolution.ContainsDocument(hostDocument.Id)) { // Disable undo on generated documents needsUndoDisabled = this.CurrentSolution.GetDocument(hostDocument.Id).IsGeneratedCode(CancellationToken.None); } else { // Enable undo on "additional documents" or if no document can be found. needsUndoDisabled = false; } } return(new InvisibleEditor(DeferredState.ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled)); }
/// <summary> /// Finds the current context hierarchy for the given document. If the document is in a /// Shared Code project, this returns that project's SharedItemContextHierarchy. If the /// document is linked into multiple projects, this returns the hierarchy in which it is /// currently open as indicated by the running document table. Otherwise, it returns the /// hierarchy of the document's project. /// </summary> public static IVsHierarchy GetContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { return s_singleton.GetContextHierarchyInternal(document, runningDocumentTable); }
private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument) { vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile( project, ImmutableArray<string>.Empty, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType)); return vsDocument != null; }
private IVsHierarchy GetContextHierarchyInternal(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { AssertIsForeground(); return GetSharedItemContextHierarchy(document) ?? GetContextHierarchyFromRunningDocumentTable(document, runningDocumentTable) ?? document.Project.Hierarchy; }
/// <summary> /// Finds the current context hierarchy for the given document. If the document is in a /// Shared Code project, this returns that project's SharedItemContextHierarchy. If the /// document is linked into multiple projects, this returns the hierarchy in which it is /// currently open as indicated by the running document table. Otherwise, it returns the /// hierarchy of the document's project. /// </summary> public static IVsHierarchy GetContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { return(s_singleton.GetContextHierarchyInternal(document, runningDocumentTable)); }
private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument) { vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile( project, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType), _ => SpecializedCollections.EmptyReadOnlyList<string>()); return vsDocument != null; }
public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { // runningDocumentTable might be null for tests. return runningDocumentTable != null && document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable); }
internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument) { // We need to ensure the file is saved, only if a global undo transaction is open var globalUndoService = this.Services.GetService<IGlobalUndoService>(); var needsSave = globalUndoService.IsGlobalTransactionOpen(this); var needsUndoDisabled = false; if (needsSave) { if (this.CurrentSolution.ContainsDocument(hostDocument.Id)) { // Disable undo on generated documents needsUndoDisabled = this.Services.GetService<IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id)); } else { // Enable undo on "additional documents" or if no document can be found. needsUndoDisabled = false; } } return new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled); }
public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { return(document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable)); }
public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { return document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable); }
internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isCurrentContext) { _additionalDocuments.Add(document.Id, document); _documentMonikers.Add(document.Key.Moniker, document); if (_pushingChangesToWorkspaceHosts) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentAdded(document.GetInitialState())); if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext)); } } document.Opened += s_additionalDocumentOpenedEventHandler; document.Closing += s_additionalDocumentClosingEventHandler; document.UpdatedOnDisk += s_additionalDocumentUpdatedOnDiskEventHandler; DocumentProvider.NotifyDocumentRegisteredToProject(document); if (!_pushingChangesToWorkspaceHosts && document.IsOpen) { StartPushingToWorkspaceAndNotifyOfOpenDocuments(); } }
private void AddGeneratedDocument(IVisualStudioHostDocument document, bool isCurrentContext) { // We do not want to allow message pumping/reentrancy when processing project system changes. using (Dispatcher.CurrentDispatcher.DisableProcessing()) { _documents.Add(document.Id, document); _documentMonikers.Add(document.Key.Moniker, document); if (_pushingChangesToWorkspaceHosts) { if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext)); } } document.Opened += s_documentOpenedEventHandler; document.Closing += s_documentClosingEventHandler; document.UpdatedOnDisk += s_documentUpdatedOnDiskEventHandler; DocumentProvider.NotifyDocumentRegisteredToProject(document); if (!_pushingChangesToWorkspaceHosts && document.IsOpen) { StartPushingToWorkspaceAndNotifyOfOpenDocuments(); } } }
internal abstract IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument document);
private void UninitializeAdditionalDocument(IVisualStudioHostDocument document) { if (_pushingChangesToWorkspaceHosts) { if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentClosed(document.Id, document.GetOpenTextBuffer(), document.Loader)); } this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentRemoved(document.Id)); } document.Opened -= s_additionalDocumentOpenedEventHandler; document.Closing -= s_additionalDocumentClosingEventHandler; document.UpdatedOnDisk -= s_additionalDocumentUpdatedOnDiskEventHandler; document.Dispose(); }
internal void RemoveAdditionalDocument(IVisualStudioHostDocument document) { _additionalDocuments.Remove(document.Id); _documentMonikers.Remove(document.Key.Moniker); UninitializeAdditionalDocument(document); }
private void UninitializeDocument(IVisualStudioHostDocument document) { if (_pushingChangesToWorkspaceHosts) { if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentClosed(document.Id, document.GetOpenTextBuffer(), document.Loader, updateActiveContext: true)); } this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentRemoved(document.Id)); } if (_miscellaneousFilesWorkspaceOpt != null) { _miscellaneousFilesWorkspaceOpt.OnFileRemovedFromProject(document); } document.Opened -= s_documentOpenedEventHandler; document.Closing -= s_documentClosingEventHandler; document.UpdatedOnDisk -= s_documentUpdatedOnDiskEventHandler; document.Dispose(); }
private void RemoveGeneratedDocument(IVisualStudioHostDocument document) { // We do not want to allow message pumping/reentrancy when processing project system changes. using (Dispatcher.CurrentDispatcher.DisableProcessing()) { _documents.Remove(document.Id); _documentMonikers.Remove(document.Key.Moniker); UninitializeDocument(document); OnDocumentRemoved(document.Key.Moniker); } }
internal void AddAdditionalDocument(IVisualStudioHostDocument document, bool isCurrentContext) { AssertIsForeground(); lock (_gate) { _additionalDocuments.Add(document.Id, document); _documentMonikers.Add(document.Key.Moniker, document); } if (_pushingChangesToWorkspaceHosts) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentAdded(document.GetInitialState())); if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnAdditionalDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext)); } } DocumentProvider.NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(document); if (!_pushingChangesToWorkspaceHosts && document.IsOpen) { StartPushingToWorkspaceAndNotifyOfOpenDocuments(); } }
internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument hostDocument) { // We need to ensure the file is saved, only if a global undo transaction is open var globalUndoService = this.Services.GetService<IGlobalUndoService>(); bool needsSave = globalUndoService.IsGlobalTransactionOpen(this); bool needsUndoDisabled = needsSave && this.Services.GetService<IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id)); return new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled); }
internal void RemoveAdditionalDocument(IVisualStudioHostDocument document) { AssertIsForeground(); lock (_gate) { _additionalDocuments.Remove(document.Id); _documentMonikers.Remove(document.Key.Moniker); } UninitializeAdditionalDocument(document); }
public static bool IsCurrentContextHierarchy(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { // runningDocumentTable might be null for tests. return(runningDocumentTable != null && document.Project.Hierarchy == GetContextHierarchy(document, runningDocumentTable)); }
private IVsHierarchy GetContextHierarchyInternal(IVisualStudioHostDocument document, IVsRunningDocumentTable4 runningDocumentTable) { AssertIsForeground(); return(GetSharedItemContextHierarchy(document) ?? GetContextHierarchyFromRunningDocumentTable(document, runningDocumentTable) ?? document.Project.Hierarchy); }
private void UninitializeDocument(IVisualStudioHostDocument document) { AssertIsForeground(); if (_pushingChangesToWorkspaceHosts) { if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentClosed(document.Id, document.GetOpenTextBuffer(), document.Loader, updateActiveContext: true)); } this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentRemoved(document.Id)); } document.Opened -= s_documentOpenedEventHandler; document.Closing -= s_documentClosingEventHandler; document.UpdatedOnDisk -= s_documentUpdatedOnDiskEventHandler; document.Dispose(); }
internal void AddDocument(IVisualStudioHostDocument document, bool isCurrentContext, bool hookupHandlers) { AssertIsForeground(); // We do not want to allow message pumping/reentrancy when processing project system changes. using (Dispatcher.CurrentDispatcher.DisableProcessing()) { lock (_gate) { _documents.Add(document.Id, document); _documentMonikers.Add(document.Key.Moniker, document); } if (_pushingChangesToWorkspaceHosts) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentAdded(document.GetInitialState())); if (document.IsOpen) { this.ProjectTracker.NotifyWorkspaceHosts(host => host.OnDocumentOpened(document.Id, document.GetOpenTextBuffer(), isCurrentContext)); } } if (hookupHandlers) { document.Opened += s_documentOpenedEventHandler; document.Closing += s_documentClosingEventHandler; document.UpdatedOnDisk += s_documentUpdatedOnDiskEventHandler; } DocumentProvider.NotifyDocumentRegisteredToProjectAndStartToRaiseEvents(document); if (!_pushingChangesToWorkspaceHosts && document.IsOpen) { StartPushingToWorkspaceAndNotifyOfOpenDocuments(); } } }
internal void RemoveDocument(IVisualStudioHostDocument document) { AssertIsForeground(); // We do not want to allow message pumping/reentrancy when processing project system changes. using (Dispatcher.CurrentDispatcher.DisableProcessing()) { lock (_gate) { _documents.Remove(document.Id); _documentMonikers.Remove(document.Key.Moniker); } UninitializeDocument(document); OnDocumentRemoved(document.Key.Moniker); } }