Browse Source

Refactor/rename

Ruben 7 months ago
parent
commit
a60d986d9f

+ 4 - 4
src/PicView.Avalonia/Converters/ConversionHelper.cs

@@ -9,7 +9,7 @@ namespace PicView.Avalonia.Converters;
 
 internal static class ConversionHelper
 {
-    internal static async Task<bool> ResizeImageByPercentage(FileInfo fileInfo, int selectedIndex)
+    public static async Task<bool> ResizeImageByPercentage(FileInfo fileInfo, int selectedIndex)
     {
         var percentage = 100 - selectedIndex * 5;
 
@@ -36,7 +36,7 @@ internal static class ConversionHelper
         }
     }
 
-    internal static async Task<bool> ResizeByWidth(FileInfo fileInfo, double width)
+    public static async Task<bool> ResizeByWidth(FileInfo fileInfo, double width)
     {
         if (width <= 0)
         {
@@ -46,7 +46,7 @@ internal static class ConversionHelper
         return await SaveImageFileHelper.ResizeImageAsync(fileInfo, (uint)width, 0).ConfigureAwait(false);
     }
 
-    internal static async Task<bool> ResizeByHeight(FileInfo fileInfo, double height)
+    public static async Task<bool> ResizeByHeight(FileInfo fileInfo, double height)
     {
         if (height <= 0)
         {
@@ -56,7 +56,7 @@ internal static class ConversionHelper
         return await SaveImageFileHelper.ResizeImageAsync(fileInfo, 0, (uint)height).ConfigureAwait(false);
     }
 
-    internal static async Task<string> ConvertTask(FileInfo fileInfo, int selectedIndex)
+    public static async Task<string> ConvertTask(FileInfo fileInfo, int selectedIndex)
     {
         var currentExtension = fileInfo.Extension.ToLower();
         var newExtension = selectedIndex switch

+ 2 - 2
src/PicView.Avalonia/Gallery/GalleryFunctions.cs

@@ -283,7 +283,7 @@ public static class GalleryFunctions
             return;
         }
 
-        UIHelper.CloseMenus(vm);
+        MenuManager.CloseMenus(vm);
         if (Settings.Gallery.IsBottomGalleryShown)
         {
             // Showing bottom gallery is enabled
@@ -332,7 +332,7 @@ public static class GalleryFunctions
             return;
         }
 
-        UIHelper.CloseMenus(vm);
+        MenuManager.CloseMenus(vm);
 
         if (Settings.Gallery.IsBottomGalleryShown)
         {

+ 80 - 0
src/PicView.Avalonia/ImageTransformations/Rotation.cs

@@ -5,6 +5,8 @@ using PicView.Avalonia.Gallery;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Views.UC.Menus;
+using PicView.Avalonia.WindowBehavior;
+using PicView.Core.Gallery;
 
 namespace PicView.Avalonia.ImageTransformations;
 public static class Rotation
@@ -130,4 +132,82 @@ public static class Rotation
 
         Dispatcher.UIThread.Invoke(() => { vm.ImageViewer.Flip(true); });
     }
+    
+    /// <summary>
+    /// Navigates up or rotates the image based on current state
+    /// </summary>
+    public static async Task NavigateUp(MainViewModel? vm)
+    {
+        if (vm is null)
+        {
+            return;
+        }
+
+        if (GalleryFunctions.IsFullGalleryOpen)
+        {
+            GalleryNavigation.NavigateGallery(Direction.Up, vm);
+            return;
+        }
+
+        await Dispatcher.UIThread.InvokeAsync(() => 
+        {
+            if (vm.IsScrollingEnabled)
+            {
+                vm.ImageViewer.ImageScrollViewer.LineUp();
+            }
+            else
+            {
+                vm.ImageViewer.Rotate(true);
+            }
+        });
+    }
+
+    /// <summary>
+    /// Navigates down or rotates the image based on current state
+    /// </summary>
+    public static async Task NavigateDown(MainViewModel? vm)
+    {
+        if (vm is null)
+        {
+            return;
+        }
+
+        if (GalleryFunctions.IsFullGalleryOpen)
+        {
+            GalleryNavigation.NavigateGallery(Direction.Down, vm);
+            return;
+        }
+
+        await Dispatcher.UIThread.InvokeAsync(() => 
+        {
+            if (vm.IsScrollingEnabled)
+            {
+                vm.ImageViewer.ImageScrollViewer.LineDown();
+            }
+            else
+            {
+                vm.ImageViewer.Rotate(false);
+            }
+        });
+    }
+
+    /// <summary>
+    /// Centers the window or gallery based on current state
+    /// </summary>
+    public static void Center(MainViewModel? vm)
+    {
+        if (vm is null)
+        {
+            return;
+        }
+        
+        if (GalleryFunctions.IsFullGalleryOpen)
+        {
+            GalleryFunctions.CenterGallery(vm);
+        }
+        else
+        {
+            WindowFunctions.CenterWindowOnScreen();
+        }
+    }
 }

+ 0 - 3
src/PicView.Avalonia/Input/MainKeyboardShortcuts.cs

@@ -68,9 +68,6 @@ public static class MainKeyboardShortcuts
             case Key.F12:
                 // Show Avalonia DevTools in DEBUG mode
                 return;
-            case Key.F7:
-                await FunctionsHelper.Invalidate();
-                return;
             case Key.F9:
                 await FunctionsHelper.ShowStartUpMenu();
                 return;

+ 1 - 1
src/PicView.Avalonia/Navigation/ErrorHandling.cs

@@ -51,7 +51,7 @@ public static class ErrorHandling
 
             vm.GalleryMode = GalleryMode.Closed;
             GalleryFunctions.Clear();
-            UIHelper.CloseMenus(vm);
+            MenuManager.CloseMenus(vm);
             vm.GalleryMargin = new Thickness(0, 0, 0, 0);
             vm.GetIndex = 0;
             vm.PlatformService.StopTaskbarProgress();

+ 1 - 1
src/PicView.Avalonia/Navigation/NavigationManager.cs

@@ -338,7 +338,7 @@ public static class NavigationManager
             return;
         }
 
