소스 검색

Crashes fixes and autosavecontrol look

Fixed
- corrupted preference crash,
- non-ui thread set text,
- converted text block to tooltip in autosave control
Krzysztof Krysiński 1 년 전
부모
커밋
13145d8088

+ 16 - 8
src/PixiEditor/Models/Preferences/PreferencesSettings.cs

@@ -199,19 +199,27 @@ internal class PreferencesSettings : IPreferences
     {
         if (!dict.ContainsKey(name)) return fallbackValue;
         var preference = dict[name];
-        if (typeof(T) == preference.GetType()) return (T)preference;
 
-        if (typeof(T).IsEnum)
+        try
         {
-            return (T)Enum.Parse(typeof(T), preference.ToString());
+            if (typeof(T) == preference.GetType()) return (T)preference;
+
+            if (typeof(T).IsEnum)
+            {
+                return (T)Enum.Parse(typeof(T), preference.ToString());
+            }
+
+            if (preference.GetType() == typeof(JArray))
+            {
+                return ((JArray)preference).ToObject<T>();
+            }
+
+            return (T)Convert.ChangeType(dict[name], typeof(T));
         }
-        
-        if (preference.GetType() == typeof(JArray))
+        catch (Exception)
         {
-            return ((JArray)preference).ToObject<T>();
+            return fallbackValue;
         }
-
-        return (T)Convert.ChangeType(dict[name], typeof(T));
     }
 
 #nullable disable

+ 16 - 5
src/PixiEditor/ViewModels/SubViewModels/Document/AutosaveDocumentViewModel.cs

@@ -281,20 +281,31 @@ internal class AutosaveDocumentViewModel : NotifyableObject
             try
             {
                 File.Copy(tempPath, Document.FullFilePath!, true);
-                Document.MarkAsSaved();
-                UpdateMainMenuTextSave("AUTOSAVE_SAVED", SaveIcon, SuccessBrush, false);
+                Application.Current.Dispatcher.Invoke(() =>
+                {
+                    Document.MarkAsSaved();
+                    UpdateMainMenuTextSave("AUTOSAVE_SAVED", SaveIcon, SuccessBrush, false);
+                });
             }
             catch (Exception e) when (e is UnauthorizedAccessException or DirectoryNotFoundException)
             {
-                UpdateMainMenuTextSave("AUTOSAVE_PLEASE_RESAVE", SaveIcon, ErrorBrush, true);
+                Application.Current.Dispatcher.Invoke(() =>
+                {
+                    UpdateMainMenuTextSave("AUTOSAVE_PLEASE_RESAVE", SaveIcon, ErrorBrush, true);
+                });
             }
             catch
             {
                 var minute = AutosavePeriodMinutes <= 1
                     ? new LocalizedString("MINUTE_SINGULAR")
                     : new LocalizedString("MINUTE_PLURAL");
-            
-                UpdateMainMenuTextSave(new LocalizedString("AUTOSAVE_FAILED_RETRYING", AutosavePeriodMinutes.ToString("0"), minute), WarnIcon, WarnBrush, true);
+
+                Application.Current.Dispatcher.Invoke(() =>
+                {
+                    UpdateMainMenuTextSave(
+                        new LocalizedString("AUTOSAVE_FAILED_RETRYING", AutosavePeriodMinutes.ToString("0"), minute),
+                        WarnIcon, WarnBrush, true);
+                });
             }
         }
     }

+ 1 - 1
src/PixiEditor/Views/MainWindow.xaml

@@ -495,7 +495,7 @@
                     </Grid>
                 </Border>
                 <usercontrols:AutosaveControl
-                    MinWidth="255"
+                    MinWidth="50"
                     Height="25"
                     Margin="5,0,0,0"
                     DataContext="{Binding DocumentManagerSubViewModel.ActiveDocument.AutosaveViewModel}"

+ 1 - 4
src/PixiEditor/Views/UserControls/AutosaveControl.xaml

@@ -14,6 +14,7 @@
     <Border Padding="8, 0"
             CornerRadius="5"
             BorderThickness="0"
+            ui:Translator.TooltipKey="{Binding MainMenuText, Mode=OneWay}"
             x:Name="autosaveControl">
         <Border.Style>
             <Style TargetType="Border">
@@ -66,10 +67,6 @@
                         </Style>
                     </TextBlock.Style>
                 </TextBlock>
-                <TextBlock
-                    ui:Translator.LocalizedString="{Binding MainMenuText, Mode=OneWay}"
-                    Foreground="White"
-                    VerticalAlignment="Center" />
             </StackPanel>
             <StackPanel Grid.Column="1" Orientation="Horizontal">
                 <StackPanel.Style>