Browse Source

Switch to modern pattern matching for image format handling, clean up unused XAML namespaces, and refine menu item theming.

- Replaced traditional switch statements with switch expressions for better readability and maintainability in `GetImage.cs`.
- Removed unused `xmlns:uc` namespace from `ImageViewer.axaml`.
- Enhanced XAML theme consistency by adding `Theme` property to menu items in the title bar.
- Added comments and minor cleanup in `ZoomPanControl` for future enhancements.
Ruben 1 week ago
parent
commit
8ae635508a

+ 8 - 3
src/PicView.Avalonia.Win32/Views/WinTitleBar.axaml

@@ -501,8 +501,11 @@
                     <Separator Margin="0" Opacity="1" />
 
                     <!--  Fullscreen  -->
-                    <MenuItem Command="{CompiledBinding MainWindow.ToggleFullscreenCommand}"
-                              Header="{CompiledBinding Translation.Fullscreen.Value, Mode=OneWay}">
+                    <MenuItem
+                        Command="{CompiledBinding MainWindow.ToggleFullscreenCommand}"
+                        Header="{CompiledBinding Translation.Fullscreen.Value,
+                                                 Mode=OneWay}"
+                        Theme="{StaticResource MainBg}">
                         <MenuItem.Icon>
                             <Path Classes="FullscreenPath" />
                         </MenuItem.Icon>
@@ -515,6 +518,7 @@
                                                  Mode=OneWay}"
                         IsVisible="{CompiledBinding MainWindow.ShouldMaximizeBeShown.Value,
                                                     Mode=OneWay}"
+                        Theme="{StaticResource MainBg}"
                         x:Name="MaximizeMenuItem">
                         <MenuItem.Icon>
                             <Image Classes="MaximizeImage" />
@@ -527,7 +531,8 @@
                         Header="{CompiledBinding Translation.RestoreDown.Value,
                                                  Mode=OneWay}"
                         IsVisible="{CompiledBinding MainWindow.ShouldRestore.Value,
-                                                    Mode=OneWay}">
+                                                    Mode=OneWay}"
+                        Theme="{StaticResource MainBg}">
                         <MenuItem.Icon>
                             <Path Classes="RestorePath" />
                         </MenuItem.Icon>

+ 8 - 3
src/PicView.Avalonia/CustomControls/ZoomPanControl.cs

@@ -94,6 +94,8 @@ public class ZoomPanControl : Decorator
             IsVisible = false
         };
         _zoomPreviewer.SetZoomPanControl(this);
+
+        // TODO: should figure out how to make a more self-contained approach, for ZoomPreviewer, for possible future tab-based layout
         UIHelper.GetMainView.MainGrid.Children.Add(_zoomPreviewer);
     }
 
@@ -124,6 +126,9 @@ public class ZoomPanControl : Decorator
         RemoveHandler(PointerPressedEvent, HandleResetZoomOrStartPanning);
         RemoveHandler(PointerMovedEvent, HandlePanning);
         RemoveHandler(PointerReleasedEvent, StopPanning);
+
+        UIHelper.GetMainView.MainGrid.Children.Remove(_zoomPreviewer);
+        _zoomPreviewer = null;
         base.OnDetachedFromVisualTree(e);
     }
 
@@ -262,6 +267,9 @@ public class ZoomPanControl : Decorator
             return;
         }
 
+        // Animated panning feels off, should disable it
+        SetTransitions(false);
+
         _isPanning = true;
         _panStartPointer = p;
         _panStartTranslate = new Point(TranslateX, TranslateY);
@@ -281,9 +289,6 @@ public class ZoomPanControl : Decorator
             return;
         }
 
-        // Animated panning feels off, should disable it
-        SetTransitions(false);
-
         var p = e.GetPosition(this);
         var delta = p - _panStartPointer;
 

+ 28 - 32
src/PicView.Avalonia/ImageHandling/GetImage.cs

@@ -28,40 +28,36 @@ public static class GetImage
             }
 
             // Process the image based on type
-            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
-            switch (magickImage.Format)
+            return magickImage.Format switch
             {
-                case MagickFormat.WebP: 
-                case MagickFormat.WebM:
-                case MagickFormat.Png:
-                case MagickFormat.Png00:
-                case MagickFormat.Png8:
-                case MagickFormat.Png24:
-                case MagickFormat.Png32:
-                case MagickFormat.Png48:
-                case MagickFormat.Png64:
-                case MagickFormat.APng:
-                case MagickFormat.Jpe:
-                case MagickFormat.Jpeg:
-                case MagickFormat.Pjpeg:
-                case MagickFormat.Bmp:
-                case MagickFormat.Tif:
-                case MagickFormat.Tiff:
-                case MagickFormat.Ico:
-                case MagickFormat.Icon:
-                case MagickFormat.Wbmp:
-                    return await GetSkBitmapAsync(fileInfo).ConfigureAwait(false);
-                
-                case MagickFormat.Arw:
-                case MagickFormat.Nef:
-                case MagickFormat.Dng:
-                case MagickFormat.Cr2:
-                case MagickFormat.Rw2:
-                    return await GetRawBitmapAsync(fileInfo, magickImage).ConfigureAwait(false);
+                MagickFormat.WebP or
+                    MagickFormat.WebM or
+                    MagickFormat.Png or
+                    MagickFormat.Png00 or
+                    MagickFormat.Png8 or
+                    MagickFormat.Png24 or
+                    MagickFormat.Png32 or
+                    MagickFormat.Png48 or
+                    MagickFormat.Png64 or
+                    MagickFormat.APng or
+                    MagickFormat.Jpe or
+                    MagickFormat.Jpeg or
+                    MagickFormat.Pjpeg or
+                    MagickFormat.Bmp or
+                    MagickFormat.Tif or
+                    MagickFormat.Tiff or
+                    MagickFormat.Ico or
+                    MagickFormat.Icon or
+                    MagickFormat.Wbmp => await GetSkBitmapAsync(fileInfo).ConfigureAwait(false),
 
-                default:
-                    return await GetNonStandardBitmapAsync(fileInfo, magickImage).ConfigureAwait(false);
-            }
+                MagickFormat.Arw or
+                    MagickFormat.Nef or
+                    MagickFormat.Dng or
+                    MagickFormat.Cr2 or
+                    MagickFormat.Rw2 => await GetRawBitmapAsync(fileInfo, magickImage).ConfigureAwait(false),
+
+                _ => await GetNonStandardBitmapAsync(fileInfo, magickImage).ConfigureAwait(false)
+            };
         }
         catch (Exception e)
         {

+ 0 - 1
src/PicView.Avalonia/Views/UC/ImageViewer.axaml

@@ -5,7 +5,6 @@
     x:DataType="vm:MainViewModel"
     xmlns="https://github.com/avaloniaui"
     xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls"
-    xmlns:uc="clr-namespace:PicView.Avalonia.Views.UC"
     xmlns:vm="clr-namespace:PicView.Avalonia.ViewModels"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <LayoutTransformControl x:Name="ImageLayoutTransformControl">