-        UIHelper.CloseMenus(vm);
+        MenuManager.CloseMenus(vm);
         vm.IsLoading = true;
         SetTitleHelper.SetLoadingTitle(vm);
 

+ 1 - 1
src/PicView.Avalonia/Navigation/Slideshow.cs

@@ -110,7 +110,7 @@ public static class Slideshow
         _timer.Start();
         vm.PlatformService.DisableScreensaver();
 
-        UIHelper.CloseMenus(vm);
+        MenuManager.CloseMenus(vm);
 
         if (!Settings.WindowProperties.Fullscreen)
         {

+ 1 - 1
src/PicView.Avalonia/StartUp/StartUpHelper.cs

@@ -116,7 +116,7 @@ public static class StartUpHelper
         HandleWindowControlSettings(vm, desktop);
         ValidateGallerySettings(vm, settingsExists);
         SetWindowEventHandlers(window);
-        UIHelper.AddMenus();
+        MenuManager.AddMenus();
 
         Application.Current.Name = "PicView";
 

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

@@ -159,7 +159,7 @@ public static class FunctionsHelper
         {
             return Task.CompletedTask;
         }
-        UIHelper.CloseMenus(Vm);
+        MenuManager.CloseMenus(Vm);
         return Task.CompletedTask;
     }
 
@@ -169,7 +169,7 @@ public static class FunctionsHelper
         {
             return Task.CompletedTask;
         }
-        UIHelper.ToggleFileMenu(Vm);
+        MenuManager.ToggleFileMenu(Vm);
         return Task.CompletedTask;
     }
 
@@ -179,7 +179,7 @@ public static class FunctionsHelper
         {
             return Task.CompletedTask;
         }
-        UIHelper.ToggleImageMenu(Vm);
+        MenuManager.ToggleImageMenu(Vm);
         return Task.CompletedTask;
     }
 
@@ -189,7 +189,7 @@ public static class FunctionsHelper
         {
             return Task.CompletedTask;
         }
-        UIHelper.ToggleSettingsMenu(Vm);
+        MenuManager.ToggleSettingsMenu(Vm);
         return Task.CompletedTask;
     }
 
