瀏覽代碼

Get rid of some build warnings and remove unused code

Ruben 3 月之前
父節點
當前提交
e4670ab974

+ 2 - 2
src/PicView.Avalonia/Crop/CropFunctions.cs

@@ -67,8 +67,8 @@ public static class CropFunctions
         });
 
         IsCropping = true;
-        vm.PicViewer.Title.Value = TranslationManager.Translation.CropMessage;
-        vm.PicViewer.TitleTooltip.Value = TranslationManager.Translation.CropMessage;
+        vm.PicViewer.Title.Value = TranslationManager.Translation.CropMessage!;
+        vm.PicViewer.TitleTooltip.Value = TranslationManager.Translation.CropMessage!;
 
         await FunctionsMapper.CloseMenus();
 

+ 16 - 8
src/PicView.Avalonia/CustomControls/CopyButton.cs

@@ -1,6 +1,7 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Interactivity;
+using PicView.Core.DebugTools;
 
 namespace PicView.Avalonia.CustomControls;
 
@@ -11,9 +12,9 @@ public class CopyButton : Button
         
     protected override Type StyleKeyOverride => typeof(Button);
         
-    public string CopyText
+    public string? CopyText
     {
-        get => (string)GetValue(CopyTextProperty);
+        get => (string)GetValue(CopyTextProperty)!;
         set => SetValue(CopyTextProperty, value);
     }
 
@@ -24,15 +25,22 @@ public class CopyButton : Button
 
     private async void CopyButton_OnClick(object? sender, RoutedEventArgs args)
     {
-        if (string.IsNullOrWhiteSpace(CopyText))
+        try
         {
-            return;
-        }
+            if (string.IsNullOrWhiteSpace(CopyText))
+            {
+                return;
+            }
 
-        var topLevel = TopLevel.GetTopLevel(this);
-        if (topLevel?.Clipboard != null)
+            var topLevel = TopLevel.GetTopLevel(this);
+            if (topLevel?.Clipboard != null)
+            {
+                await topLevel.Clipboard.SetTextAsync(CopyText);
+            }
+        }
+        catch (Exception e)
         {
-            await topLevel.Clipboard.SetTextAsync(CopyText);
+            DebugHelper.LogDebug(nameof(CopyButton), nameof(CopyButton_OnClick), e);
         }
     }
 

+ 3 - 3
src/PicView.Avalonia/UI/TitleManager.cs

@@ -93,7 +93,7 @@ public static class TitleManager
     public static void SetLoadingTitle(MainViewModel vm)
     {
         vm.PicViewer.TitleTooltip.Value = vm.PicViewer.WindowTitle.Value = $"{TranslationManager.Translation.Loading} - PicView";
-        vm.PicViewer.Title.Value = TranslationManager.Translation.Loading;
+        vm.PicViewer.Title.Value = TranslationManager.Translation.Loading ?? string.Empty;
     }
 
     /// <summary>
@@ -260,9 +260,9 @@ public static class TitleManager
     /// </remarks>
     public static void SetNoImageTitle(MainViewModel vm)
     {
-        vm.PicViewer.Title.Value = TranslationManager.Translation.NoImage;
+        vm.PicViewer.Title.Value = TranslationManager.Translation.NoImage ?? string.Empty;
         vm.PicViewer.WindowTitle.Value = TranslationManager.Translation.NoImage + " - PicView";
-        vm.PicViewer.TitleTooltip.Value = TranslationManager.Translation.NoImage;
+        vm.PicViewer.TitleTooltip.Value = TranslationManager.Translation.NoImage ?? string.Empty;
     }
 
     private static void ReturnError(MainViewModel vm)

+ 3 - 20
src/PicView.Core/Titles/ImageTitleFormatter.cs

@@ -156,15 +156,6 @@ public static class ImageTitleFormatter
     }
 
 
-    /// <inheritdoc cref="GenerateTitleStrings(int, int, int, FileInfo, double, List{string})" />
-    public static WindowTitles GenerateTitleStrings(double width, double height, int index, FileInfo? fileInfo,
-        double zoomValue, List<string> filesList)
-    {
-        var newWidth = Convert.ToInt32(width);
-        var newHeight = Convert.ToInt32(height);
-        return GenerateTitleStrings(newWidth, newHeight, index, fileInfo, zoomValue, filesList);
-    }
-
     /// <summary>
     /// Generates a set of error titles in case of invalid parameters or exceptions during title generation.
     /// </summary>
@@ -173,9 +164,9 @@ public static class ImageTitleFormatter
     {
         return new WindowTitles
         {
-            BaseTitle = TranslationManager.Translation.UnexpectedError,
-            TitleWithAppName = TranslationManager.Translation.UnexpectedError,
-            FilePathTitle = TranslationManager.Translation.UnexpectedError
+            BaseTitle = TranslationManager.Translation.UnexpectedError ?? "",
+            TitleWithAppName = TranslationManager.Translation.UnexpectedError ?? "",
+            FilePathTitle = TranslationManager.Translation.UnexpectedError ?? ""
         };
     }
 
@@ -237,14 +228,6 @@ public static class ImageTitleFormatter
         };
     }
 
-    /// <inheritdoc cref="GenerateTitleForSingleImage(int, int, string, double)" />
-    public static WindowTitles GenerateTitleForSingleImage(double width, double height, string name, double zoomValue)
-    {
-        var newWidth = Convert.ToInt32(width);
-        var newHeight = Convert.ToInt32(height);
-        return GenerateTitleForSingleImage(newWidth, newHeight, name, zoomValue);
-    }
-
     /// <summary>
     /// Generates a string representing the aspect ratio of an image based on its width and height.
     /// If the aspect ratio exceeds a certain limit, no aspect ratio is returned.

+ 3 - 3
src/PicView.Core/ViewModels/PicViewerModel.cs

@@ -61,11 +61,11 @@ public class PicViewerModel : IDisposable
     // Used to flip the flip button
     public BindableReactiveProperty<int> ScaleX { get; } = new(1);
 
-    public BindableReactiveProperty<string> Title { get; } = new();
+    public BindableReactiveProperty<string>? Title { get; } = new();
 
-    public BindableReactiveProperty<string> TitleTooltip { get; } = new();
+    public BindableReactiveProperty<string>? TitleTooltip { get; } = new();
 
-    public BindableReactiveProperty<string> WindowTitle { get; } = new();
+    public BindableReactiveProperty<string>? WindowTitle { get; } = new();
     
     public BindableReactiveProperty<int> Index { get; } = new();
     public BindableReactiveProperty<int> GetIndex { get; } = new();