protected override async Task <CodeMapWindow> OpenToolWindowAsync() { CodeMapWindow codeMapWindow = await base.OpenToolWindowAsync(); if (codeMapWindow?.CodeMapWPFControl == null) { return(codeMapWindow); } CodeMapWindowViewModel codeMapViewModel = codeMapWindow.CodeMapWPFControl.DataContext as CodeMapWindowViewModel; IWpfTextView textView = await ServiceProvider.GetWpfTextViewAsync(); Document document = textView?.TextSnapshot?.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) { return(codeMapWindow); } else if (CheckIfSameDocumentWasReOpened(codeMapViewModel, document)) //Return window in case of re-openning of the same doc { codeMapWindow.CodeMapWPFControl.DataContext = CodeMapWindowViewModel.InitCodeMap(textView, document); return(codeMapWindow); } else if (codeMapViewModel != null) //Cancel operations in case of another doc and dispose of the old view model { codeMapViewModel.CancelCodeMapBuilding(); codeMapViewModel.Dispose(); } codeMapWindow.CodeMapWPFControl.DataContext = CodeMapWindowViewModel.InitCodeMap(textView, document); return(codeMapWindow); }
public override async void OnToolWindowCreated() { base.OnToolWindowCreated(); // Set the text that will appear in the title bar of the tool window. Note that because we need access to the package for localization, // we have to wait to do this here. If we used a constant string, we could do this in the constructor. this.Caption = VSIXResource.CodeMap_WindowTitle; if (CodeMapWPFControl == null) { return; } IAsyncServiceProvider serviceProvider = AcuminatorVSPackage.Instance ?? AsyncServiceProvider.GlobalProvider; if (serviceProvider == null) { return; } Workspace?workspace = await AcuminatorVSPackage.Instance.GetVSWorkspaceAsync(); if (workspace == null) { return; } IWpfTextView?textView = await ThreadHelper.JoinableTaskFactory.RunAsync(serviceProvider.GetWpfTextViewAsync); Document?document = textView?.TextSnapshot?.GetOpenDocumentInCurrentContextWithChanges(); if (CodeMapWPFControl.DataContext is CodeMapWindowViewModel codeMapViewModel) { await codeMapViewModel.RefreshCodeMapOnWindowOpeningAsync(textView, document); } else { CodeMapWPFControl.DataContext = CodeMapWindowViewModel.InitCodeMap(workspace, textView, document); } }