@@ -199,7 +199,7 @@ public static class FunctionsHelper
         {
             return Task.CompletedTask;
         }
-        UIHelper.ToggleToolsMenu(Vm);
+        MenuManager.ToggleToolsMenu(Vm);
         return Task.CompletedTask;
     }
 
@@ -260,7 +260,7 @@ public static class FunctionsHelper
 
     public static async Task Up()
     {
-        await UIHelper.NavigateUp(Vm);
+        await Rotation.NavigateUp(Vm);
     }
 
     public static async Task RotateRight()
@@ -275,7 +275,7 @@ public static class FunctionsHelper
 
     public static async Task Down()
     {
-        await UIHelper.NavigateDown(Vm);
+        await Rotation.NavigateDown(Vm);
     }
     
     public static async Task ScrollDown()
@@ -432,7 +432,7 @@ public static class FunctionsHelper
     {
         await Dispatcher.UIThread.InvokeAsync(() =>
         {
-            UIHelper.Center(Vm);
+            Rotation.Center(Vm);
         });
     }
     
@@ -1081,12 +1081,4 @@ public static class FunctionsHelper
     #endregion
     
     #endregion
-
-    #if DEBUG
-    public static async Task Invalidate()
-    {
-        Vm?.ImageViewer?.MainImage?.InvalidateVisual();
-        //Vm?.ImageViewer?.InvalidateVisual();
-    }
-    #endif
 }

+ 1 - 1
src/PicView.Avalonia/UI/HideInterfaceLogic.cs

@@ -86,7 +86,7 @@ public static class HideInterfaceLogic
         }
         
         WindowResizing.SetSize(vm);
-        UIHelper.CloseMenus(vm);
+        MenuManager.CloseMenus(vm);
         await SaveSettingsAsync();
     }
     

+ 140 - 0
src/PicView.Avalonia/UI/MenuManager.cs

@@ -0,0 +1,140 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Layout;
+using PicView.Avalonia.ViewModels;
+using PicView.Avalonia.Views.UC.Menus;
+
+namespace PicView.Avalonia.UI;
+
+public static class MenuManager
+{
+    /// <summary>
+    /// Adds menu controls to the main view
+    /// </summary>
+    public static void AddMenus()
+    {
+        var mainView = UIHelper.GetMainView;
+        if (mainView?.MainGrid == null)
+        {
+            return;
+        }
+
+        mainView.MainGrid.Children.Add(CreateMenu<FileMenu>(new Thickness(0, 0, 120, 0)));
+        mainView.MainGrid.Children.Add(CreateMenu<ImageMenu>(new Thickness(0, 0, 63, 0)));
+        mainView.MainGrid.Children.Add(CreateMenu<SettingsMenu>(new Thickness(0, 0, -75, 0)));
+        mainView.MainGrid.Children.Add(CreateMenu<ToolsMenu>(new Thickness(80, 0, 0, 0)));
+    }
+
+    private static T CreateMenu<T>(Thickness margin) where T : Control, new()
+    {
+        return new T
+        {
+            VerticalAlignment = VerticalAlignment.Bottom,
+            HorizontalAlignment = HorizontalAlignment.Center,
+            Margin = margin,
+            IsVisible = false
+        };
+    }
+    
+    /// <summary>
+    /// Closes all menus
+    /// </summary>
+    public static void CloseMenus(MainViewModel vm)
+    {
+        vm.IsFileMenuVisible = false;
+        vm.IsImageMenuVisible = false;
+        vm.IsSettingsMenuVisible = false;
+        vm.IsToolsMenuVisible = false;
+    }
+
+    /// <summary>
+    /// Checks if any menu is open
+    /// </summary>
+    public static bool IsAnyMenuOpen(MainViewModel vm)
+    {
+        return vm.IsFileMenuVisible ||
+               vm.IsImageMenuVisible ||
+               vm.IsSettingsMenuVisible ||
+               vm.IsToolsMenuVisible;
+    }
+
+    /// <summary>
+    /// Toggles the file menu
+    /// </summary>
+    public static void ToggleFileMenu(MainViewModel vm) => ToggleMenu(vm, MenuType.File);
+
+    /// <summary>
+    /// Toggles the image menu
+    /// </summary>
+    public static void ToggleImageMenu(MainViewModel vm) => ToggleMenu(vm, MenuType.Image);
+
+    /// <summary>
+    /// Toggles the settings menu
+    /// </summary>
+    public static void ToggleSettingsMenu(MainViewModel vm) => ToggleMenu(vm, MenuType.Settings);
+
+    /// <summary>
+    /// Toggles the tools menu
+    /// </summary>
+    public static void ToggleToolsMenu(MainViewModel vm) => ToggleMenu(vm, MenuType.Tools);
+
+    private static void ToggleMenu(MainViewModel vm, MenuType menuType)
+    {
+        if (UIHelper.IsDialogOpen)
+        {
+            return;
+        }
+
+        // Get the current state of the menu being toggled
+        var currentState = GetMenuState(vm, menuType);
+        
+        // Close all menus
+        CloseMenus(vm);
+        
+        // Only open the menu if it wasn't already open (toggle behavior)
+        if (!currentState)
+        {
+            SetMenuState(vm, menuType, true);
+        }
+        // If it was already open, it remains closed after CloseMenus()
+    }
+    
+    private static bool GetMenuState(MainViewModel vm, MenuType menuType)
+    {
+        return menuType switch
+        {
+            MenuType.File => vm.IsFileMenuVisible,
+            MenuType.Image => vm.IsImageMenuVisible,
+            MenuType.Settings => vm.IsSettingsMenuVisible,
+            MenuType.Tools => vm.IsToolsMenuVisible,
+            _ => false
+        };
+    }
+    
+    private static void SetMenuState(MainViewModel vm, MenuType menuType, bool state)
+    {
+        switch (menuType)
+        {
+            case MenuType.File:
+                vm.IsFileMenuVisible = state;
+                break;
+            case MenuType.Image:
+                vm.IsImageMenuVisible = state;
+                break;
+            case MenuType.Settings:
+                vm.IsSettingsMenuVisible = state;
+                break;
+            case MenuType.Tools:
+                vm.IsToolsMenuVisible = state;
+                break;
+        }
+    }
+
+    private enum MenuType
+    {
+        File,
+        Image,
+        Settings,
+        Tools
+    }
+}

