Browse Source

Refactor: move wallpaper-related logic to `ToolsViewModel`. Update bindings across views, remove redundant commands and methods from `MainViewModel`, and enhance command structure for wallpaper tasks.

Ruben 3 months ago
parent
commit
1d10985068

+ 1 - 1
src/PicView.Avalonia.MacOS/Views/MacMainWindow.axaml

@@ -147,7 +147,7 @@
                                                     Converter={x:Static ObjectConverters.IsNotNull}}" />
                     <NativeMenuItemSeparator />
                     <NativeMenuItem
-                        Command="{CompiledBinding SetAsWallpaperCommand}"
+                        Command="{CompiledBinding Tools.SetAsWallpaperCommand}"
                         CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                            FallbackValue=''}"
                         Header="{CompiledBinding Translation.SetAsWallpaper.Value,

+ 1 - 1
src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml

@@ -113,7 +113,7 @@
                             </MenuItem>
                             <Separator />
                             <MenuItem
-                                Command="{CompiledBinding SetAsWallpaperFilledCommand}"
+                                Command="{CompiledBinding Tools.SetAsWallpaperFilledCommand}"
                                 CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                                    FallbackValue=''}"
                                 Header="{CompiledBinding Translation.SetAsWallpaper.Value,

+ 2 - 42
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -7,13 +7,10 @@ using PicView.Avalonia.Clipboard;
 using PicView.Avalonia.Converters;
 using PicView.Avalonia.FileSystem;
 using PicView.Avalonia.Functions;
-using PicView.Avalonia.Gallery;
 using PicView.Avalonia.ImageTransformations.Rotation;
 using PicView.Avalonia.Interfaces;
-using PicView.Avalonia.LockScreen;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.UI;
-using PicView.Avalonia.Wallpaper;
 using PicView.Avalonia.WindowBehavior;
 using PicView.Core.FileSorting;
 using PicView.Core.ProcessHandling;
@@ -30,12 +27,13 @@ public class MainViewModel : ReactiveObject
     public readonly IPlatformWindowService? PlatformWindowService;
     
     public TranslationViewModel Translation { get; } = new();
-    public GlobalSettingsViewModel? GLobalSettings { get; } = new();
+    public ToolsViewModel? GLobalSettings { get; } = new();
     public SettingsViewModel? SettingsViewModel { get; set; }
     public ImageCropperViewModel? Crop { get; set; }
     public NavigationViewModel Navigation { get; } = new();
     public PicViewerModel PicViewer { get; } = new();
     public GalleryViewModel? Gallery { get; } = new();
+    public ToolsViewModel? Tools { get; } = new();
     public ExifViewModel? Exif { get; set;  }
     
     public FileAssociationsViewModel? AssociationsViewModel { get; set; }
@@ -177,12 +175,6 @@ public class MainViewModel : ReactiveObject
 
         LocateOnDiskCommand = FunctionsHelper.CreateReactiveCommand<string>(LocateOnDiskTask);
 
-        SetAsWallpaperCommand = FunctionsHelper.CreateReactiveCommand<string>(SetAsWallpaperTask);
-        SetAsWallpaperTiledCommand = FunctionsHelper.CreateReactiveCommand<string>(SetAsWallpaperTiledTask);
-        SetAsWallpaperStretchedCommand = FunctionsHelper.CreateReactiveCommand<string>(SetAsWallpaperStretchedTask);
-        SetAsWallpaperCenteredCommand = FunctionsHelper.CreateReactiveCommand<string>(SetAsWallpaperCenteredTask);
-        SetAsWallpaperFilledCommand = FunctionsHelper.CreateReactiveCommand<string>(SetAsWallpaperFilledTask);
-
         #endregion File commands
 
         #region UI Commands
@@ -324,12 +316,6 @@ public class MainViewModel : ReactiveObject
 
     public ReactiveCommand<int, Unit>? SlideshowCommand { get; }
 
-    public ReactiveCommand<string, Unit>? SetAsWallpaperCommand { get; }
-    public ReactiveCommand<string, Unit>? SetAsWallpaperFilledCommand { get; }
-    public ReactiveCommand<string, Unit>? SetAsWallpaperStretchedCommand { get; }
-    public ReactiveCommand<string, Unit>? SetAsWallpaperTiledCommand { get; }
-    public ReactiveCommand<string, Unit>? SetAsWallpaperCenteredCommand { get; }
-
     public ReactiveCommand<Unit, Unit>? ResetSettingsCommand { get; }
 
     public ReactiveCommand<Unit, Unit>? ShowSideBySideCommand { get; }
