1
1
Эх сурвалжийг харах

Add navigation arrows to go back and forward in tab navigation history for the settings window.

Ruben 7 сар өмнө
parent
commit
9712248283

+ 1 - 0
src/PicView.Avalonia.MacOS/App.axaml.cs

@@ -275,6 +275,7 @@ public class App : Application, IPlatformSpecificService
             if (_settingsWindow is null)
             {
                 _vm.AssociationsViewModel ??= new FileAssociationsViewModel();
+                _vm.SettingsViewModel ??= new SettingsViewModel();
                 _settingsWindow = new SettingsWindow
                 {
                     DataContext = _vm,

+ 1 - 0
src/PicView.Avalonia.Win32/App.axaml.cs

@@ -315,6 +315,7 @@ public partial class App : Application, IPlatformSpecificService
             if (_settingsWindow is null)
             {
                 _vm.AssociationsViewModel ??= new FileAssociationsViewModel();
+                _vm.SettingsViewModel ??= new SettingsViewModel();
                 _settingsWindow = new SettingsWindow
                 {
                     DataContext = _vm,

+ 32 - 1
src/PicView.Avalonia.Win32/Views/SettingsWindow.axaml

@@ -37,6 +37,34 @@
                             Width="20" />
                     </Border>
 
+                    <Border Background="{StaticResource WindowSecondaryBackgroundColor}" DockPanel.Dock="Left">
+                        <customControls:IconButton
+                            Background="{StaticResource WindowSecondaryBackgroundColor}"
+                            Classes="noBorderHover"
+                            Command="{CompiledBinding SettingsViewModel.GoBackCommand}"
+                            Data="{StaticResource ArrowLeftGeometry}"
+                            Foreground="{StaticResource SecondaryTextColor}"
+                            IconHeight="12"
+                            IconWidth="12"
+                            Padding="8,0" />
+                    </Border>
+
+                    <Border
+                        Background="{StaticResource WindowSecondaryBackgroundColor}"
+                        BorderBrush="{DynamicResource MainBorderColor}"
+                        BorderThickness="0,0,1,0"
+                        DockPanel.Dock="Left">
+                        <customControls:IconButton
+                            Background="{StaticResource WindowSecondaryBackgroundColor}"
+                            Classes="noBorderHover"
+                            Command="{CompiledBinding SettingsViewModel.GoForwardCommand}"
+                            Data="{StaticResource ArrowRightGeometry}"
+                            Foreground="{StaticResource SecondaryTextColor}"
+                            IconHeight="12"
+                            IconWidth="12"
+                            Padding="8,0" />
+                    </Border>
+
                     <customControls:IconButton
                         Background="{DynamicResource WindowButtonBackgroundColor}"
                         Classes="hover"
@@ -82,7 +110,10 @@
                 </DockPanel>
             </Border>
 
-            <views:SettingsView Background="{DynamicResource NoisyTexture}" Margin="0,28,0,0" />
+            <views:SettingsView
+                Background="{DynamicResource NoisyTexture}"
+                Margin="0,28,0,0"
+                x:Name="SettingsView" />
 
         </Panel>
     </Border>

+ 2 - 0
src/PicView.Avalonia/PicViewTheme/Icons.axaml

@@ -19,6 +19,8 @@
     <StreamGeometry x:Key="ShowInFolderGeometry">M1 5C1 3.34315 2.34315 2 4 2H8.43845C9.81505 2 11.015 2.93689 11.3489 4.27239L11.7808 6H13.5H20C21.6569 6 23 7.34315 23 9V11C23 11.5523 22.5523 12 22 12C21.4477 12 21 11.5523 21 11V9C21 8.44772 20.5523 8 20 8H13.5H11.7808H4C3.44772 8 3 8.44772 3 9V10V19C3 19.5523 3.44772 20 4 20H9C9.55228 20 10 20.4477 10 21C10 21.5523 9.55228 22 9 22H4C2.34315 22 1 20.6569 1 19V10V9V5ZM3 6.17071C3.31278 6.06015 3.64936 6 4 6H9.71922L9.40859 4.75746C9.2973 4.3123 8.89732 4 8.43845 4H4C3.44772 4 3 4.44772 3 5V6.17071ZM20.1716 18.7574C20.6951 17.967 21 17.0191 21 16C21 13.2386 18.7614 11 16 11C13.2386 11 11 13.2386 11 16C11 18.7614 13.2386 21 16 21C17.0191 21 17.967 20.6951 18.7574 20.1716L21.2929 22.7071C21.6834 23.0976 22.3166 23.0976 22.7071 22.7071C23.0976 22.3166 23.0976 21.6834 22.7071 21.2929L20.1716 18.7574ZM13 16C13 14.3431 14.3431 13 16 13C17.6569 13 19 14.3431 19 16C19 17.6569 17.6569 19 16 19C14.3431 19 13 17.6569 13 16Z</StreamGeometry>
     <StreamGeometry x:Key="CutGeometry">M9.77 11.5l5.34 3.91c.44.33 1.24.59 1.79.59H20L6.89 6.38A3.5 3.5 0 1 0 5.5 8.37L7.73 10 5.5 11.63a3.5 3.5 0 1 0 1.38 1.99l2.9-2.12zM3.5 7a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm0 9a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zM15.1 4.59A3.53 3.53 0 0 1 16.9 4H20l-7.5 5.5L10.45 8l4.65-3.41z</StreamGeometry>
     <StreamGeometry x:Key="RecycleGeometry">M836 1169l-15 368-2 22-420-29q-36-3-67-31.5t-47-65.5q-11-27-14.5-55t4-65 12-55 21.5-64 19-53q78 12 509 28zm-387-586l180 379-147-92q-63 72-111.5 144.5t-72.5 125-39.5 94.5-18.5 63l-4 21-190-357q-17-26-18-56t6-47l8-18q35-63 114-188l-140-86zm1231 517l-188 359q-12 29-36.5 46.5t-43.5 20.5l-18 4q-71 7-219 12l8 164-230-367 211-362 7 173q170 16 283 5t170-33zm-785-924q-47 63-265 435l-317-187-19-12 225-356q20-31 60-42t80-10q24 2 48.5 12t42 21 41.5 33 36 34.5 36 39.5 32 35zm655 307l212 363q18 37 12.5 76t-27.5 74q-13 20-33 37t-38 28-48.5 22-47 16-51.5 14-46 12q-34-72-265-436l313-195zm-143-226l142-83-220 373-419-20 151-86q-34-89-75-166t-75.5-123.5-64.5-80-47-46.5l-17-13 405 1q31-3 58 10.5t39 28.5l11 15q39 61 112 190z</StreamGeometry>
+    <StreamGeometry x:Key="ArrowLeftGeometry">m313-440 224 224-57 56-320-320 320-320 57 56-224 224h487v80H313Z</StreamGeometry>
+    <StreamGeometry x:Key="ArrowRightGeometry">M647-440H160v-80h487L423-744l57-56 320 320-320 320-57-56 224-224Z</StreamGeometry>
     <StreamGeometry x:Key="FilledArrowLeftGeometry">F1M27.008,0L27.01,31.062 0,15.529z</StreamGeometry>
     <StreamGeometry x:Key="FilledArrowRightGeometry">F1M0.002,31.062L0,0 27.01,15.534z</StreamGeometry>
     <StreamGeometry x:Key="ChevronUpGeometry">M112 328l144-144 144 144</StreamGeometry>

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

@@ -28,10 +28,10 @@ namespace PicView.Avalonia.ViewModels;
 public class MainViewModel : ReactiveObject
 {
     public readonly IPlatformSpecificService? PlatformService;
-    public ImageCropperViewModel? Crop { get; set; }
     
     public TranslationViewModel Translation { get; } = new();
-    
+    public SettingsViewModel? SettingsViewModel { get; set; }
+    public ImageCropperViewModel? Crop { get; set; }
     public PicViewerModel PicViewer { get; } = new();
     
     public ExifViewModel Exif { get; } = new();

+ 2 - 1
src/PicView.Avalonia/Views/SettingsView.axaml

@@ -907,7 +907,8 @@
                     <views:FileAssociationsView
                         Background="Transparent"
                         Margin="{StaticResource TabMargin}"
-                        Padding="45,0,0,0" />
+                        Padding="45,0,0,0"
+                        x:Name="FileAssociationsView" />
                 </customControls:AutoScrollViewer>
             </TabItem>
         </TabControl>

+ 33 - 0
src/PicView.Avalonia/Views/SettingsView.axaml.cs

@@ -3,6 +3,8 @@ using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Input;
 using Avalonia.Media;
+using PicView.Avalonia.ViewModels;
+using ReactiveUI;
 
 namespace PicView.Avalonia.Views;
 
@@ -25,6 +27,21 @@ public partial class SettingsView : UserControl
             MainTabControl.MinHeight = MainTabControl.Bounds.Height;
             MainTabControl.SelectionChanged += TabSelectionChanged;
             PointerPressed += OnMouseButtonDown;
+
+            if (DataContext is not MainViewModel vm)
+            {
+                return;
+            }
+            
+            vm.SettingsViewModel.GoBackCommand = ReactiveCommand.Create(
+                GoBack, 
+                vm.SettingsViewModel.WhenAnyValue(x => x.IsBackButtonEnabled)
+            );
+            
+            vm.SettingsViewModel.GoForwardCommand = ReactiveCommand.Create(
+                GoForward, 
+                vm.SettingsViewModel.WhenAnyValue(x => x.IsForwardButtonEnabled)
+            );
         };
     }
 
@@ -53,10 +70,13 @@ public partial class SettingsView : UserControl
         if (_currentTab != null)
         {
             _backStack.Push(_currentTab);
+            // Clear forward stack when a new tab is selected directly
+            _forwardStack.Clear();
         }
     
         _currentTab = selectedTab;
         SelectTab(_currentTab);
+        UpdateNavigationButtons();
     }
     
     public void GoBack()
@@ -69,6 +89,7 @@ public partial class SettingsView : UserControl
         _forwardStack.Push(_currentTab);
         _currentTab = _backStack.Pop();
         SelectTab(_currentTab);
+        UpdateNavigationButtons();
     }
 
     public void GoForward()
@@ -81,6 +102,18 @@ public partial class SettingsView : UserControl
         _backStack.Push(_currentTab);
         _currentTab = _forwardStack.Pop();
         SelectTab(_currentTab);
+        UpdateNavigationButtons();
+    }
+
+    private void UpdateNavigationButtons()
+    {
+        if (DataContext is not MainViewModel vm)
+        {
+            return;
+        }
+        
+        vm.SettingsViewModel.IsBackButtonEnabled = _backStack.Count > 0;
+        vm.SettingsViewModel.IsForwardButtonEnabled = _forwardStack.Count > 0;
     }
 
     private void SelectTab(TabItem? tab)

+ 31 - 0
src/PicView.Core/ViewModels/SettingsViewModel.cs

@@ -0,0 +1,31 @@
+using System.Reactive;
+using ReactiveUI;
+
+namespace PicView.Core.ViewModels;
+
+
+public class SettingsViewModel : ReactiveObject
+{
+    public bool IsBackButtonEnabled
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+
+    public bool IsForwardButtonEnabled
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+    public ReactiveCommand<Unit, Unit>? GoForwardCommand
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+
+    public ReactiveCommand<Unit, Unit>? GoBackCommand
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+}