-
Notifications
You must be signed in to change notification settings - Fork 2
/
ToolItemDef.ts
60 lines (53 loc) · 1.76 KB
/
ToolItemDef.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*---------------------------------------------------------------------------------------------
* 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 { Tool } from "@itwin/core-frontend";
import { IModelApp } from "@itwin/core-frontend";
import type { OnItemExecutedFunc } from "@itwin/appui-abstract";
import { ActionButtonItemDef } from "./ActionButtonItemDef";
import type { ToolItemProps } from "./ItemProps";
/** An Item that starts the execution of a Tool.
* @public
*/
export class ToolItemDef extends ActionButtonItemDef {
public toolId: string = "";
constructor(
toolItemProps: ToolItemProps,
onItemExecuted?: OnItemExecutedFunc
) {
super(toolItemProps, onItemExecuted);
if (toolItemProps.execute) {
this._commandHandler = {
execute: toolItemProps.execute,
parameters: toolItemProps.parameters,
getCommandArgs: toolItemProps.getCommandArgs,
};
}
this.toolId = toolItemProps.toolId;
}
public get id(): string {
return this.toolId;
}
/** Create a ToolItemDef that will run a registered tool. */
public static getItemDefForTool(
tool: typeof Tool,
icon?: string,
...args: any[]
): ToolItemDef {
return new ToolItemDef({
toolId: tool.toolId,
icon: icon
? icon
: tool.iconSpec && tool.iconSpec.length > 0
? tool.iconSpec
: undefined,
label: () => tool.flyover,
description: () => tool.description,
execute: async () => IModelApp.tools.run(tool.toolId, ...args),
});
}
}