-
Notifications
You must be signed in to change notification settings - Fork 2
/
BaseUiItemsProvider.ts
164 lines (148 loc) · 4.47 KB
/
BaseUiItemsProvider.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module UiProvider
*/
import { StageUsage } from "../frontstage/StageUsage";
import type { StagePanelLocation } from "../stagepanels/StagePanelLocation";
import type { StagePanelSection } from "../stagepanels/StagePanelSection";
import type { StatusBarItem } from "../statusbar/StatusBarItem";
import type {
ToolbarItem,
ToolbarOrientation,
ToolbarUsage,
} from "../toolbar/ToolbarItem";
import type { Widget } from "../widgets/Widget";
import { UiItemsManager } from "./UiItemsManager";
import type { UiItemsProvider } from "./UiItemsProvider";
/** Base implementation of a UiItemsProvider. The base class allows the user to pass in a function that is used to determine if the
* active stage should be provided items. Derived provider classes should override the `xxxInternal` methods to provide items.
* @public
*/
export class BaseUiItemsProvider implements UiItemsProvider {
/*
* @param providerId - unique identifier for this instance of the provider. This is required in case separate packages want
* to set up custom stage with their own subset of standard tools.
* @param isSupportedStage - optional function that will be called to determine if tools should be added to current stage. If not set and
* the current stage's `usage` is set to `StageUsage.General` then the provider will add items to frontstage.
*/
constructor(
protected _providerId: string,
public isSupportedStage?: (
stageId: string,
stageUsage: string,
stageAppData?: any,
provider?: UiItemsProvider
) => boolean
) {}
public get id(): string {
return this._providerId;
}
public onUnregister(): void {}
public unregister() {
UiItemsManager.unregister(this._providerId);
}
public provideToolbarItemsInternal(
_stageId: string,
_stageUsage: string,
_toolbarUsage: ToolbarUsage,
_toolbarOrientation: ToolbarOrientation,
_stageAppData?: any
): ToolbarItem[] {
return [];
}
public provideToolbarItems(
stageId: string,
stageUsage: string,
toolbarUsage: ToolbarUsage,
toolbarOrientation: ToolbarOrientation,
stageAppData?: any
): ToolbarItem[] {
let provideToStage = false;
if (this.isSupportedStage) {
provideToStage = this.isSupportedStage(
stageId,
stageUsage,
stageAppData,
this
);
} else {
provideToStage = stageUsage === StageUsage.General.valueOf();
}
return provideToStage
? this.provideToolbarItemsInternal(
stageId,
stageUsage,
toolbarUsage,
toolbarOrientation,
stageAppData
)
: [];
}
public provideStatusBarItemsInternal(
_stageId: string,
_stageUsage: string,
_stageAppData?: any
): StatusBarItem[] {
return [];
}
public provideStatusBarItems(
stageId: string,
stageUsage: string,
stageAppData?: any
): StatusBarItem[] {
let provideToStage = false;
if (this.isSupportedStage) {
provideToStage = this.isSupportedStage(
stageId,
stageUsage,
stageAppData,
this
);
} else {
provideToStage = stageUsage === StageUsage.General.valueOf();
}
return provideToStage
? this.provideStatusBarItemsInternal(stageId, stageUsage, stageAppData)
: [];
}
public provideWidgetsInternal(
_stageId: string,
_stageUsage: string,
_location: StagePanelLocation,
_section?: StagePanelSection,
_stageAppData?: any
): Widget[] {
return [];
}
public provideWidgets(
stageId: string,
stageUsage: string,
location: StagePanelLocation,
section?: StagePanelSection,
stageAppData?: any
): ReadonlyArray<Widget> {
let provideToStage = false;
if (this.isSupportedStage) {
provideToStage = this.isSupportedStage(
stageId,
stageUsage,
stageAppData,
this
);
} else {
provideToStage = stageUsage === StageUsage.General.valueOf();
}
return provideToStage
? this.provideWidgetsInternal(
stageId,
stageUsage,
location,
section,
stageAppData
)
: [];
}
}