Selaa lähdekoodia

Update functionality for file history

Ruben 6 kuukautta sitten
vanhempi
sitoutus
0d3c1915fc

+ 3 - 0
src/PicView.Avalonia/Functions/FunctionsMapper.cs

@@ -865,6 +865,9 @@ public static class FunctionsMapper
     public static async Task ShowKeybindingsFile() =>
     public static async Task ShowKeybindingsFile() =>
         await Task.Run(() => Vm?.PlatformService?.OpenWith(KeybindingFunctions.CurrentKeybindingsPath)).ConfigureAwait(false);
         await Task.Run(() => Vm?.PlatformService?.OpenWith(KeybindingFunctions.CurrentKeybindingsPath)).ConfigureAwait(false);
     
     
+    public static async Task ShowRecentHistoryFile() =>
+        await Task.Run(() => Vm?.PlatformService?.OpenWith(FileHistoryManager.CurrentFileHistoryFile)).ConfigureAwait(false);
+    
     /// <inheritdoc cref="SettingsUpdater.ToggleUsingTouchpad(MainViewModel)" />
     /// <inheritdoc cref="SettingsUpdater.ToggleUsingTouchpad(MainViewModel)" />
     public static async Task ToggleUsingTouchpad() =>
     public static async Task ToggleUsingTouchpad() =>
         await SettingsUpdater.ToggleUsingTouchpad(Vm).ConfigureAwait(false);
         await SettingsUpdater.ToggleUsingTouchpad(Vm).ConfigureAwait(false);

+ 4 - 4
src/PicView.Avalonia/PicView.Avalonia.csproj

@@ -103,11 +103,11 @@
   </ItemGroup>
   </ItemGroup>
 
 
   <ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Avalonia" Version="11.2.6" />
-    <PackageReference Include="Avalonia.Desktop" Version="11.2.6" />
-    <PackageReference Include="Avalonia.ReactiveUI" Version="11.2.6" />
+    <PackageReference Include="Avalonia" Version="11.3.0-beta2" />
+    <PackageReference Include="Avalonia.Desktop" Version="11.3.0-beta2" />
+    <PackageReference Include="Avalonia.ReactiveUI" Version="11.3.0-beta2" />
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
-    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.6" />
+    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.0-beta2" />
     <PackageReference Include="Avalonia.Svg.Skia" Version="11.2.0.2" />
     <PackageReference Include="Avalonia.Svg.Skia" Version="11.2.0.2" />
   </ItemGroup>
   </ItemGroup>
 
 

+ 8 - 2
src/PicView.Avalonia/Views/MainView.axaml.cs

@@ -7,6 +7,7 @@ using Avalonia.Threading;
 using PicView.Avalonia.Converters;
 using PicView.Avalonia.Converters;
 using PicView.Avalonia.Crop;
 using PicView.Avalonia.Crop;
 using PicView.Avalonia.DragAndDrop;
 using PicView.Avalonia.DragAndDrop;
+using PicView.Avalonia.Functions;
 using PicView.Avalonia.Input;
 using PicView.Avalonia.Input;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.UI.FileHistory;
 using PicView.Avalonia.UI.FileHistory;
@@ -60,7 +61,12 @@ public partial class MainView : UserControl
                 return;
                 return;
             }
             }
             // Initialize the history menu controller
             // Initialize the history menu controller
+            // TODO: rewrite FileHistory to MVVM
             FileHistoryMenuController = new FileHistoryMenuController(RecentFilesCM, HistorySortButton, HistoryClearButton, vm);
             FileHistoryMenuController = new FileHistoryMenuController(RecentFilesCM, HistorySortButton, HistoryClearButton, vm);
