[]
Spread.Commands.CommandManager
• new CommandManager(context
)
Represents a command manager.
Name | Type | Description |
---|---|---|
context |
Object |
The execution context for all commands in the command manager. |
▸ execute(commandOptions
): boolean
Executes a command and adds the command to UndoManager.
example
//For example, the following code executes the autoFitColumn command.
var spread = GC.Spread.Sheets.findControl(document.getElementById("ss"));
spread.commandManager().execute({cmd: "autoFitColumn", sheetName: "Sheet1", columns: [{col: 1}], rowHeader: false, autoFitType: GC.Spread.Sheets.AutoFitType.cell});
Name | Type | Description |
---|---|---|
commandOptions |
Object |
The options for the command. |
boolean
The execute command result.
▸ register(name
, command
, key?
, ctrl?
, shift?
, alt?
, meta?
): void
Registers a command with the command manager.
example
//For example, the following code registers the changeBackColor command and then executes the command.
var command = {
canUndo: true,
execute: function (context, options, isUndo) {
var Commands = GC.Spread.Sheets.Commands;
options.cmd = "changeBackColor";
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
var sheet = context.getSheetFromName(options.sheetName);
var cell = sheet.getCell(options.row, options.col);
cell.backColor(options.backColor);
Commands.endTransaction(context, options);
return true;
}
}
};
var spread = GC.Spread.Sheets.findControl(document.getElementById("ss"));
var commandManager = spread.commandManager();
commandManager.register("changeBackColor", command);
commandManager.execute({cmd: "changeBackColor", sheetName: spread.getSheet(0).name(), row: 1, col: 2, backColor: "red"});
Name | Type | Description |
---|---|---|
name |
string |
The name of the command. |
command |
Object |
The object that defines the command. |
key? |
number |
The key code. |
ctrl? |
boolean |
true if the command uses the Ctrl key; otherwise, false . |
shift? |
boolean |
true if the command uses the Shift key; otherwise, false . |
alt? |
boolean |
true if the command uses the Alt key; otherwise, false . |
meta? |
boolean |
true if the command uses the Command key on the Macintosh or the Windows key on Microsoft Windows; otherwise, false . |
void
▸ setShortcutKey(commandName
, key?
, ctrl?
, shift?
, alt?
, meta?
): void
Binds a shortcut key to a command.
example
//This example changes the behavior of default keys.
var activeSheet = spread.getActiveSheet();
//Change the default Up arrow key action to "Page Up" for the active cell.
spread.commandManager().setShortcutKey('navigationPageUp', GC.Spread.Commands.Key.up, false, false, false, false);
//Change the default Down arrow key action to "Page Down" for the active cell.
spread.commandManager().setShortcutKey('navigationPageDown', GC.Spread.Commands.Key.down, false, false, false, false);
Name | Type | Description |
---|---|---|
commandName |
string |
The command name, setting commandName to undefined removes the bound command of the shortcut key. |
key? |
number |
The key code, setting the key code to undefined removes the shortcut key of the command. |
ctrl? |
boolean |
true if the command uses the Ctrl key; otherwise, false . |
shift? |
boolean |
true if the command uses the Shift key; otherwise, false . |
alt? |
boolean |
true if the command uses the Alt key; otherwise, false . |
meta? |
boolean |
true if the command uses the Command key on the Macintosh or the Windows key on Microsoft Windows; otherwise, false . |
void