Class UndoManager
The UndoManager class observes and records model changes and supports undo and redo operations.
Namespace: StockSharp.Xaml.Diagram.GXDiagram.Model
Assembly: StockSharp.Xaml.Diagram.dll
Syntax
public class UndoManager : Object
Constructors
UndoManager()
Create a UndoManager that is ready to record model modifications, but that does not know about any models yet.
Declaration
public UndoManager()
Properties
ChecksTransactionLevel
Gets or sets whether this undo manager will output warnings to Trace listeners when model changes occur outside of a transaction.
Declaration
public bool ChecksTransactionLevel { get; set; }
Property Value
Type | Description |
---|---|
Boolean | This defaults to false. |
CompoundEdits
Gets a list of all of the compound edits.
Declaration
public IList<IUndoableEdit> CompoundEdits { get; }
Property Value
Type | Description |
---|---|
IList<IUndoableEdit> | This will be a |
CurrentEdit
Gets the current compound edit for recording additional model change events.
Declaration
public UndoManager.CompoundEdit CurrentEdit { get; set; }
Property Value
Type | Description |
---|---|
UndoManager.CompoundEdit |
Remarks
This is initialized and augmented by HandleModelChanged(Object, ModelChangedEventArgs) before it is added to CompoundEdits by a top-level call to CommitTransaction(String).
CurrentTransactionName
Gets the current transaction name given by StartTransaction(String).
Declaration
public string CurrentTransactionName { get; }
Property Value
Type | Description |
---|---|
String | If no transaction is ongoing, this will be an empty string. |
EditToRedo
Gets the current IUndoableEdit to be redone, or null if there is none.
Declaration
public IUndoableEdit EditToRedo { get; }
Property Value
Type | Description |
---|---|
IUndoableEdit |
See Also
EditToUndo
Gets the current IUndoableEdit to be undone, or null if there is none.
Declaration
public IUndoableEdit EditToUndo { get; }
Property Value
Type | Description |
---|---|
IUndoableEdit |
See Also
IsUndoingRedoing
Declaration
public bool IsUndoingRedoing { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
When this property is true, CanUndo() and CanRedo() will be false. To avoid confusion, HandleModelChanged(Object, ModelChangedEventArgs) ignores all model change events when this property is true.
MaximumEditCount
Gets or sets the maximum number of compound edits that this undo manager will remember.
Declaration
public int MaximumEditCount { get; set; }
Property Value
Type | Description |
---|---|
Int32 | If the value is negative, no limit is assumed. A new value of zero is treated as if the new value were one. The initial value is 999. |
Remarks
This property is useful in helping limit the memory consumption of typical application usage. But note that this only limits the number of compound edits, not the size of any individual UndoManager.CompoundEdit, which may still have an unlimited number of ModelChangedEventArgss.
Decreasing this value will not necessarily remove any existing edits if there currently exist more edits in CompoundEdits than the new value would allow.
Models
Gets a list of models for which this UndoManager is recording undo/redo information.
Declaration
public IEnumerable<IDiagramModel> Models { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IDiagramModel> |
Remarks
You can manipulate this list explicitly by calling AddModel(IDiagramModel) and RemoveModel(IDiagramModel). Setting UndoManager automatically calls these methods. Undo() and Redo() use this list to call RaiseChanged(ModelChangedEventArgs) with notices about starting and ending undo and redo actions, and about starting/finishing/rollingback edits.
NestedTransactionNames
Gets a stack of ongoing transaction names.
Declaration
public IList<string> NestedTransactionNames { get; }
Property Value
Type | Description |
---|---|
IList<String> |
Remarks
The outermost transaction name will be the first item in the list. The last one will be the name of the most recent (nested) call to StartTransaction(String).
TransactionLevel
Gets the current transaction level.
Declaration
public int TransactionLevel { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 | This value is zero when no transaction is in progress. The initial value is zero. StartTransaction(String) will increment this value; EndTransaction(Boolean, String) will decrement it. When this value is greater than zero, CanUndo() and CanRedo() will be false, because additional logically related model change events may occur. |
UndoEditIndex
Gets the index into CompoundEdits for the current undoable edit.
Declaration
public int UndoEditIndex { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 | -1 if there's no undoable edit to be undone. |
Methods
AddModel(IDiagramModel)
Make sure this undo manager knows about a IDiagramModel for which it is receiving model Changed event notifications.
Declaration
public virtual void AddModel(IDiagramModel model)
Parameters
Type | Name | Description |
---|---|---|
IDiagramModel | model |
Remarks
This just adds model
to the list of Models.
See Also
CanRedo()
This predicate is true when one can call Redo().
Declaration
public virtual bool CanRedo()
Returns
Type | Description |
---|---|
Boolean |
Remarks
In order to be able to perform a redo, a transaction must not be in progress, nor an undo or a redo. Furthermore there must be an EditToRedo that itself is ready to be redone, because its CanRedo() predicate is true.
See Also
CanUndo()
This predicate is true when one can call Undo().
Declaration
public virtual bool CanUndo()
Returns
Type | Description |
---|---|
Boolean |
Remarks
In order to be able to perform an undo, a transaction must not be in progress, nor an undo or a redo. Furthermore there must be an EditToUndo that itself is ready to be undone, because its CanUndo() predicate is true.
See Also
Clear()
Clear all of the UndoManager.CompoundEdits and reset all other state.
Declaration
public virtual void Clear()
Remarks
However, this does not forget the models that this undo manager is managing.
CommitCompoundEdit(UndoManager.CompoundEdit)
This method is called by EndTransaction(Boolean, String) when committing a compound edit.
Declaration
protected virtual UndoManager.CompoundEdit CommitCompoundEdit(UndoManager.CompoundEdit cedit)
Parameters
Type | Name | Description |
---|---|---|
UndoManager.CompoundEdit | cedit | the CurrentEdit; this may be null if there had been no changes at commit time |
Returns
Type | Description |
---|---|
UndoManager.CompoundEdit | By default, the unmodified |
Remarks
You may wish to override this method in order to perform optimizations, such as removing duplicate or unnecessary ModelChangedEventArgss.
CommitTransaction(String)
Just call EndTransaction(Boolean, String), committing the current transaction, with the presentation name for the transaction.
Declaration
public bool CommitTransaction(string tname)
Parameters
Type | Name | Description |
---|---|---|
String | tname | the transaction name |
Returns
Type | Description |
---|---|
Boolean | the value of the call to EndTransaction(Boolean, String) |
EndTransaction(Boolean, String)
Stop the current transaction, either rolling it back or committing it.
Declaration
protected virtual bool EndTransaction(bool commit, string tname)
Parameters
Type | Name | Description |
---|---|---|
Boolean | commit | true to terminate the transaction normally; false to abort it and rollback the existing edits |
String | tname | the internal locale-neutral name for the transaction |
Returns
Type | Description |
---|---|
Boolean | true for a committed top-level transaction |
Remarks
If this call stops a top-level transaction, a value of false for
commit
just undoes and discards the information in the
CurrentEdit.
If commit
is true for a top-level transaction,
we mark the CurrentEdit complete,
call CommitCompoundEdit(UndoManager.CompoundEdit),
and add the resulting UndoManager.CompoundEdit
to the list of compound edits that this undo manager is recording.
Committing a transaction when there have been some undos without corresponding redos will throw away the compound edits holding changes that happened after the current state, before adding this new compound edit to the undo manager's list of edits.
This method raises a Changed event
for each of this undo manager's Models,
with a hint of CommittedTransaction,
and with a OldValue
that is the UndoManager.CompoundEdit
that has been added to the list of CompoundEdits.
Similarly, if the transaction is aborted, either because commit
is false or because there is no CurrentEdit to commit,
all of the Models get a RolledBackTransaction
Changed event. The values passed in the ModelChangedEventArgs
may all be null, however.
FindPrimaryObject(IUndoableEdit)
Given an IUndoableEdit return an edited object that represents what was modified.
Declaration
public virtual object FindPrimaryObject(IUndoableEdit edit)
Parameters
Type | Name | Description |
---|---|---|
IUndoableEdit | edit | an IUndoableEdit, usually either a ModelChangedEventArgs or a UndoManager.CompoundEdit |
Returns
Type | Description |
---|---|
Object | typically a StockSharp.Xaml.Diagram.GXDiagram.Node or a StockSharp.Xaml.Diagram.GXDiagram.Link,
but this may be null if there is no such object,
perhaps because a model property was modified,
or because there were no real edits in the argument |
HandleModelChanged(Object, ModelChangedEventArgs)
Create an IUndoableEdit for a Changed event.
Declaration
public virtual void HandleModelChanged(object sender, ModelChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
Object | sender | |
ModelChangedEventArgs | e |
Remarks
This calls SkipEvent(ModelChangedEventArgs) if for some reason we should ignore
the e
.
This then creates a ModelChangedEventArgs and adds it to the
CurrentEdit, a UndoManager.CompoundEdit which it allocates
if needed.
This method always ignores all Changed events while we are performing an
Undo() or Redo().
Redo()
Restore the state of some models to after the current IUndoableEdit.
Declaration
public virtual void Redo()
Remarks
This calls Redo() on the current EditToRedo. This will raise a Changed event with a hint of StartingRedo before actually performing the redo, and will raise a Changed event with a hint of FinishedRedo afterwards. The Data is the UndoManager.CompoundEdit that was the value of EditToRedo before calling Redo.
See Also
RemoveModel(IDiagramModel)
Call this method to inform this undo manager that it no longer will be notified of model Changed events.
Declaration
public virtual void RemoveModel(IDiagramModel model)
Parameters
Type | Name | Description |
---|---|---|
IDiagramModel | model |
Remarks
This just removes model
from the list of Models.
See Also
RollbackTransaction()
Just call EndTransaction(Boolean, String), rolling back the current transaction.
Declaration
public bool RollbackTransaction()
Returns
Type | Description |
---|---|
Boolean | the value of the call to EndTransaction(Boolean, String) |
SkipEvent(ModelChangedEventArgs)
This predicate is responsible for deciding if a ModelChangedEventArgs is not interesting enough to be recorded.
Declaration
protected virtual bool SkipEvent(ModelChangedEventArgs evt)
Parameters
Type | Name | Description |
---|---|---|
ModelChangedEventArgs | evt |
Returns
Type | Description |
---|---|
Boolean | normally false, which causes the given event to be remembered; but true for negative valued enumerations of ModelChange. |
StartTransaction(String)
Begin a transaction, where the changes are held by a UndoManager.CompoundEdit.
Declaration
public virtual bool StartTransaction(string tname)
Parameters
Type | Name | Description |
---|---|---|
String | tname |
Returns
Type | Description |
---|---|
Boolean | true if starting a top-level transaction |
Remarks
Transactions can be nested:
Nested transactions will share the same compound edit as the top-level one. This will raise a Changed event for each of the Models, with a hint of StartedTransaction.
See Also
ToString()
For debugging.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Undo()
Restore the state of some models to before the current IUndoableEdit.
Declaration
public virtual void Undo()
Remarks
This calls Undo() on the current EditToUndo. This will raise a Changed event with a hint of StartingUndo before actually performing the undo, and will raise a Changed event with a hint of FinishedUndo afterwards. The Data is the UndoManager.CompoundEdit that was the value of EditToUndo before calling Undo.