Class GridModelCommandManager
This class manages undo and redo commands for a grid.
Implements
Inherited Members
Namespace: Syncfusion.Windows.Controls.Grid
Assembly: Syncfusion.Grid.Wpf.dll
Syntax
public sealed class GridModelCommandManager : NonFinalizeDisposable, IDisposable
Remarks
You access this class from a grid with the CommandStack property of a GridModel instance.
Constructors
GridModelCommandManager(GridModel)
Initializes a GridModelCommandManager and associates it with a GridModel.
Declaration
public GridModelCommandManager(GridModel model)
Parameters
Type | Name | Description |
---|---|---|
GridModel | model | A reference to the parent GridModel. |
Properties
CurrentTransactionCommand
Gets the GridTransactionCommand while the transaction is recorded. If BeginTrans(String) was not called, this will be NULL.
Declaration
public GridTransactionCommand CurrentTransactionCommand { get; }
Property Value
Type |
---|
GridTransactionCommand |
Enabled
Gets or sets a value indicating whether the grid should record undo information or if no undo information should be recorded.
Declaration
public bool Enabled { get; set; }
Property Value
Type |
---|
System.Boolean |
InTransaction
Gets a value indicating whether BeginTrans(String) has been called.
Declaration
public bool InTransaction { get; }
Property Value
Type |
---|
System.Boolean |
IsRecording
Gets a value indicating whether grid is in the default mode that records undo information.
Declaration
public bool IsRecording { get; }
Property Value
Type |
---|
System.Boolean |
Mode
Gets or sets the current undo mode that indicates if the grid is in a regular operation or performing an undo or rollback.
Declaration
public GridCommandMode Mode { get; set; }
Property Value
Type |
---|
GridCommandMode |
Model
Gets the GridModel this object is associated with.
Declaration
public GridModel Model { get; }
Property Value
Type |
---|
GridModel |
RedoStack
Gets the stack with redo commands.
Declaration
public Stack RedoStack { get; }
Property Value
Type |
---|
System.Collections.Stack |
ShouldGenerateUndoInfo
Gets a value indicating whether a grid operation should generate undo information or if undo is temporarily suspended.
Declaration
public bool ShouldGenerateUndoInfo { get; }
Property Value
Type |
---|
System.Boolean |
Remarks
You should call this method from your command if you add operations to the grid that you want to be able to undo.
Examples
The following example checks ShouldGenerateUndoInfo before it pushes saved state onto the undo stack:
if (OnDefaultSizeChanging(new GridDefaultSizeChangingEventArgs(value)))
{
bool success = false;
int savedValue = DefaultSize;
try
{
defaultSize = value;
success = true;
if (model.CommandStack.ShouldGenerateUndoInfo)
model.CommandStack.Push(new GridModelSetDefaultSizeCommand(this, savedValue));
}
finally
{
OnDefaultSizeChanged(new GridDefaultSizeChangedEventArgs(savedValue, success));
}
}
SuspendUndo
Gets or sets a value indicating whether
Declaration
public bool SuspendUndo { get; set; }
Property Value
Type |
---|
System.Boolean |
UndoStack
Gets the stack with undo commands.
Declaration
public Stack UndoStack { get; }
Property Value
Type |
---|
System.Collections.Stack |
Methods
BeginTrans(String)
Starts a transaction that combines several subsequent commands into one transaction.
Declaration
public void BeginTrans(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | A description for the transaction. This text can appear for example as "Undo" information in a menu to give feedback to the user about command on the undo stack. |
Remarks
When you call BeginTrans(String), a GridTransactionCommand is created and the GridModelCommandManager is switched into a special mode where new commands will not be pushed onto the undo stack. Instead all new commands will be pushed into the current GridTransactionCommand instance.
When you call CommitTrans(), the current GridTransactionCommand command will be pushed onto the undo stack and the GridModelCommandManager will switch back to its default behavior where new commands are pushed onto the undo stack.
When you call BeginTrans(String), an internal counter will increase but no additional GridTransactionCommand is created. Only once you call CommitTrans() as many times as you have called BeginTrans(String) will the transaction will be considered complete and the current GridTransactionCommand command will be pushed onto the undo stack.
That means nested transactions are supported. But when you Undo() or Rollback() a transaction, all nested transaction will be treated as one single transaction.
Clear()
Empties both the undo and redo stack.
Declaration
public void Clear()
CommitTrans()
Ends a transaction that was started with a previous BeginTrans(String) call.
Declaration
public void CommitTrans()
Remarks
See BeginTrans(String) for discussion about transaction in a grid.
CreateSelectionStateCommand()
Creates a GridSelectionStateCommand with information about the grid's current selection state.
Declaration
public GridSelectionStateCommand CreateSelectionStateCommand()
Returns
Type | Description |
---|---|
GridSelectionStateCommand | A GridSelectionStateCommand with information about the grid's current selection state. |
Remarks
The GridModel has an internal dirty flag that this method will reset. Only when the user moves the current cell or changes the current selection, will the dirty flag be set.
If the dirty flag was reset and there were no changes to selection, this method will return NULL.
If the dirty flag was True, this method will return the current selection state and reset the dirty flag.
Dispose(Boolean)
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
Push(SyncfusionCommand)
Pushes a command onto the undo stack.
Declaration
public void Push(SyncfusionCommand cmd)
Parameters
Type | Name | Description |
---|---|---|
SyncfusionCommand | cmd | The SyncfusionCommand with undo information. |
Remarks
When the grid is performing an Undo(), the command will be pushed onto the redo stack. Otherwise, commands are pushed onto the undo stack.
Push(SyncfusionCommand, SyncfusionCommand)
Pushes a command together with selection state onto the undo stack.
Declaration
public void Push(SyncfusionCommand cmd, SyncfusionCommand selectionStateCommand)
Parameters
Type | Name | Description |
---|---|---|
SyncfusionCommand | cmd | The SyncfusionCommand with undo information. |
SyncfusionCommand | selectionStateCommand | The command object with selection information created by a CreateSelectionStateCommand() call. |
Redo()
Execute the latest command from the redo stack.
Declaration
public void Redo()
Remarks
If a GridSelectionStateCommand is found, this will also be executed so that selection state will be restored to the same state as it was when the undo / redo command was recorded.
Rollback()
Rolls back a transaction in progress that was started with a previous BeginTrans(String) call.
Declaration
public void Rollback()
Remarks
All commands since a BeginTrans(String) call will be undone.
SetModelInt(GridModel)
Used internally.
Declaration
public void SetModelInt(GridModel model)
Parameters
Type | Name | Description |
---|---|---|
GridModel | model |
Undo()
Execute the latest command from the undo stack.
Declaration
public void Undo()
Remarks
The redo stack will be cleared.
If a GridSelectionStateCommand is found this will also be executed so that selection state will be restored to the same state as it was when the undo command was recorded.