فهرست منبع

Fixed crash report popup

CPKreuz 2 سال پیش
والد
کامیت
a6353e6679

+ 1 - 1
src/PixiEditor/Localization/ILocalizationProvider.cs

@@ -4,7 +4,7 @@ namespace PixiEditor.Localization;
 
 public interface ILocalizationProvider
 {
-    public static ILocalizationProvider Current => ViewModelMain.Current.LocalizationProvider;
+    public static ILocalizationProvider Current => ViewModelMain.Current?.LocalizationProvider;
     
     public string LocalizationDataPath { get; }
     public LocalizationData LocalizationData { get; }

+ 1 - 1
src/PixiEditor/Localization/LocalizedString.cs

@@ -16,7 +16,7 @@ public struct LocalizedString
             #if DEBUG_LOCALIZATION
             Value = key;
             #else
-            Value = ViewModelMain.Current.DebugSubViewModel?.LocalizationKeyShowMode switch
+            Value = ViewModelMain.Current?.DebugSubViewModel?.LocalizationKeyShowMode switch
             {
                 LocalizationKeyShowMode.Key => Key,
                 LocalizationKeyShowMode.ValueKey => $"{GetValue(value)} ({Key})",

+ 12 - 0
src/PixiEditor/Views/Translator.cs

@@ -56,6 +56,12 @@ public class Translator : UIElement
     private static void TooltipKeyPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
     {
         d.SetValue(FrameworkElement.ToolTipProperty, new LocalizedString(GetTooltipKey(d)).Value);
+
+        if (ILocalizationProvider.Current == null)
+        {
+            return;
+        }
+        
         ILocalizationProvider.Current.OnLanguageChanged += (lang) => OnLanguageChangedTooltipKey(d, lang);
     }
 
@@ -92,6 +98,12 @@ public class Translator : UIElement
         if (e.NewValue is string key)
         {
             UpdateKey(d, key);
+            
+            if (ILocalizationProvider.Current == null)
+            {
+                return;
+            }
+
             ILocalizationProvider.Current.OnLanguageChanged += (lang) => OnLanguageChangedKey(d, lang);
         }
     }