-
Notifications
You must be signed in to change notification settings - Fork 210
/
UiProviderTool.ts
128 lines (116 loc) · 4.54 KB
/
UiProviderTool.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
/** @module Tools */
import {
Tool, PluginUiProvider, PluginUiManager, UiItemNode,
} from "@bentley/imodeljs-frontend";
import {
ActionItemInsertSpec, GroupItemInsertSpec,
ToolbarItemInsertSpec, ToolbarItemType, BadgeType, ConditionalDisplayType,
} from "@bentley/ui-abstract";
import { SampleAppIModelApp, SampleAppUiActionId } from "../index";
/** alpha test code */
class TestUiProvider implements PluginUiProvider {
public readonly id = "TestUiProvider";
public provideToolbarItems(toolBarId: string, _itemIds: UiItemNode): ToolbarItemInsertSpec[] {
// tslint:disable-next-line: no-console
// console.log(`Requesting tools for toolbar ${toolBarId}`);
if ("[ViewsFrontstage]ToolWidget-horizontal" === toolBarId) {
const simpleActionSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
itemId: "simple-test-action-tool",
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "simple-test-action-tool",
};
const childActionSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
itemId: "child-test-action-tool",
condition: {
type: ConditionalDisplayType.Visibility,
testFunc: (): boolean => SampleAppIModelApp.getTestProperty() !== "HIDE",
syncEventIds: [SampleAppUiActionId.setTestProperty],
},
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "child-test-action-tool",
};
const nestedActionSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
parentToolGroupId: "tool-formatting-setting",
itemId: "nested-test-action-tool",
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "test action tool (nested)",
};
const groupSpec: GroupItemInsertSpec = {
itemType: ToolbarItemType.GroupButton,
itemId: "test-tool-group",
badge: BadgeType.TechnicalPreview,
icon: "icon-developer",
label: "test group",
items: [childActionSpec, simpleActionSpec],
};
return [simpleActionSpec, nestedActionSpec, groupSpec];
} else if ("[ViewsFrontstage]NavigationWidget-horizontal" === toolBarId) {
const navHorizontalSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
itemId: "nav1-test-action-tool",
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "test action tool (navH)",
};
return [navHorizontalSpec];
} else if ("[ViewsFrontstage]NavigationWidget-vertical" === toolBarId) {
const navVerticalSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
itemId: "nav2-test-action-tool",
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "test action tool (navV)",
};
return [navVerticalSpec];
}
return [];
}
}
/** An Immediate Tool that toggles the test ui provider defined above. */
export class UiProviderTool extends Tool {
public static testPluginLoaded = "";
public static toolId = "TestUiProvider";
public run(_args: any[]): boolean {
if (UiProviderTool.testPluginLoaded.length > 0) {
PluginUiManager.unregister(UiProviderTool.testPluginLoaded);
UiProviderTool.testPluginLoaded = "";
} else {
const testUiProvider = new TestUiProvider();
PluginUiManager.register(testUiProvider);
UiProviderTool.testPluginLoaded = testUiProvider.id;
}
return true;
}
}
// used to test loading Plugin that provides Ui items at startup
const testPluginLoadedAtStartup = false;
if (testPluginLoadedAtStartup) {
const uiProvider = new TestUiProvider();
PluginUiManager.register(uiProvider);
UiProviderTool.testPluginLoaded = uiProvider.id;
}