-
Notifications
You must be signed in to change notification settings - Fork 2
/
CommandItemDef.ts
45 lines (39 loc) · 1.4 KB
/
CommandItemDef.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Item
*/
import type { OnItemExecutedFunc } from "@itwin/appui-abstract";
import { ActionButtonItemDef } from "./ActionButtonItemDef";
import type { CommandItemProps } from "./ItemProps";
/** An Item that executes a Command.
* @public
*/
export class CommandItemDef extends ActionButtonItemDef {
private static _sId = 0;
public static commandIdPrefix = "Command-";
public commandId: string = "";
constructor(
commandItemProps: CommandItemProps,
onItemExecuted?: OnItemExecutedFunc
) {
super(commandItemProps, onItemExecuted);
if (commandItemProps.execute) {
this._commandHandler = {
execute: commandItemProps.execute,
parameters: commandItemProps.parameters,
getCommandArgs: commandItemProps.getCommandArgs,
};
}
if (commandItemProps.commandId) this.commandId = commandItemProps.commandId;
else {
CommandItemDef._sId++;
this.commandId = CommandItemDef.commandIdPrefix + CommandItemDef._sId;
}
}
public get id(): string {
return this.commandId;
}
}