Browse Source

Duplicate file fixes

Ruben 9 months ago
parent
commit
a243293883

+ 21 - 0
src/PicView.Avalonia/Clipboard/ClipboardHelper.cs

@@ -13,6 +13,7 @@ using PicView.Avalonia.ImageHandling;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
+using PicView.Core.FileHandling;
 using PicView.Core.Localization;
 using PicView.Core.ProcessHandling;
 
@@ -46,6 +47,26 @@ public static class ClipboardHelper
             UIHelper.GetMainView.MainGrid.Children.Remove(rectangle);
         });
     }
+
+    public static async Task Duplicate(MainViewModel vm)
+    {
+        if (!NavigationHelper.CanNavigate(vm))
+        {
+            return;
+        }
+        vm.IsLoading = true;
+        var oldPath = vm.FileInfo.FullName;
+        var duplicatedPathTask = Task.FromResult(FileHelper.DuplicateAndReturnFileName(oldPath));
+        await Task.WhenAll(CopyAnimation(), duplicatedPathTask);
+        var duplicatedPath = await duplicatedPathTask;
+        if (!File.Exists(duplicatedPath))
+        {
+            return;
+        }
+        vm.ImageIterator.Clear();
+        await NavigationHelper.LoadPicFromFile(duplicatedPath, vm);
+    }
+    
     public static async Task CopyTextToClipboard(string text)
     {
         if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)

+ 0 - 12
src/PicView.Avalonia/Navigation/NavigationHelper.cs

@@ -12,7 +12,6 @@ using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.WindowBehavior;
 using PicView.Core.ArchiveHandling;
 using PicView.Core.Config;
-using PicView.Core.FileHandling;
 using PicView.Core.Gallery;
 using PicView.Core.ImageDecoding;
 using PicView.Core.Localization;
@@ -235,17 +234,6 @@ public static class NavigationHelper
         }
     }
 
-    public static async Task DuplicateAndNavigate(MainViewModel vm)
-    {
-        if (!CanNavigate(vm))
-        {
-            return;
-        }
-        vm.IsLoading = true;
-        var oldPath = vm.FileInfo.FullName;
-        await Task.FromResult(FileHelper.DuplicateAndReturnFileName(oldPath)).ConfigureAwait(false);
-    }
-
     #endregion
 
     #region Load pictures from string, file or url

+ 8 - 1
src/PicView.Avalonia/UI/FunctionsHelper.cs

@@ -86,6 +86,7 @@ public static class FunctionsHelper
             "ResizeWindow" => ResizeWindow,
             "SettingsWindow" => SettingsWindow,
             "KeybindingsWindow" => KeybindingsWindow,
+            "BatchResizeWindow" => BatchResizeWindow,
 
             // Open functions
             "Open" => Open,
@@ -466,6 +467,12 @@ public static class FunctionsHelper
         Vm?.PlatformService?.ShowSingleImageResizeWindow();
         return Task.CompletedTask;
     }
+    
+    public static Task BatchResizeWindow()
+    {
+        Vm?.PlatformService?.ShowBatchResizeWindow();
+        return Task.CompletedTask;
+    }
 
     public static Task SettingsWindow()
     {
@@ -667,7 +674,7 @@ public static class FunctionsHelper
 
     public static async Task DuplicateFile()
     {
-        await NavigationHelper.DuplicateAndNavigate(Vm).ConfigureAwait(false);
+        await ClipboardHelper.Duplicate(Vm).ConfigureAwait(false);
     }
 
     public static async Task CutFile()