private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { try { var result = e.Result as BackgroundWorkerResult; if (result?.CodeItems == null) { LogHelper.Log($"CodeNav for '{DocumentHelper.GetName(_window)}' updated, no results"); return; } // Filter all null items from the code document SyntaxMapper.FilterNullItems(result.CodeItems); // Do we need to update the DataContext? var areEqual = AreDocumentsEqual(CodeDocumentViewModel.CodeDocument, result.CodeItems); if (result.ForceUpdate == false && areEqual) { LogHelper.Log($"CodeNav for '{DocumentHelper.GetName(_window)}' updated, document did not change"); // Should the margin be shown and are there any items to show, if not hide the margin VisibilityHelper.SetMarginWidth(_column, CodeDocumentViewModel.CodeDocument); return; } // Set the new list of codeitems as DataContext CodeDocumentViewModel.CodeDocument = result.CodeItems; _cache = result.CodeItems; // Set currently active codeitem HighlightHelper.SetForeground(CodeDocumentViewModel.CodeDocument); // Should the margin be shown and are there any items to show, if not hide the margin VisibilityHelper.SetMarginWidth(_column, CodeDocumentViewModel.CodeDocument); // Apply current visibility settings to the document VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel.CodeDocument); // Sync all regions OutliningHelper.SyncAllRegions(OutliningManager, TextView, CodeDocumentViewModel.CodeDocument); // Sort items CodeDocumentViewModel.SortOrder = Settings.Default.SortOrder; SortHelper.Sort(CodeDocumentViewModel); // Apply bookmarks LoadBookmarksFromStorage(); BookmarkHelper.ApplyBookmarks(CodeDocumentViewModel, Dte?.Solution?.FileName); LogHelper.Log($"CodeNav for '{DocumentHelper.GetName(_window)}' updated"); } catch (ObjectDisposedException ex) { LogHelper.Log($"CodeNav: RunWorkerCompleted exception: {ex.Message}"); LogHelper.Log("RunWorkerCompleted exception", ex); } }
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { var result = e.Result as BackgroundWorkerResult; if (result?.CodeItems == null) { LogHelper.Log($"CodeNav for '{_window.Document.Name}' updated, no results"); return; } // Filter all null items from the code document SyntaxMapper.FilterNullItems(result.CodeItems); // Do we need to update the DataContext? var areEqual = AreDocumentsEqual(CodeDocumentViewModel.CodeDocument, result.CodeItems); if (result.ForceUpdate == false && areEqual) { LogHelper.Log($"CodeNav for '{_window.Document.Name}' updated, document did not change"); return; } // Set the new list of codeitems as DataContext CodeDocumentViewModel.CodeDocument = result.CodeItems; _cache = result.CodeItems; // Set currently active codeitem HighlightHelper.SetForeground(CodeDocumentViewModel.CodeDocument); // Are there any items to show, if not hide the margin VisibilityHelper.SetMarginWidth(_column, CodeDocumentViewModel.CodeDocument); // Apply current visibility settings to the document VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel.CodeDocument); // Sync all regions OutliningHelper.SyncAllRegions(_outliningManager, _textView, CodeDocumentViewModel.CodeDocument); LogHelper.Log($"CodeNav for '{_window.Document.Name}' updated"); }
public async Task UpdateDocumentAsync(bool forceUpdate = false) { await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var activeDocument = DocumentHelper.GetActiveDocument(Dte); if (activeDocument == null) { return; } CodeDocumentViewModel.FilePath = activeDocument.FullName; // Do we need to change the side where the margin is displayed if (_margin?.MarginSide != null && _margin?.MarginSide != Settings.Default.MarginSide && Dte != null) { var filename = activeDocument.FullName; Dte.ExecuteCommand("File.Close"); Dte.ExecuteCommand("File.OpenFile", filename); } try { if (forceUpdate) { _cache = null; CodeDocumentViewModel.CodeDocument.Clear(); } // Do we have a cached version of this document if (_cache != null) { CodeDocumentViewModel.CodeDocument = _cache; } // If not show a loading item if (!CodeDocumentViewModel.CodeDocument.Any()) { CodeDocumentViewModel.CodeDocument = CreateLoadingItem(); } var codeItems = await SyntaxMapper.MapDocumentAsync(activeDocument, this, _workspace); if (codeItems == null) { // CodeNav for document updated, no results return; } // Filter all null items from the code document SyntaxMapper.FilterNullItems(codeItems); // Sort items CodeDocumentViewModel.SortOrder = Settings.Default.SortOrder; SortHelper.Sort(codeItems, Settings.Default.SortOrder); // Set currently active codeitem HighlightHelper.SetForeground(codeItems); // Set the new list of codeitems as DataContext CodeDocumentViewModel.CodeDocument = codeItems; _cache = codeItems; // Apply current visibility settings to the document VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel); // Apply bookmarks LoadBookmarksFromStorage(); BookmarkHelper.ApplyBookmarks(CodeDocumentViewModel, Dte?.Solution?.FileName); // Apply history items LoadHistoryItemsFromStorage(); HistoryHelper.ApplyHistoryIndicator(CodeDocumentViewModel); } catch (Exception e) { LogHelper.Log("Error running UpdateDocument", e); } try { // Sync all regions OutliningHelper.SyncAllRegions(OutliningManagerService, TextView, CodeDocumentViewModel.CodeDocument); // Should the margin be shown and are there any items to show, if not hide the margin VisibilityHelper.SetMarginHeight(_row, CodeDocumentViewModel.CodeDocument); } catch (Exception e) { LogHelper.Log("Error finishing UpdateDocument", e); } }