+            HistoryFileButton.Click += async delegate
+            {
+                await FunctionsMapper.ShowRecentHistoryFile();
+            };
 
 
             HideInterfaceLogic.AddHoverButtonEvents(AltButtonsPanel, vm);
             HideInterfaceLogic.AddHoverButtonEvents(AltButtonsPanel, vm);
             PointerWheelChanged += async (_, e) => await vm.ImageViewer.PreviewOnPointerWheelChanged(this, e);
             PointerWheelChanged += async (_, e) => await vm.ImageViewer.PreviewOnPointerWheelChanged(this, e);
@@ -124,10 +130,10 @@ public partial class MainView : UserControl
             }
             }
             var isNavigatingWithCtrl = Settings.Zoom.CtrlZoom;
             var isNavigatingWithCtrl = Settings.Zoom.CtrlZoom;
             vm.ChangeCtrlZoomImage = isNavigatingWithCtrl ? leftRightArrowsImage as DrawingImage : scanEyeImage as DrawingImage;
             vm.ChangeCtrlZoomImage = isNavigatingWithCtrl ? leftRightArrowsImage as DrawingImage : scanEyeImage as DrawingImage;
-        }, DispatcherPriority.Render);
+        });
         
         
         // Update file history menu items in Dispatcher with low priority to avoid slowdown
         // Update file history menu items in Dispatcher with low priority to avoid slowdown
-        await Dispatcher.UIThread.InvokeAsync(() => FileHistoryMenuController?.UpdateFileHistoryMenu(), DispatcherPriority.Background);
+        await Dispatcher.UIThread.InvokeAsync(() => FileHistoryMenuController?.UpdateFileHistoryMenu());
     }
     }
 
 
     private async Task Drop(object? sender, DragEventArgs e)
     private async Task Drop(object? sender, DragEventArgs e)

+ 5 - 3
src/PicView.Core/FileHistory/FileHistoryManager.cs

@@ -18,7 +18,7 @@ internal partial class FileHistoryGenerationContext : JsonSerializerContext;
 public static class FileHistoryManager
 public static class FileHistoryManager
 {
 {
     private const int MaxHistoryEntries = 50;
     private const int MaxHistoryEntries = 50;
-    private const int MaxPinnedEntries = 5;
+    public const int MaxPinnedEntries = 5;
     private static readonly List<Entry> Entries = [];
     private static readonly List<Entry> Entries = [];
     private static string? _fileLocation;
     private static string? _fileLocation;
 
 
@@ -62,6 +62,8 @@ public static class FileHistoryManager
     public static string? CurrentEntry =>
     public static string? CurrentEntry =>
         CurrentIndex >= 0 && CurrentIndex < Count ? Entries[CurrentIndex].Path : null;
         CurrentIndex >= 0 && CurrentIndex < Count ? Entries[CurrentIndex].Path : null;
 
 
+    public static string CurrentFileHistoryFile => _fileLocation.Replace("/", "\\");
+
     /// <summary>
     /// <summary>
     ///     Initializes the file history by loading entries from the history file.
     ///     Initializes the file history by loading entries from the history file.
     /// </summary>
     /// </summary>
@@ -370,10 +372,10 @@ public static class FileHistoryManager
             var sortedEntries = new List<Entry>();
             var sortedEntries = new List<Entry>();
 
 
             // Add all pinned entries first (preserving their original order) - should be max 5
             // Add all pinned entries first (preserving their original order) - should be max 5
-            sortedEntries.AddRange(Entries.Where(e => e.IsPinned));
+            sortedEntries.AddRange(Entries.Where(e => e.IsPinned).Take(MaxPinnedEntries));
 
 
             // Then add all unpinned entries (preserving their original order) - limited by MaxHistoryEntries
             // Then add all unpinned entries (preserving their original order) - limited by MaxHistoryEntries
-            sortedEntries.AddRange(Entries.Where(e => !e.IsPinned));
+            sortedEntries.AddRange(Entries.Where(e => !e.IsPinned).Take(MaxHistoryEntries));
 
 
             var historyEntries = new FileHistoryEntries
             var historyEntries = new FileHistoryEntries
             {
             {