Преглед на файлове

Refactor title management and aspect ratio formatting

- Consolidated title assignment logic into `ApplyTitles` for better code reuse.
- Simplified and streamlined `FormatAspectRatio` logic for clarity.
- Improved consistency and readability across `ImageTitleFormatter` and `TitleManager`.
Ruben преди 4 месеца
родител
ревизия
c1cfba570e
променени са 2 файла, в които са добавени 16 реда и са изтрити 18 реда
  1. 10 9
      src/PicView.Avalonia/UI/TitleManager.cs
  2. 6 9
      src/PicView.Core/Titles/ImageTitleFormatter.cs

+ 10 - 9
src/PicView.Avalonia/UI/TitleManager.cs

@@ -80,9 +80,7 @@ public static class TitleManager
         var windowTitles = ImageTitleFormatter.GenerateTitleStrings(pWidth, pHeight,
             NavigationManager.GetCurrentIndex,
             fileInfo, vm.GlobalSettings.RotationAngle.CurrentValue, NavigationManager.GetCollection);
-        vm.PicViewer.WindowTitle.Value = windowTitles.TitleWithAppName;
-        vm.PicViewer.Title.Value = windowTitles.BaseTitle;
-        vm.PicViewer.TitleTooltip.Value = windowTitles.FilePathTitle;
+        ApplyTitles(vm, windowTitles);
     }
 
     /// <summary>
@@ -122,9 +120,7 @@ public static class TitleManager
         var windowTitles = ImageTitleFormatter.GenerateTitleStrings(imageModel.PixelWidth, imageModel.PixelHeight,
             NavigationManager.GetCurrentIndex,
             imageModel.FileInfo, vm.GlobalSettings.RotationAngle.CurrentValue, NavigationManager.GetCollection);
-        vm.PicViewer.WindowTitle.Value = windowTitles.TitleWithAppName;
-        vm.PicViewer.Title.Value = windowTitles.BaseTitle;
-        vm.PicViewer.TitleTooltip.Value = windowTitles.FilePathTitle;
+        ApplyTitles(vm, windowTitles);
     }
 
     /// <summary>
@@ -146,9 +142,7 @@ public static class TitleManager
     {
         var singeImageWindowTitles = ImageTitleFormatter.GenerateTiffTitleStrings(width, height, index, fileInfo,
             tiffNavigationInfo, 1, NavigationManager.GetCollection);
-        vm.PicViewer.WindowTitle.Value = singeImageWindowTitles.TitleWithAppName;
-        vm.PicViewer.Title.Value = singeImageWindowTitles.BaseTitle;
-        vm.PicViewer.TitleTooltip.Value = singeImageWindowTitles.BaseTitle;
+        ApplyTitles(vm, singeImageWindowTitles);
     }
 
     /// <summary>
@@ -282,4 +276,11 @@ public static class TitleManager
         ReturnError(vm);
         return false;
     }
+    
+    private static void ApplyTitles(MainViewModel vm, WindowTitles titles)
+    {
+        vm.PicViewer.WindowTitle.Value = titles.TitleWithAppName;
+        vm.PicViewer.Title.Value = titles.BaseTitle;
+        vm.PicViewer.TitleTooltip.Value = titles.FilePathTitle;
+    }
 }

+ 6 - 9
src/PicView.Core/Titles/ImageTitleFormatter.cs

@@ -90,6 +90,7 @@ public static class ImageTitleFormatter
         sb.Append(" x ");
         sb.Append(height);
         sb.Append(FormatAspectRatio(width, height));
+        sb.Append(") "); 
         sb.Append(fileInfo.Length.GetReadableFileSize());
 
         var zoomString = FormatZoomPercentage(zoomValue);
@@ -206,6 +207,7 @@ public static class ImageTitleFormatter
         sb.Append(" x ");
         sb.Append(height);
         sb.Append(FormatAspectRatio(width, height));
+        sb.Append(") "); 
 
         // Add zoom information if applicable
         var zoomString = FormatZoomPercentage(zoomValue);
@@ -237,24 +239,19 @@ public static class ImageTitleFormatter
     /// <returns>A string representing the aspect ratio in the format "x:y", or an empty string if the ratio is too large.</returns>
     public static string FormatAspectRatio(int width, int height)
     {
-        if (width <= 0 || height <= 0)
-        {
-            return ") ";
-        }
+        if (width <= 0 || height <= 0) { return string.Empty; }
 
         var gcd = GCD(width, height);
         var aspectX = width / gcd;
         var aspectY = height / gcd;
 
         return IsAspectRatioWithinLimits(aspectX, aspectY) 
-            ? $", {aspectX}:{aspectY}) " 
-            : ") ";
+            ? $", {aspectX}:{aspectY}" 
+            : string.Empty;
     }
     
     private static bool IsAspectRatioWithinLimits(int x, int y)
-    {
-        return x <= MaxAspectRatioX && y <= MaxAspectRatioY;
-    }
+        => x <= MaxAspectRatioX && y <= MaxAspectRatioY;
 
     /// <summary>
     /// Calculates the Greatest Common Divisor (GCD) of two integers.