Selaa lähdekoodia

Fix crash when navigating into file view associations too fast #157

Ruben 7 kuukautta sitten
vanhempi
sitoutus
34698ff30d

+ 21 - 0
src/PicView.Avalonia/Views/FileAssociationsView.axaml.cs

@@ -4,6 +4,7 @@ using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Media;
 using PicView.Avalonia.ViewModels;
+using PicView.Core.Localization;
 using PicView.Core.ViewModels;
 using ReactiveUI;
 
@@ -79,6 +80,26 @@ public partial class FileAssociationsView : UserControl
         // Create checkboxes for each file type group and item
         foreach (var fileTypeGroup in vm.AssociationsViewModel.FileTypeGroups)
         {
+            if (fileTypeGroup.Name is null)
+            {
+                // If going into this view too fast, sometimes the name is null. This is a workaround
+                if (fileTypeGroup.FileTypes.Any(x => x.Extension.StartsWith(".png")))
+                {
+                    fileTypeGroup.Name = TranslationManager.Translation.Normal!;
+                }
+                else if (fileTypeGroup.FileTypes.Any(x => x.Extension.StartsWith(".svg")))
+                {
+                    fileTypeGroup.Name = TranslationManager.GetTranslation("Graphics");
+                }
+                else if (fileTypeGroup.FileTypes.Any(x => x.Extension.StartsWith(".raw")))
+                {
+                    fileTypeGroup.Name = TranslationManager.GetTranslation("Raw");
+                }
+                else if (fileTypeGroup.FileTypes.Any(x => x.Extension.StartsWith(".wpg")))
+                {
+                    fileTypeGroup.Name = TranslationManager.GetTranslation("Uncommon");
+                }
+            }
             // Create group header checkbox
             var groupCheckBox = new CheckBox
             {

+ 2 - 0
src/PicView.Core/Localization/LanguageModel.cs

@@ -388,4 +388,6 @@ public class LanguageModel
     public string? ClearEffects { get; set; }
     public string? Solarize { get; set; }
     public string? PencilSketch { get; set; }
+    
+    
 }

+ 6 - 6
src/PicView.Core/ViewModels/FileAssociationsViewModel.cs

@@ -98,7 +98,7 @@ public class FileAssociationsViewModel : ReactiveObject
         }
     }
     
-    private void InitializeFileTypes()
+    public void InitializeFileTypes()
     {
         var groups = new[]
         {
@@ -114,7 +114,7 @@ public class FileAssociationsViewModel : ReactiveObject
                 new FileTypeItem("Icon", [".ico"])
             ]),
             
-            new FileTypeGroup("Graphics", [
+            new FileTypeGroup(TranslationManager.GetTranslation("Graphics"), [
                 new FileTypeItem("Scalable Vector Graphics", [".svg", ".svgz"]),
                 new FileTypeItem("Photoshop", [".psd", ".psb"]),
                 new FileTypeItem("XCF", [".xcf"]),
@@ -129,7 +129,7 @@ public class FileAssociationsViewModel : ReactiveObject
                 new FileTypeItem("Industrial Light & Magic OpenEXR", [".exr"])
             ]),
             
-            new FileTypeGroup("Raw", [
+            new FileTypeGroup(TranslationManager.GetTranslation("Raw"), [
                 new FileTypeItem("Raw", [".raw"]),
                 new FileTypeItem("Framed Raster", [".3fr"]),
                 new FileTypeItem("Sony Digital Camera RAW", [".arw"]),
@@ -154,7 +154,7 @@ public class FileAssociationsViewModel : ReactiveObject
                 new FileTypeItem("Windows Metafile Image", [".wmf", ".emf"]),
             ]),
             
-            new FileTypeGroup("Uncommon", [
+            new FileTypeGroup(TranslationManager.GetTranslation("Uncommon"), [
                 new FileTypeItem("Wordperfect Graphics", [".wpg"]),
                 new FileTypeItem("Paintbrush bitmap graphics", [".pcx"]),
                 new FileTypeItem("X Bitmap", [".xbm"]),
@@ -166,7 +166,7 @@ public class FileAssociationsViewModel : ReactiveObject
                 new FileTypeItem("Base64", [".b64"])
             ]),
             
-            new FileTypeGroup("Archive", [
+            new FileTypeGroup(TranslationManager.GetTranslation("Archives"), [
                 new FileTypeItem("Zip", [".zip"], false),
                 new FileTypeItem("Rar", [".rar"], false),
                 new FileTypeItem("Gzip", [".gzip"], false),
@@ -184,7 +184,7 @@ public class FileAssociationsViewModel : ReactiveObject
 
 public class FileTypeGroup : ReactiveObject
 {
-    public string Name { get; }
+    public string Name { get; set; }
     public ObservableCollection<FileTypeItem> FileTypes { get; }
 
     public bool IsSelected