+ 57 - 183
src/PicView.Avalonia/UI/UIHelper.cs

@@ -1,23 +1,22 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.ApplicationLifetimes;
-using Avalonia.Layout;
 using Avalonia.Threading;
 using PicView.Avalonia.Crop;
-using PicView.Avalonia.Gallery;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Views;
 using PicView.Avalonia.Views.UC;
-using PicView.Avalonia.Views.UC.Menus;
 using PicView.Avalonia.Views.UC.PopUps;
 using PicView.Avalonia.WindowBehavior;
-using PicView.Core.Gallery;
 
 namespace PicView.Avalonia.UI;
+
+/// <summary>
+/// Provides UI-related helper methods and properties
+/// </summary>
 public static class UIHelper
 {
-    #region GetControls
     
     public static bool IsDialogOpen { get; set; }
 
@@ -25,227 +24,104 @@ public static class UIHelper
     public static Control? GetTitlebar { get; private set; }
     public static EditableTitlebar? GetEditableTitlebar { get; private set; }
     public static GalleryAnimationControlView? GetGalleryView { get; private set; }
-
     public static BottomBar? GetBottomBar { get; private set; }
-    
     public static ToolTipMessage? GetToolTipMessage { get; private set; }
 
+    /// <summary>
+    /// Sets up control references from the main desktop application
+    /// </summary>
     public static void SetControls(IClassicDesktopStyleApplicationLifetime desktop)
     {
-        GetMainView = desktop.MainWindow.FindControl<MainView>("MainView");
-        GetTitlebar = desktop.MainWindow.FindControl<Control>("Titlebar");
-        GetEditableTitlebar = GetTitlebar.FindControl<EditableTitlebar>("EditableTitlebar");
-        GetGalleryView = GetMainView.MainGrid.GetControl<GalleryAnimationControlView>("GalleryView");
-        GetBottomBar = desktop.MainWindow.FindControl<BottomBar>("BottomBar");
-        GetToolTipMessage = GetMainView.MainGrid.FindControl<ToolTipMessage>("ToolTipMessage");
-    }
-
-    #endregion
-
-    #region Menus
-
-    public static void AddMenus()
-    {
-        var mainView = GetMainView;
-        var fileMenu = new FileMenu
-        {
-            VerticalAlignment = VerticalAlignment.Bottom,
-            HorizontalAlignment = HorizontalAlignment.Center,
-            Margin = new Thickness(0, 0, 120, 0),
-            IsVisible = false
-        };
-
-        mainView.MainGrid.Children.Add(fileMenu);
-
-        var imageMenu = new ImageMenu
-        {
-            VerticalAlignment = VerticalAlignment.Bottom,
-            HorizontalAlignment = HorizontalAlignment.Center,
-            Margin = new Thickness(0, 0, 63, 0),
-            IsVisible = false
-        };
-
-        mainView.MainGrid.Children.Add(imageMenu);
-
-        var settingsMenu = new SettingsMenu
-        {
-            VerticalAlignment = VerticalAlignment.Bottom,
-            HorizontalAlignment = HorizontalAlignment.Center,
-            Margin = new Thickness(0, 0, -75, 0),
-            IsVisible = false
-        };
-
-        mainView.MainGrid.Children.Add(settingsMenu);
-
-        var toolsMenu = new ToolsMenu
-        {
-            VerticalAlignment = VerticalAlignment.Bottom,
-            HorizontalAlignment = HorizontalAlignment.Center,
-            Margin = new Thickness(80, 0, 0, 0),
-            IsVisible = false
-        };
-
-        mainView.MainGrid.Children.Add(toolsMenu);
+        GetMainView = desktop.MainWindow?.FindControl<MainView>("MainView");
+        GetTitlebar = desktop.MainWindow?.FindControl<Control>("Titlebar");
+        GetEditableTitlebar = GetTitlebar?.FindControl<EditableTitlebar>("EditableTitlebar");
+        GetGalleryView = GetMainView?.MainGrid.GetControl<GalleryAnimationControlView>("GalleryView");
+        GetBottomBar = desktop.MainWindow?.FindControl<BottomBar>("BottomBar");
+        GetToolTipMessage = GetMainView?.MainGrid.FindControl<ToolTipMessage>("ToolTipMessage");
     }
 
-    public static void CloseMenus(MainViewModel vm)
-    {
-        vm.IsFileMenuVisible = false;
-        vm.IsImageMenuVisible = false;
-        vm.IsSettingsMenuVisible = false;
-        vm.IsToolsMenuVisible = false;
-    }
+    #region Navigation buttons
 
-    public static bool IsAnyMenuOpen(MainViewModel vm)
+    /// <summary>
+    /// Navigates to the next image using the bottom navigation button
+    /// </summary>
+    public static void NextButtonNavigation(MainViewModel vm)
     {
-        return vm.IsFileMenuVisible || vm.IsImageMenuVisible || vm.IsSettingsMenuVisible || vm.IsToolsMenuVisible;
+        SetButtonIntervalAndNavigate(GetBottomBar?.NextButton, true, false, vm);
     }
-
-    public static void ToggleFileMenu(MainViewModel vm)
-    {
-        if (IsDialogOpen)
-        {
-            return;
-        }
-        vm.IsFileMenuVisible = !vm.IsFileMenuVisible;
-        vm.IsImageMenuVisible = false;
-        vm.IsSettingsMenuVisible = false;
-        vm.IsToolsMenuVisible = false;
-    }
-
-    public static void ToggleImageMenu(MainViewModel vm)
+    
+    /// <summary>
+    /// Navigates to the previous image using the bottom navigation button
+    /// </summary>
+    public static void PreviousButtonNavigation(MainViewModel vm)
     {
-        if (IsDialogOpen)
-        {
-            return;
-        }
-        vm.IsFileMenuVisible = false;
-        vm.IsImageMenuVisible = !vm.IsImageMenuVisible;
-        vm.IsSettingsMenuVisible = false;
-        vm.IsToolsMenuVisible = false;
+        SetButtonIntervalAndNavigate(GetBottomBar?.PreviousButton, false, false, vm);
     }
-
-    public static void ToggleSettingsMenu(MainViewModel vm)
+    
+    /// <summary>
+    /// Navigates to the next image using the arrow button
+    /// </summary>
+    public static void NextArrowButtonNavigation(MainViewModel vm)
     {
-        if (IsDialogOpen)
-        {
-            return;
-        }
-        vm.IsFileMenuVisible = false;
-        vm.IsImageMenuVisible = false;
-        vm.IsSettingsMenuVisible = !vm.IsSettingsMenuVisible;
-        vm.IsToolsMenuVisible = false;
+        SetButtonIntervalAndNavigate(GetMainView?.ClickArrowRight?.PolyButton, true, true, vm);
     }
-
-    public static void ToggleToolsMenu(MainViewModel vm)
-    {
-        if (IsDialogOpen)
-        {
-            return;
-        }
-        vm.IsFileMenuVisible = false;
-        vm.IsImageMenuVisible = false;
-        vm.IsSettingsMenuVisible = false;
-        vm.IsToolsMenuVisible = !vm.IsToolsMenuVisible;
-    }
-
-    #endregion Menus
-
-    #region Navigation
-
-    public static async Task NavigateUp(MainViewModel? vm)
+    
+    /// <summary>
+    /// Navigates to the previous image using the arrow button
+    /// </summary>
+    public static void PreviousArrowButtonNavigation(MainViewModel vm)
     {
-        if (vm is null)
-        {
-            return;
-        }
-
-        if (GalleryFunctions.IsFullGalleryOpen)
-        {
-            GalleryNavigation.NavigateGallery(Direction.Up, vm);
-            return;
-        }
-
-        if (vm.IsScrollingEnabled)
-        {
-            await Dispatcher.UIThread.InvokeAsync(() => { vm.ImageViewer.ImageScrollViewer.LineUp(); });
-        }
-        else
-        {
-            vm.ImageViewer.Rotate(true);
-        }
+        SetButtonIntervalAndNavigate(GetMainView?.ClickArrowLeft?.PolyButton, false, true, vm);
     }
 
-    public static async Task NavigateDown(MainViewModel? vm)
+    private static void SetButtonIntervalAndNavigate(RepeatButton? button, bool isNext, bool isArrow, MainViewModel vm)
     {
-        if (vm is null)
-        {
-            return;
-        }
-
-        if (GalleryFunctions.IsFullGalleryOpen)
+        if (button != null)
         {
-            GalleryNavigation.NavigateGallery(Direction.Down, vm);
-            return;
+            button.Interval = (int)TimeSpan.FromSeconds(Settings.UIProperties.NavSpeed).TotalMilliseconds;
         }
 
-        if (vm.IsScrollingEnabled)
-        {
-            vm.ImageViewer.ImageScrollViewer.LineDown();
-        }
-        else
-        {
-            await Dispatcher.UIThread.InvokeAsync(() => { vm.ImageViewer.Rotate(false); });
-        }
+        Task.Run(() => NavigationManager.NavigateAndPositionCursor(isNext, isArrow, vm));
     }
 
-    public static void Center(MainViewModel? vm)
-    {
-        if (vm is null)
-        {
-            return;
-        }
-        if (GalleryFunctions.IsFullGalleryOpen)
-        {
-            GalleryFunctions.CenterGallery(vm);
-        }
-        else
-        {
-             WindowFunctions.CenterWindowOnScreen();
-        }
-    }
-
-
-
-    #endregion Navigation
+    #endregion
     
-    #region Dialogs
+    #region Dialog Operations
     
+    /// <summary>
+    /// Handles close action based on current application state
+    /// </summary>
     public static async Task Close(MainViewModel vm)
     {
-        if (IsAnyMenuOpen(vm))
+        // Handle open menus
+        if (MenuManager.IsAnyMenuOpen(vm))
         {
-            CloseMenus(vm);
+            MenuManager.CloseMenus(vm);
             return;
         }
 
+        // Handle cropping mode
         if (CropFunctions.IsCropping)
         {
             CropFunctions.CloseCropControl(vm);
             return;
         }
 
+        // Handle slideshow
         if (Slideshow.IsRunning)
         {
             Slideshow.StopSlideshow(vm);
             return;
         }
 
+        // Handle fullscreen
         if (Settings.WindowProperties.Fullscreen)
         {
             await WindowFunctions.MaximizeRestore();
             return;
         }
+        
+        // Handle window close
         if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
         {
             return;
@@ -255,16 +131,14 @@ public static class UIHelper
         {
             if (Settings.UIProperties.ShowConfirmationOnEsc)
             {
-                GetMainView.MainGrid.Children.Add(new CloseDialog());
+                GetMainView?.MainGrid.Children.Add(new CloseDialog());
             }
             else
             {
                 desktop.MainWindow?.Close();
             }
         });
-    } 
+    }
 
     #endregion
