浏览代码

Make 'Mark as saved' a passthrough action, now the * works correctly

Equbuxu 1 年之前
父节点
当前提交
b9dddac5a0

+ 8 - 1
src/PixiEditor/Models/DocumentModels/DocumentUpdater.cs

@@ -125,10 +125,17 @@ internal class DocumentUpdater
             case ClearSoftSelectedMembers_PassthroughAction info:
                 ProcessClearSoftSelectedMembers(info);
                 break;
-                
+            case MarkAsSavedAutosavedEtc_PassthroughAction info:
+                MarkAsSavedAutosavedEtc(info);
+                break;
         }
     }
 
+    private void MarkAsSavedAutosavedEtc(MarkAsSavedAutosavedEtc_PassthroughAction info)
+    {
+        doc.InternalMarkAsSavedAutosavedEtc(info.Type);
+    }
+
     private void ProcessReferenceLayerIsVisible(ReferenceLayerIsVisible_ChangeInfo info)
     {
         doc.ReferenceLayerViewModel.InternalSetReferenceLayerIsVisible(info.IsVisible);

+ 14 - 0
src/PixiEditor/Models/DocumentPassthroughActions/MarkAsSavedAutosavedEtc_PassthroughAction.cs

@@ -0,0 +1,14 @@
+using PixiEditor.ChangeableDocument.Actions;
+using PixiEditor.ChangeableDocument.ChangeInfos;
+
+namespace PixiEditor.Models.DocumentPassthroughActions;
+
+internal enum DocumentMarkType
+{
+    Saved,
+    Unsaved,
+    Autosaved,
+    UnAutosaved
+}
+
+internal record class MarkAsSavedAutosavedEtc_PassthroughAction(DocumentMarkType Type) : IChangeInfo, IAction;

+ 28 - 6
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentViewModel.cs

@@ -23,6 +23,7 @@ using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DocumentModels;
 using PixiEditor.Models.DocumentModels.Public;
+using PixiEditor.Models.DocumentPassthroughActions;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.Localization;
 using PixiEditor.ViewModels.SubViewModels.Document.TransformOverlays;
@@ -302,20 +303,17 @@ internal partial class DocumentViewModel : NotifyableObject
 
     public void MarkAsSaved()
     {
-        lastChangeOnSave = Internals.Tracker.LastChangeGuid;
-        RaisePropertyChanged(nameof(AllChangesSaved));
+        Internals.ActionAccumulator.AddActions(new MarkAsSavedAutosavedEtc_PassthroughAction(DocumentMarkType.Saved));
     }
 
     public void MarkAsAutosaved()
     {
-        lastChangeOnAutosave = Internals.Tracker.LastChangeGuid;
-        RaisePropertyChanged(nameof(AllChangesAutosaved));
+        Internals.ActionAccumulator.AddActions(new MarkAsSavedAutosavedEtc_PassthroughAction(DocumentMarkType.Autosaved));
     }
 
     public void MarkAsUnsaved()
     {
-        lastChangeOnSave = Guid.NewGuid();
-        RaisePropertyChanged(nameof(AllChangesSaved));
+        Internals.ActionAccumulator.AddActions(new MarkAsSavedAutosavedEtc_PassthroughAction(DocumentMarkType.Unsaved));
     }
 
     /// <summary>
@@ -542,7 +540,31 @@ internal partial class DocumentViewModel : NotifyableObject
     public void InternalClearSoftSelectedMembers() => softSelectedStructureMembers.Clear();
 
     public void InternalAddSoftSelectedMember(StructureMemberViewModel member) => softSelectedStructureMembers.Add(member);
+    
     public void InternalRemoveSoftSelectedMember(StructureMemberViewModel member) => softSelectedStructureMembers.Remove(member);
+
+    public void InternalMarkAsSavedAutosavedEtc(DocumentMarkType type)
+    {
+        switch (type)
+        {
+            case DocumentMarkType.Saved:
+                lastChangeOnSave = Internals.Tracker.LastChangeGuid;
+                RaisePropertyChanged(nameof(AllChangesSaved));
+                break;
+            case DocumentMarkType.Unsaved:
+                lastChangeOnSave = Guid.NewGuid();
+                RaisePropertyChanged(nameof(AllChangesSaved));
+                break;
+            case DocumentMarkType.Autosaved:
+                lastChangeOnAutosave = Internals.Tracker.LastChangeGuid;
+                RaisePropertyChanged(nameof(AllChangesAutosaved));
+                break;
+            case DocumentMarkType.UnAutosaved:
+                lastChangeOnAutosave = Guid.NewGuid();
+                RaisePropertyChanged(nameof(AllChangesAutosaved));
+                break;
+        }
+    }
     #endregion
 
     /// <summary>