@@ -783,32 +769,6 @@ public class MainViewModel : ReactiveObject
     private async Task LocateOnDiskTask(string path) =>
         await FileManager.LocateOnDisk(path, this).ConfigureAwait(false);
 
-    private async Task SetAsWallpaperTask(string path) =>
-        await SetAsWallpaperTask(path, WallpaperStyle.Fill).ConfigureAwait(false);
-
-    private async Task SetAsWallpaperFilledTask(string path) =>
-        await SetAsWallpaperTask(path, WallpaperStyle.Fill).ConfigureAwait(false);
-    
-    private async Task SetAsWallpaperFittedTask(string path) =>
-        await SetAsWallpaperTask(path, WallpaperStyle.Fit).ConfigureAwait(false);
-
-    private async Task SetAsWallpaperTiledTask(string path) =>
-        await SetAsWallpaperTask(path, WallpaperStyle.Tile).ConfigureAwait(false);
-
-    private async Task SetAsWallpaperStretchedTask(string path) =>
-        await SetAsWallpaperTask(path, WallpaperStyle.Stretch).ConfigureAwait(false);
-
-    private async Task SetAsWallpaperCenteredTask(string path) =>
-        await SetAsWallpaperTask(path, WallpaperStyle.Center).ConfigureAwait(false);
-
-    private async Task SetAsWallpaperTask(string path, WallpaperStyle style) =>
-        await WallpaperManager.SetAsWallpaper(path, style, this).ConfigureAwait(false);
-
-    private async Task SetAsLockScreenTask(string path) =>
-        await LockScreenHelper.SetAsLockScreenTask(path, this).ConfigureAwait(false);
-
-    private void SetGalleryItemStretch(string value) => GalleryHelper.SetGalleryItemStretch(value, this);
-
     public async Task StartSlideShowTask(int milliseconds) =>
         await Slideshow.StartSlideshow(this, milliseconds);
 

+ 1 - 0
src/PicView.Avalonia/ViewModels/NavigationViewModel.cs

@@ -4,6 +4,7 @@ using R3;
 
 namespace PicView.Avalonia.ViewModels;
 
