From 28d3209cb11fbe3fca3ebaa202f84ebffd9470d1 Mon Sep 17 00:00:00 2001 From: Samir Boulema Date: Wed, 5 Feb 2025 21:14:09 +0100 Subject: [PATCH] fix: Fix refresh documents that are above the line threshold --- CodeNav.Shared/CodeNavMargin.cs | 2 +- CodeNav.Shared/CodeViewUserControl.xaml.cs | 13 +++++++------ CodeNav.Shared/CodeViewUserControlTop.xaml.cs | 7 ++++--- CodeNav.Shared/Controls/MainToolbar.xaml.cs | 2 +- CodeNav.Shared/Helpers/DocumentHelper.cs | 7 ++++--- CodeNav.Shared/ICodeViewUserControl.cs | 9 +++++++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/CodeNav.Shared/CodeNavMargin.cs b/CodeNav.Shared/CodeNavMargin.cs index d01c050..899ba44 100644 --- a/CodeNav.Shared/CodeNavMargin.cs +++ b/CodeNav.Shared/CodeNavMargin.cs @@ -265,7 +265,7 @@ public void Dispose() _control.CaretPositionChangedSubscription?.Dispose(); _control.TextContentChangedSubscription?.Dispose(); _control.UpdateWhileTypingSubscription?.Dispose(); - _control.FileActionOccuredSubscription?.Dispose(); + _control.FileActionOccurredSubscription?.Dispose(); GC.SuppressFinalize(this); _isDisposed = true; diff --git a/CodeNav.Shared/CodeViewUserControl.xaml.cs b/CodeNav.Shared/CodeViewUserControl.xaml.cs index 4a50cdd..b4e6de5 100644 --- a/CodeNav.Shared/CodeViewUserControl.xaml.cs +++ b/CodeNav.Shared/CodeViewUserControl.xaml.cs @@ -27,7 +27,7 @@ public partial class CodeViewUserControl : ICodeViewUserControl public IDisposable? CaretPositionChangedSubscription { get; set; } public IDisposable? TextContentChangedSubscription { get; set; } public IDisposable? UpdateWhileTypingSubscription { get; set; } - public IDisposable? FileActionOccuredSubscription { get; set; } + public IDisposable? FileActionOccurredSubscription { get; set; } public CodeDocumentViewModel CodeDocumentViewModel { get; set; } @@ -35,7 +35,7 @@ public CodeViewUserControl(ColumnDefinition? column = null) { InitializeComponent(); - // Setup viewmodel as datacontext + // Setup view model as data context CodeDocumentViewModel = new CodeDocumentViewModel(); DataContext = CodeDocumentViewModel; @@ -54,9 +54,9 @@ public async Task RegisterDocumentEvents() var textBuffer2 = documentView?.TextView?.TextBuffer as ITextBuffer2; // Subscribe to Document save events - if (document != null && FileActionOccuredSubscription == null) + if (document != null && FileActionOccurredSubscription == null) { - FileActionOccuredSubscription = Observable + FileActionOccurredSubscription = Observable .FromEventPattern( h => document.FileActionOccurred += h, h => document.FileActionOccurred -= h) @@ -185,9 +185,10 @@ public void FilterBookmarks() public void ToggleAll(bool isExpanded, List? root = null) => OutliningHelper.ToggleAll(root ?? CodeDocumentViewModel.CodeDocument, isExpanded); - public void UpdateDocument(string filePath = "") + /// + public void UpdateDocument(string filePath = "", bool force = false) => ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel, - _column, null, filePath)); + _column, null, filePath, force)); public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor) => HighlightHelper.HighlightCurrentItem( diff --git a/CodeNav.Shared/CodeViewUserControlTop.xaml.cs b/CodeNav.Shared/CodeViewUserControlTop.xaml.cs index 12f1b79..c2128bd 100644 --- a/CodeNav.Shared/CodeViewUserControlTop.xaml.cs +++ b/CodeNav.Shared/CodeViewUserControlTop.xaml.cs @@ -22,7 +22,7 @@ public partial class CodeViewUserControlTop : ICodeViewUserControl public IDisposable? CaretPositionChangedSubscription { get; set; } public IDisposable? TextContentChangedSubscription { get; set; } public IDisposable? UpdateWhileTypingSubscription { get; set; } - public IDisposable? FileActionOccuredSubscription { get; set; } + public IDisposable? FileActionOccurredSubscription { get; set; } public CodeDocumentViewModel CodeDocumentViewModel { get; set; } @@ -55,9 +55,10 @@ public void ToggleAll(bool isExpanded, List? root = null) OutliningHelper.ToggleAll(root ?? CodeDocumentViewModel.CodeDocument, isExpanded); } - public void UpdateDocument(string filePath = "") + /// + public void UpdateDocument(string filePath = "", bool force = false) => ThreadHelper.JoinableTaskFactory.RunAsync(async () => await DocumentHelper.UpdateDocument(this, CodeDocumentViewModel, - null, _row, filePath)); + null, _row, filePath, force)); public void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor) { diff --git a/CodeNav.Shared/Controls/MainToolbar.xaml.cs b/CodeNav.Shared/Controls/MainToolbar.xaml.cs index dacff7e..02d3f3b 100644 --- a/CodeNav.Shared/Controls/MainToolbar.xaml.cs +++ b/CodeNav.Shared/Controls/MainToolbar.xaml.cs @@ -21,7 +21,7 @@ public MainToolbar() } private void ButtonRefresh_OnClick(object sender, RoutedEventArgs e) - => WpfHelper.FindParent(this)?.UpdateDocument(); + => WpfHelper.FindParent(this)?.UpdateDocument(force: true); private void ButtonSortByFileOrder_OnClick(object sender, RoutedEventArgs e) => Sort(SortOrderEnum.SortByFile).FireAndForget(); diff --git a/CodeNav.Shared/Helpers/DocumentHelper.cs b/CodeNav.Shared/Helpers/DocumentHelper.cs index 32af884..4bc6668 100644 --- a/CodeNav.Shared/Helpers/DocumentHelper.cs +++ b/CodeNav.Shared/Helpers/DocumentHelper.cs @@ -231,7 +231,8 @@ public static async Task UpdateDocument(ICodeViewUserControl control, CodeDocumentViewModel codeDocumentViewModel, ColumnDefinition? column = null, RowDefinition? row = null, - string filePath = "") + string filePath = "", + bool force = false) { if (string.IsNullOrEmpty(filePath)) { @@ -242,7 +243,7 @@ public static async Task UpdateDocument(ICodeViewUserControl control, try { - if (await IsLargeDocument()) + if (await IsLargeDocument() && !force) { codeDocumentViewModel.CodeDocument = PlaceholderHelper.CreateLineThresholdPassedItem(); return; @@ -270,7 +271,7 @@ public static async Task UpdateDocument(ICodeViewUserControl control, codeDocumentViewModel.SortOrder = (SortOrderEnum)general.SortOrder; SortHelper.Sort(items, (SortOrderEnum)general.SortOrder); - // Set the new list of codeitems as DataContext + // Set the new list of code items as DataContext codeDocumentViewModel.CodeDocument = items; // Apply highlights diff --git a/CodeNav.Shared/ICodeViewUserControl.cs b/CodeNav.Shared/ICodeViewUserControl.cs index 62f4190..e99cea3 100644 --- a/CodeNav.Shared/ICodeViewUserControl.cs +++ b/CodeNav.Shared/ICodeViewUserControl.cs @@ -14,7 +14,12 @@ public interface ICodeViewUserControl { CodeDocumentViewModel CodeDocumentViewModel { get; set; } - void UpdateDocument(string filePath = ""); + /// + /// Update the Code Document View Model + /// + /// Optional path to use as code source file + /// Optional boolean to indicate to update documents that may contain too many lines + void UpdateDocument(string filePath = "", bool force = false); void HighlightCurrentItem(CaretPositionChangedEventArgs e, Color backgroundBrushColor); @@ -30,6 +35,6 @@ public interface ICodeViewUserControl IDisposable? UpdateWhileTypingSubscription { get; set; } - IDisposable? FileActionOccuredSubscription { get; set; } + IDisposable? FileActionOccurredSubscription { get; set; } } }