Browse Source

Add maximize to contextmenu, change restore logic

Ruben 8 months ago
parent
commit
53f32108c2

File diff suppressed because it is too large
+ 3 - 0
src/PicView.Avalonia/PicViewTheme/Icons.axaml


+ 22 - 0
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -359,6 +359,7 @@ public class MainViewModel : ViewModelBase
     public ReactiveCommand<Unit, Unit>? MinimizeCommand { get; }
     public ReactiveCommand<Unit, Unit>? MaximizeCommand { get; }
     
+    public ReactiveCommand<Unit, Unit>? RestoreCommand { get; }
     public ReactiveCommand<Unit, Unit>? ToggleFullscreenCommand { get; }
     public ReactiveCommand<Unit, Unit>? NextCommand { get; }
     public ReactiveCommand<Unit, Unit>? NextButtonCommand { get; }
@@ -535,6 +536,26 @@ public class MainViewModel : ViewModelBase
     }
 
     public bool IsFullscreen
+    {
+        get;
+        set
+        {
+            this.RaiseAndSetIfChanged(ref field, value);
+            ShouldRestore = IsFullscreen || IsMaximized;
+        }
+    }
+    
+    public bool IsMaximized
+    {
+        get;
+        set
+        {
+            this.RaiseAndSetIfChanged(ref field, value);
+            ShouldRestore = IsFullscreen || IsMaximized;
+        }
+    }
+    
+    public bool ShouldRestore
     {
         get;
         set => this.RaiseAndSetIfChanged(ref field, value);
@@ -1585,6 +1606,7 @@ public class MainViewModel : ViewModelBase
         ExitCommand = ReactiveCommand.CreateFromTask(WindowFunctions.Close);
         MinimizeCommand = ReactiveCommand.CreateFromTask(WindowFunctions.Minimize);
         MaximizeCommand = ReactiveCommand.CreateFromTask(WindowFunctions.MaximizeRestore);
+        RestoreCommand = ReactiveCommand.Create(WindowFunctions.Restore);
         ToggleFullscreenCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleFullscreen);
         NewWindowCommand = ReactiveCommand.Create(ProcessHelper.StartNewProcess);
 

+ 21 - 2
src/PicView.Avalonia/Views/MainView.axaml

@@ -982,11 +982,30 @@
                         Width="12" />
                 </MenuItem.Icon>
             </MenuItem>
+
+            <!--  Maximize  -->
             <MenuItem
-                Command="{CompiledBinding ToggleFullscreenCommand}"
+                Command="{CompiledBinding MaximizeCommand}"
+                Header="{CompiledBinding Maximize,
+                                         Mode=OneWay}"
+                IsVisible="{CompiledBinding !IsMaximized,
+                                            Mode=OneWay}"
+                x:Name="MaximizeMenuItem">
+                <MenuItem.Icon>
+                    <Image
+                        Height="12"
+                        Source="{StaticResource SquareImage}"
+                        Stretch="Fill"
+                        Width="12" />
+                </MenuItem.Icon>
+            </MenuItem>
+
+            <!--  Restore  -->
+            <MenuItem
+                Command="{CompiledBinding RestoreCommand}"
                 Header="{CompiledBinding RestoreDown,
                                          Mode=OneWay}"
-                IsVisible="{CompiledBinding IsFullscreen,
+                IsVisible="{CompiledBinding ShouldRestore,
                                             Mode=OneWay}">
                 <MenuItem.Icon>
                     <Path

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

@@ -37,6 +37,8 @@ public partial class MainView : UserControl
             {
                 // TODO Implement setting as wallpaper for macOS
                 WallpaperMenuItem.IsEnabled = false;
+                
+                MaximizeMenuItem.IsVisible = false;
             }
             
             if (DataContext is not MainViewModel vm)

+ 15 - 0
src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs

@@ -252,6 +252,16 @@ public static class WindowFunctions
         await SaveSettingsAsync().ConfigureAwait(false);
     }
 
+    public static void Restore()
+    {
+        if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || desktop.MainWindow.DataContext is not MainViewModel vm)
+        {
+            return;
+        }
+
+        Restore(vm, desktop);
+    }
+
     public static void Restore(MainViewModel vm, IClassicDesktopStyleApplicationLifetime desktop)
     {
         if (Settings.UIProperties.ShowInterface)
@@ -286,6 +296,8 @@ public static class WindowFunctions
             vm.CanResize = true;
         }
         SetMargin();
+        vm.IsMaximized = false;
+        vm.IsFullscreen = false;
     }
 
     public static void Maximize()
@@ -321,6 +333,8 @@ public static class WindowFunctions
             Settings.WindowProperties.Maximized = true;
             WindowResizing.SetSize(desktop.MainWindow.DataContext as MainViewModel);
             SetMargin();
+            vm.IsMaximized = true;
+            vm.IsFullscreen = false;
         }
     }
     
@@ -360,6 +374,7 @@ public static class WindowFunctions
     {
         vm.SizeToContent = SizeToContent.Manual;
         vm.IsFullscreen = true;
+        vm.IsMaximized = false;
         vm.CanResize = false;
         if (Dispatcher.UIThread.CheckAccess())
         {

Some files were not shown because too many files changed in this diff