Browse Source

Fix recent files not being updated

Equbuxu 2 years ago
parent
commit
080dcfa5ff

+ 2 - 1
src/PixiEditor/Models/UserPreferences/PreferencesConstants.cs

@@ -1,6 +1,7 @@
-namespace PixiEditor.Models.UserPreferences;
+namespace PixiEditor.Models.UserPreferences;
 
 
 internal static class PreferencesConstants
 internal static class PreferencesConstants
 {
 {
     public const string FavouritePalettes = "FavouritePalettes";
     public const string FavouritePalettes = "FavouritePalettes";
+    public const string RecentlyOpened = "RecentlyOpened";
 }
 }

+ 9 - 1
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -91,7 +91,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         {
         {
             NoticeDialog.Show("The file does not exist", "Failed to open the file");
             NoticeDialog.Show("The file does not exist", "Failed to open the file");
             RecentlyOpened.Remove(path);
             RecentlyOpened.Remove(path);
-            IPreferences.Current.UpdateLocalPreference("RecentlyOpened", RecentlyOpened.Select(x => x.FilePath));
+            IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, RecentlyOpened.Select(x => x.FilePath));
             return;
             return;
         }
         }
 
 
@@ -165,6 +165,9 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
     {
     {
         DocumentViewModel document = Importer.ImportDocument(path);
         DocumentViewModel document = Importer.ImportDocument(path);
         AddDocumentViewModelToTheSystem(document);
         AddDocumentViewModelToTheSystem(document);
+
+        RecentlyOpened.Insert(0, document.FullFilePath);
+        IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, RecentlyOpened.Select(x => x.FilePath));
     }
     }
 
 
     /// <summary>
     /// <summary>
@@ -246,6 +249,11 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         if (asNew || string.IsNullOrEmpty(document.FullFilePath))
         if (asNew || string.IsNullOrEmpty(document.FullFilePath))
         {
         {
             success = Exporter.SaveAsEditableFileWithDialog(document, out path);
             success = Exporter.SaveAsEditableFileWithDialog(document, out path);
+            if (success)
+            {
+                RecentlyOpened.Insert(0, path);
+                IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, RecentlyOpened.Select(x => x.FilePath));
+            }
         }
         }
         else
         else
         {
         {