-
-
-}
+}

+ 4 - 53
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -13,7 +13,6 @@ using PicView.Avalonia.ImageHandling;
 using PicView.Avalonia.ImageTransformations;
 using PicView.Avalonia.Interfaces;
 using PicView.Avalonia.LockScreen;
-using PicView.Avalonia.Navigation;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.Wallpaper;
 using PicView.Avalonia.WindowBehavior;
@@ -60,65 +59,17 @@ public class MainViewModel : ViewModelBase
 
         NextCommand = ReactiveCommand.Create(() => { Task.Run(FunctionsHelper.Next); });
 
-        NextButtonCommand = ReactiveCommand.Create(() =>
-        {
-            var button = UIHelper.GetBottomBar?.NextButton;
-            if (button != null)
-            {
-                button.Interval =
-                    (int)TimeSpan.FromSeconds(SettingsHelper.Settings.UIProperties.NavSpeed).TotalMilliseconds;
-            }
-
-            Task.Run(() =>
-                NavigationManager.NavigateAndPositionCursor(true, false, this)
-            );
-        });
+        NextButtonCommand = ReactiveCommand.Create(() => { UIHelper.NextButtonNavigation(this); });
 
-        NextArrowButtonCommand = ReactiveCommand.Create(() =>
-        {
-            var button = UIHelper.GetMainView?.ClickArrowRight?.PolyButton;
-            if (button != null)
-            {
-                button.Interval =
-                    (int)TimeSpan.FromSeconds(SettingsHelper.Settings.UIProperties.NavSpeed).TotalMilliseconds;
-            }
-
-            Task.Run(() =>
-                NavigationManager.NavigateAndPositionCursor(true, true, this)
-            );
-        });
+        NextArrowButtonCommand = ReactiveCommand.Create(() => { UIHelper.NextArrowButtonNavigation(this); });
 
         NextFolderCommand = ReactiveCommand.Create(() => { Task.Run(FunctionsHelper.NextFolder); });
 
         PreviousCommand = ReactiveCommand.Create(() => { Task.Run(FunctionsHelper.Prev); });
 
