4 using System.Collections.Generic;
7 using SiliconStudio.ActionStack;
8 using SiliconStudio.Core.Extensions;
9 using SiliconStudio.Presentation.Services;
10 using SiliconStudio.Presentation.ViewModel.ActionStack;
12 namespace SiliconStudio.Presentation.ViewModel
20 private readonly HashSet<ViewModelActionItem> changes =
new HashSet<ViewModelActionItem>();
21 private readonly List<IDirtiableViewModel> dependencies =
new List<IDirtiableViewModel>();
29 : base(serviceProvider)
34 public bool IsDirty {
get {
return isDirty; }
protected set { var oldValue = isDirty; SetValueUncancellable(ref isDirty, value); OnDirtyFlagSet(oldValue, value); } }
45 foreach (var dependency
in dependencies)
46 dependency.DirtinessChanged -= DependencyDirtinessChanged;
52 if (changes.Contains(actionItem))
throw new ArgumentException(
@"The given action item is already registered.",
"actionItem");
53 changes.Add(actionItem);
60 bool removed = changes.Remove(actionItem);
61 if (!removed)
throw new ArgumentException(
@"The given action item was not registered.",
"actionItem");
74 if (dependencies.Contains(dirtiable))
throw new ArgumentException(
@"The given dirtiable object is already registered as a dependency.",
"dirtiable");
75 dependencies.Add(dirtiable);
76 dirtiable.DirtinessChanged += DependencyDirtinessChanged;
82 dirtiable.DirtinessChanged -= DependencyDirtinessChanged;
83 bool removed = dependencies.Remove(dirtiable);
84 if (!removed)
throw new ArgumentException(
@"The given dirtiable object was not registered as a dependency.",
"dirtiable");
92 private void DependencyDirtinessChanged(
object sender,
EventArgs e)
97 private void UpdateDirtiness()
99 bool previousValue = IsDirty;
100 IsDirty = changes.Any(x => x.IsSaved != x.IsDone) || dependencies.Any(x => x.IsDirty);
101 var handler = DirtinessChanged;
102 if (previousValue != IsDirty && handler != null)
104 handler(
this,
new DirtinessChangedEventArgs(IsDirty));
An interface that represents an object which can be in a dirty state (modified since last save)...
virtual void RegisterActionItem(ViewModelActionItem actionItem)
Register a ViewModelActionItem object to this dirtiable object. A registered action item can modify t...
virtual void DiscardActionItem(ViewModelActionItem actionItem)
Discard a previously registered ViewModelActionItem. The action item to discard.The given action item...
DirtiableEditableViewModel(IViewModelServiceProvider serviceProvider)
Initializes a new instance of the DirtiableEditableViewModel class.
virtual void NotifyActionStackChange(ActionStackChange change)
Notify the IDirtiableViewModel that a registered action item has been modified and thus the dirty sta...
A service provider class for view model objects.
void UnregisterDirtiableDependency(IDirtiableViewModel dirtiable)
Unregister a IDirtiableViewModel as a dependency of the current object. The dirtiable object to unreg...
virtual void OnDirtyFlagSet(bool oldValue, bool newValue)
An abstact class that inherits from ActionItem and can be used to manage actions related to an IDirti...
This class is an implementation of the DispatcherViewModel class that supports undo/redo of property ...
EventHandler< DirtinessChangedEventArgs > DirtinessChanged
void RegisterDirtiableDependency(IDirtiableViewModel dirtiable)
Register a IDirtiableViewModel as a dependency of the current object. When a registered dependency ob...
An implementation of the EditableViewModel that is also itself an IDirtiableViewModel. The Dirtiables property returns an enumerable containing the instance itself.