Explorar o código

Fix hover navigation buttons not registering context menu when right clicking and add navigation dialog support.

- Introduced `AddNavigationDialog` method in `DialogManager` for opening a navigation dialog.
- Moved context menu logic to `UIHelper.ShowMainContextMenu` for reuse.
- Added pointer press handling in `ClickArrowLeft` and `ClickArrowRight` for context menu and navigation dialog activation.
- Removed redundant `ShowMainContextMenu` method from `HoverBar`.
Ruben hai 3 días
pai
achega
7724c02d3f

+ 11 - 0
src/PicView.Avalonia/UI/DialogManager.cs

@@ -79,4 +79,15 @@ public static class DialogManager
         MenuManager.CloseMenus(UIHelper.GetMainView.DataContext as MainViewModel);
         UIHelper.GetMainView.MainGrid.Children.Add(new FileSearchDialog());
     }
+
+    public static void AddNavigationDialog()
+    {
+        if (UIHelper.GetMainView.MainGrid.Children.OfType<NavigationDialog>().Any())
+        {
+            return;
+        }
+
+        MenuManager.CloseMenus(UIHelper.GetMainView.DataContext as MainViewModel);
+        UIHelper.GetMainView.MainGrid.Children.Add(new NavigationDialog());
+    }
 }

+ 10 - 0
src/PicView.Avalonia/UI/UIHelper.cs

@@ -71,6 +71,16 @@ public static class UIHelper
     private const string MediumFontLocation = "avares://PicView.Avalonia/Assets/Fonts/Roboto-Medium.ttf#Roboto";
     public static FontFamily MediumFontFamily => new(MediumFontLocation);
 
+    public static void ShowMainContextMenu()
+    {
+        if (GetMainView.Resources.TryGetResource("MainContextMenu", Application.Current.ActualThemeVariant,
+                out var value)
+            && value is ContextMenu mainContextMenu)
+        {
+            mainContextMenu.Open();
+        }
+    }
+
     /// <summary>
     /// Centers the window or gallery based on current state
     /// </summary>

+ 23 - 0
src/PicView.Avalonia/Views/UC/Buttons/ClickArrowLeft.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Interactivity;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
 
@@ -15,6 +17,7 @@ public partial class ClickArrowLeft : UserControl
                 return;
             }
             PointerWheelChanged += async (_, e) => await ImageViewer.PreviewOnPointerWheelChanged(this, e);
+            AddHandler(PointerPressedEvent, ManagePointerPressed, RoutingStrategies.Tunnel);
             PolyButton.Click += (_, _) =>
             {
                 vm.MainWindow.IsClickArrowLeftClicked = true;
@@ -22,4 +25,24 @@ public partial class ClickArrowLeft : UserControl
             };
         };
     }
+
+    private void ManagePointerPressed(object? sender, PointerPressedEventArgs e)
+    {
+        var props = e.Properties;
+
+        if (PolyButton.IsPointerOver)
+        {
+            if (props.IsRightButtonPressed)
+            {
+                DialogManager.AddNavigationDialog();
+            }
+        }
+        else
+        {
+            if (props.IsRightButtonPressed)
+            {
+                UIHelper.ShowMainContextMenu();
+            }
+        }
+    }
 }

+ 23 - 0
src/PicView.Avalonia/Views/UC/Buttons/ClickArrowRight.axaml.cs

@@ -1,4 +1,6 @@
 using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Interactivity;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
 
@@ -15,6 +17,7 @@ public partial class ClickArrowRight : UserControl
                 return;
             }
             PointerWheelChanged += async (_, e) => await ImageViewer.PreviewOnPointerWheelChanged(this, e);
+            AddHandler(PointerPressedEvent, ManagePointerPressed, RoutingStrategies.Tunnel);
             PolyButton.Click += (_, _) =>
             {
                 vm.MainWindow.IsClickArrowRightClicked = true;
@@ -22,4 +25,24 @@ public partial class ClickArrowRight : UserControl
             };
         };
     }
+
+    private void ManagePointerPressed(object? sender, PointerPressedEventArgs e)
+    {
+        var props = e.Properties;
+
+        if (PolyButton.IsPointerOver)
+        {
+            if (props.IsRightButtonPressed)
+            {
+                DialogManager.AddNavigationDialog();
+            }
+        }
+        else
+        {
+            if (props.IsRightButtonPressed)
+            {
+                UIHelper.ShowMainContextMenu();
+            }
+        }
+    }
 }

+ 1 - 11
src/PicView.Avalonia/Views/UC/HoverBar.axaml.cs

@@ -216,14 +216,13 @@ public partial class HoverBar : UserControl
                 await Task.Delay(TimeSpan.FromSeconds(0.3));
                 Dispatcher.UIThread.Post(() => { ToolTip.SetIsOpen(ProgressBar, false); },
                     DispatcherPriority.Background);
-                
             }
         }
         else
         {
             if (props.IsRightButtonPressed)
             {
-                ShowMainContextMenu();
+                UIHelper.ShowMainContextMenu();
             }
         }
     }
@@ -240,15 +239,6 @@ public partial class HoverBar : UserControl
     private static void ShowSearchDialog() =>
         UIHelper.GetMainView.MainGrid.Children.Add(new FileSearchDialog());
 
-    private static void ShowMainContextMenu()
-    {
-        if (UIHelper.GetMainView.Resources.TryGetResource("MainContextMenu", Application.Current.ActualThemeVariant, out var value)
-            && value is ContextMenu mainContextMenu)
-        {
-            mainContextMenu.Open();
-        }
-    }
-
     protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
     {
         base.OnDetachedFromLogicalTree(e);