-        PreviousButtonCommand = ReactiveCommand.Create(() =>
-        {
-            var button = UIHelper.GetBottomBar?.PreviousButton;
-            if (button != null)
-            {
-                button.Interval =
-                    (int)TimeSpan.FromSeconds(SettingsHelper.Settings.UIProperties.NavSpeed).TotalMilliseconds;
-            }
-
-            Task.Run(() =>
-                NavigationManager.NavigateAndPositionCursor(false, false, this)
-            );
-        });
+        PreviousButtonCommand = ReactiveCommand.Create(()  => { UIHelper.PreviousButtonNavigation(this); });
 
-        PreviousArrowButtonCommand = ReactiveCommand.Create(() =>
-        {
-            var button = UIHelper.GetMainView?.ClickArrowLeft?.PolyButton;
-            if (button != null)
-            {
-                button.Interval =
-                    (int)TimeSpan.FromSeconds(SettingsHelper.Settings.UIProperties.NavSpeed).TotalMilliseconds;
-            }
-
-            Task.Run(() =>
-                NavigationManager.NavigateAndPositionCursor(false, true, this)
-            );
-        });
+        PreviousArrowButtonCommand = ReactiveCommand.Create(() => { UIHelper.PreviousArrowButtonNavigation(this); });
 
         PreviousFolderCommand = ReactiveCommand.Create(() => { Task.Run(FunctionsHelper.PrevFolder); });