+// TODO: Move this to Core by using interfaces
 public class NavigationViewModel : IDisposable
 {
     // Reload

+ 149 - 0
src/PicView.Avalonia/ViewModels/ToolsViewModel.cs

@@ -0,0 +1,149 @@
+using PicView.Avalonia.UI;
+using PicView.Avalonia.Wallpaper;
+using R3;
+
+namespace PicView.Avalonia.ViewModels;
+
+public class ToolsViewModel : IDisposable
+{
+    
+    // Open related
+    public ReactiveCommand<string> OpenFileCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand OpenLastFileCommand { get; } = new(async (_, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> OpenWithCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    // Save related
+    public ReactiveCommand<string> SaveFileCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> SaveFileAsCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    // File Tasks
+    public ReactiveCommand<string> RecycleFileCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> LocateOnDiskCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> FilePropertiesCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> PrintCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> RenameCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> ResizeCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> ConvertCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+
+    
+    // Copy related
+    public ReactiveCommand<string> PasteCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> DuplicateFileCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> CopyImageCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> CopyFileCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> CopyFilePathCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> CutCommand { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    public ReactiveCommand<string> CopyBase64Command { get; } = new(async (path, _) =>
+    {
+        await Task.Delay(1); // TODO implement
+    });
+    
+    // Wallpaper
+    public ReactiveCommand<string> SetAsWallpaperCommand { get; } = new(async (path, _) =>
+    {
+        await WallpaperManager.SetAsWallpaper(path, WallpaperStyle.Fill, UIHelper.GetMainView.DataContext as MainViewModel).ConfigureAwait(false);
+    });
+    
+    public ReactiveCommand<string> SetAsWallpaperTiledCommand { get; } = new(async (path, _) =>
+    {
+        await WallpaperManager.SetAsWallpaper(path, WallpaperStyle.Tile, UIHelper.GetMainView.DataContext as MainViewModel).ConfigureAwait(false);
+    });
+    
+    public ReactiveCommand<string> SetAsWallpaperStretchedCommand { get; } = new(async (path, _) =>
+    {
+        await WallpaperManager.SetAsWallpaper(path, WallpaperStyle.Stretch, UIHelper.GetMainView.DataContext as MainViewModel).ConfigureAwait(false);
+    });
+    
+    public ReactiveCommand<string> SetAsWallpaperCenteredCommand { get; } = new(async (path, _) =>
+    {
+        await WallpaperManager.SetAsWallpaper(path, WallpaperStyle.Center, UIHelper.GetMainView.DataContext as MainViewModel).ConfigureAwait(false);
+    });
+    
+    public ReactiveCommand<string> SetAsWallpaperFilledCommand { get; } = new(async (path, _) =>
+    {
+        await WallpaperManager.SetAsWallpaper(path, WallpaperStyle.Fill, UIHelper.GetMainView.DataContext as MainViewModel).ConfigureAwait(false);
+    });
+    
+    public ReactiveCommand<string> SetAsWallpaperFittedCommand { get; } = new(async (path, _) =>
+    {
+        await WallpaperManager.SetAsWallpaper(path, WallpaperStyle.Fit, UIHelper.GetMainView.DataContext as MainViewModel).ConfigureAwait(false);
+    });
+    
+    public void Dispose()
+    {
+        Disposable.Dispose(SetAsWallpaperCommand,
+            SetAsWallpaperFilledCommand,
+            SetAsWallpaperStretchedCommand,
+            SetAsWallpaperCenteredCommand,
+            SetAsWallpaperFilledCommand,
+            SetAsWallpaperFittedCommand);
+    }
+}

+ 1 - 1
src/PicView.Avalonia/Views/EffectsView.axaml

@@ -49,7 +49,7 @@
             </MenuItem>
             <Separator />
             <MenuItem
-                Command="{CompiledBinding SetAsWallpaperFilledCommand}"
+                Command="{CompiledBinding Tools.SetAsWallpaperFilledCommand}"
                 CommandParameter="{CompiledBinding PicViewer.FileInfo.CurrentValue.FullName,
                                                    FallbackValue=''}"
                 Header="{CompiledBinding Translation.SetAsWallpaper.Value,

+ 5 - 5
src/PicView.Avalonia/Views/ImageInfoView.axaml

@@ -138,7 +138,7 @@
 
                 <!--  Set as wallpaper filled  -->
                 <MenuItem
-                    Command="{CompiledBinding SetAsWallpaperFilledCommand}"
+                    Command="{CompiledBinding Tools.SetAsWallpaperFilledCommand}"
                     CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                        FallbackValue=''}"
                     Header="{CompiledBinding Translation.Fill.Value,
@@ -157,7 +157,7 @@
 
                 <!--  Set as wallpaper fit  -->
                 <MenuItem
-                    Command="{CompiledBinding SetAsWallpaperFittedTask}"
+                    Command="{CompiledBinding Tools.SetAsWallpaperFittedCommand}"
                     CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                        FallbackValue=''}"
                     Header="{CompiledBinding Translation.Fit.Value,
@@ -176,7 +176,7 @@
 
                 <!--  Set as wallpaper stretched  -->
                 <MenuItem
-                    Command="{CompiledBinding SetAsWallpaperStretchedCommand}"
+                    Command="{CompiledBinding Tools.SetAsWallpaperStretchedCommand}"
                     CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                        FallbackValue=''}"
                     Header="{CompiledBinding Translation.Stretch.Value,
@@ -197,7 +197,7 @@
 
                 <!--  Set as wallpaper centered  -->
                 <MenuItem
-                    Command="{CompiledBinding SetAsWallpaperCenteredCommand}"
+                    Command="{CompiledBinding Tools.SetAsWallpaperCenteredCommand}"
                     CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                        FallbackValue=''}"
                     Header="{CompiledBinding Translation.Center.Value,
@@ -216,7 +216,7 @@
 
                 <!--  Set as wallpaper tiled  -->
                 <MenuItem
-                    Command="{CompiledBinding SetAsWallpaperTiledCommand}"
+                    Command="{CompiledBinding Tools.SetAsWallpaperTiledCommand}"
                     CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                        FallbackValue=''}"
                     Header="{CompiledBinding Translation.Tile.Value,

+ 1 - 1
src/PicView.Avalonia/Views/MainView.axaml

@@ -684,7 +684,7 @@
 
             <!--  Set as wallpaper  -->
             <MenuItem
-                Command="{CompiledBinding SetAsWallpaperCommand}"
+                Command="{CompiledBinding Tools.SetAsWallpaperCommand}"
                 CommandParameter="{CompiledBinding PicViewer.FileInfo.Value.FullName,
                                                    FallbackValue=''}"
                 Header="{CompiledBinding Translation.SetAsWallpaper.Value,

+ 1 - 1
src/PicView.Avalonia/Views/UC/GalleryItem.axaml

@@ -105,7 +105,7 @@
                 </MenuItem>
                 <Separator />
                 <MenuItem
-                    Command="{CompiledBinding SetAsWallpaperCommand}"
+                    Command="{CompiledBinding Tools.SetAsWallpaperCommand}"
                     CommandParameter="{CompiledBinding Path=Text,
                                                        ElementName=FileLocation}"
                     Header="{CompiledBinding Translation.SetAsWallpaper.Value,