diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs
index 30bccdd..ac0cbd6 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs
@@ -1,4 +1,4 @@
-// 配方编辑节点:把可序列化配方转换为可绑定、可增删排序的区域和步骤树,保存时转换回配置。
+// 配方编辑节点:把可序列化配方转换为可绑定、可增删排序的区域和步骤树,保存时转换回配置。
using System.Collections.ObjectModel;
using System.Windows.Input;
@@ -152,8 +152,10 @@ public class RecipeNode : EditorNode
get { return IsNew; }
}
- internal void MarkSaved(string fileName)
+ /// 写盘成功后同步文件名和修订日期,使后续编辑快照与已保存配置一致。
+ internal void MarkSaved(string fileName, string? revisionDate)
{
+ RevisionDate = revisionDate;
FileName = fileName;
IsNew = false;
}
@@ -177,6 +179,9 @@ public class RecipeNode : EditorNode
set { SetProperty(ref _version, value); }
}
+ /// 上次保存的修订日期,随配置载入和写出。
+ private string? RevisionDate { get; set; }
+
/// 说明(sop.description)
public string Description
{
@@ -376,6 +381,7 @@ public class RecipeNode : EditorNode
IsNew = isNew,
Name = isNew ? config.Sop.Name : fileName,
Version = config.Sop.Version,
+ RevisionDate = config.Sop.RevisionDate,
Description = config.Sop.Description,
};
@@ -444,6 +450,7 @@ public class RecipeNode : EditorNode
config.Sop.Name = Name;
config.Sop.Version = Version;
+ config.Sop.RevisionDate = RevisionDate;
config.Sop.Description = Description;
config.Sop.Parts = LegacyParts?.ToList();
diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditorViewModel.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditorViewModel.cs
index add569b..0ac418f 100644
--- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditorViewModel.cs
+++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditorViewModel.cs
@@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
+using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using Avalonia.Media;
@@ -346,6 +347,8 @@ public partial class RecipeEditorViewModel : BindableBase, IDialogAware
if (_isNew && File.Exists(path)) throw new IOException("同名配方已存在,请使用其他配方名");
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
var config = Recipe.ToConfig();
+ // 日期先写入待保存的配置,回读成功后再同步到编辑节点。
+ config.Sop.RevisionDate = DateTime.Today.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
var baselineYaml = SopConfigLoader.ToYaml(config);
var saved = SopConfigLoader.Save(config, path);
// 只有落盘并回读成功才更新基准,保存失败时仍保留关闭确认。
@@ -353,7 +356,7 @@ public partial class RecipeEditorViewModel : BindableBase, IDialogAware
_path = path;
_isNew = false;
- Recipe.MarkSaved(Path.GetFileNameWithoutExtension(path));
+ Recipe.MarkSaved(Path.GetFileNameWithoutExtension(path), saved.Sop.RevisionDate);
InitializeRecipeTools();
RaisePropertyChanged(nameof(FileNameText));
RaisePropertyChanged(nameof(Title));
diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopConfig.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopConfig.cs
index 23b1520..b90f7a5 100644
--- a/src/SopHelper.CrossPlatform.Engine/Sop/SopConfig.cs
+++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopConfig.cs
@@ -28,6 +28,10 @@ public class SopBody
/// 版本
public string Version { get; set; } = "1.0";
+ /// 最近一次在编辑器保存的本地日期(yyyy-MM-dd);旧配方可省略。
+ [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)]
+ public string? RevisionDate { get; set; }
+
/// 说明
public string Description { get; set; } = "";
diff --git a/tests/Avalonia.Smoke/Program.cs b/tests/Avalonia.Smoke/Program.cs
index a6f9ec5..a4b3a87 100644
--- a/tests/Avalonia.Smoke/Program.cs
+++ b/tests/Avalonia.Smoke/Program.cs
@@ -1547,11 +1547,17 @@ internal static class Smoke
{"onSaved",new Action(_=>callbacks++)}},_=>{});
await Task.Delay(80);
var modal=lifetime.Windows.OfType().Single();
+ // 先修改配方,触发有未保存改动时的关闭确认。
+ ((RecipeEditorViewModel)modal.DataContext!).Recipe.AddStepCommand.Execute();
((RecipeEditorViewModel)modal.DataContext!).CloseCommand.Execute();
await ChooseRecipeClose(modal,"SaveRecipeAndCloseButton");
for(var i=0;i<100&&lifetime.Windows.Contains(modal);i++)await Task.Delay(20);
Check(!lifetime.Windows.Contains(modal)&&File.Exists(store.ConfigPath(config.Sop.Name))&&callbacks==1,
"Prism关闭按钮确认后保存一次并正常关闭");
+ // 从磁盘回读,确认关闭时保存也会自动记录本地修订日期。
+ var saved = SopHelper.Engine.Sop.SopConfigLoader.Load(store.ConfigPath(config.Sop.Name));
+ Check(saved.Sop.RevisionDate == DateTime.Today.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
+ "保存配方后写入本地修订日期");
dialogs.ShowDialog("RecipeEditorDialog",new DialogParameters{{"directory",store.RecipesDirectory},{"new",false},{"config",config},
{"path",store.ConfigPath(config.Sop.Name)}},_=>{});
await Task.Delay(80);