using System.ComponentModel; namespace UndoTree; internal sealed class UndoTreeSaveWatcher : IDisposable { readonly UndoTreeHistory history; readonly UndoTreeHostModel host; public UndoTreeSaveWatcher(UndoTreeHistory history, UndoTreeHostModel host) { this.history = history; this.host = host; host.Model.PropertyChanged += Model_PropertyChanged; } public void Dispose() => host.Model.PropertyChanged -= Model_PropertyChanged; void Model_PropertyChanged(object? sender, PropertyChangedEventArgs e) { if (e.PropertyName == UndoTreeHostModel.SavedFlagName && host.IsSaved) UndoTreeDispatch.Post(history.MarkSaved); } }