/
UiAdmin.ts
318 lines (278 loc) · 16.5 KB
/
UiAdmin.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module UiAdmin
*/
import { BentleyError, BentleyStatus, BeUiEvent } from "@itwin/core-bentley";
import { AbstractMenuItemProps } from "./items/AbstractMenuItemProps";
import { AbstractToolbarProps } from "./items/AbstractToolbarProps";
import { RelativePosition } from "./items/RelativePosition";
import { PropertyDescription } from "./properties/Description";
import { Primitives } from "./properties/PrimitiveTypes";
import { OnCancelFunc, OnItemExecutedFunc, OnNumberCommitFunc, OnValueCommitFunc } from "./utils/callbacks";
import { PropertyRecord } from "./properties/Record";
import { UiDataProvider } from "./dialogs/UiDataProvider";
import { DialogLayoutDataProvider } from "./dialogs/UiLayoutDataProvider";
import { MessagePresenter } from "./notification/MessagePresenter";
interface XAndY { readonly x: number, readonly y: number }
interface BentleyErrorWithCategory extends BentleyError {
category: string;
}
/** The Generic UI Event args contains information useful for any UI message
* @public
*/
export interface GenericUiEventArgs {
uiComponentId: string;
}
/** Optional props to pass to the Dialog control that is generated.
* @public
*/
export interface DialogProps {
/** Indicates whether the user can resize dialog with cursor. */
resizable?: boolean;
/** Indicates whether the user can move dialog with cursor.*/
movable?: boolean;
/** Initial width of dialog. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */
width?: string | number;
/** Initial height of dialog. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */
height?: string | number;
/** Minimum width that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */
minWidth?: string | number;
/** Minimum height that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */
minHeight?: string | number;
/** Maximum width that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */
maxWidth?: string | number;
/** Maximum height that the dialog may be resized to. Displayed in px if value is a number; otherwise, displayed in specified CSS unit. */
maxHeight?: string | number;
}
/** The GenericUiEvent is the base event class for UI events that target a specific component, as identified in uiComponentId.
* @public
*/
export class GenericUiEvent extends BeUiEvent<GenericUiEventArgs> { }
/** Flags that control enabling/disabling certain UI features
* @public
*/
export interface UiFlags {
/** if true then Ctrl+F2 will show popup key-in palette */
allowKeyinPalette?: boolean;
}
/** The UiAdmin controls various UI components and is callable from IModelApp.uiAdmin in the core-frontend package.
* @public
*/
export class UiAdmin {
private _featureFlags: UiFlags = {};
private static _messagePresenter?: MessagePresenter;
/** The MessagePresenter used to display messages. */
public static get messagePresenter(): MessagePresenter {
if (!UiAdmin._messagePresenter) {
const error = new BentleyError(BentleyStatus.ERROR, "UiAdmin.messagePresenter not set") as BentleyErrorWithCategory;
error.category = "messagePresenter";
throw error;
}
return UiAdmin._messagePresenter;
}
public static set messagePresenter(mp: MessagePresenter) {
UiAdmin._messagePresenter = mp;
}
public get featureFlags(): UiFlags {
return { ...this._featureFlags }; // return copy so no direct access to modify value
}
public updateFeatureFlags(uiFlags: UiFlags) {
this._featureFlags = { ...this._featureFlags, ...uiFlags };
}
/** @internal */
public onInitialized() { }
/** Get the cursor X and Y position. */
public get cursorPosition(): XAndY { return { x: 0, y: 0 }; }
/** Create a PointProps object.
* @deprecated in 4.2.x. Please use @core/geometry [[XAndY]] or a custom implementation.
*/
public createXAndY(x: number, y: number): XAndY { return { x, y }; }
/** Determines if focus is set to Home */
public get isFocusOnHome(): boolean { return false; }
/** Sets focus to Home */
public setFocusToHome(): void { }
/** Show a context menu at a particular location.
* @param _menuItemsProps Properties of the menu items to display.
* @param _location Location of the context menu, relative to the origin of htmlElement or the window.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the menu was displayed, false if the menu could not be displayed.
*/
public showContextMenu(_menuItemsProps: AbstractMenuItemProps[], _location: XAndY, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Show a Toolbar at a particular location.
* @param _toolbarProps Properties of the Toolbar to display.
* @param _location Location of the Toolbar, relative to the origin of htmlElement or the window.
* @param _offset Offset of the Toolbar from the location.
* @param _onItemExecuted Function invoked after a Toolbar item is executed
* @param _onCancel Function invoked when the Escape key is pressed or a click occurs outside the Toolbar
* @param _relativePosition Position relative to the given location. Defaults to TopRight.
* @param _htmlElement The HTMLElement that anchors the Toolbar. If undefined, the location is relative to the overall window.
* @return true if the Toolbar was displayed, false if the Toolbar could not be displayed.
*/
public showToolbar(
_toolbarProps: AbstractToolbarProps, _location: XAndY, _offset: XAndY, _onItemExecuted: OnItemExecutedFunc, _onCancel: OnCancelFunc,
_relativePosition?: RelativePosition, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Hides the toolbar. */
public hideToolbar(): boolean { return false; }
/** Show a menu button at a particular location. A menu button opens a context menu.
* @param _id Id of the menu button. Multiple menu buttons may be displayed.
* @param _menuItemsProps Properties of the menu items to display.
* @param _location Location of the context menu, relative to the origin of htmlElement or the window.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the button was displayed, false if the button could not be displayed.
*/
public showMenuButton(_id: string, _menuItemsProps: AbstractMenuItemProps[], _location: XAndY, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Hides a menu button.
* @param _id Id of the menu button. Multiple menu buttons may be displayed.
* @return true if the menu was hidden, false if the menu could not be hidden.
*/
public hideMenuButton(_id: string): boolean { return false; }
/** Show a calculator at a particular location.
* @param _initialValue Value initially displayed in the calculator.
* @param _resultIcon Icon displayed to the left of the value.
* @param _location Location of the calculator, relative to the origin of htmlElement or the window.
* @param _onCommit Function called when the OK button or the Enter key is pressed.
* @param _onCancel Function called when the Cancel button or the Escape key is pressed.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the calculator was displayed, false if the calculator could not be displayed.
*/
public showCalculator(_initialValue: number, _resultIcon: string, _location: XAndY, _onCommit: OnNumberCommitFunc, _onCancel: OnCancelFunc, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Hides the calculator. */
public hideCalculator(): boolean { return false; }
/** Show an input editor for an angle value at a particular location.
* @param _initialValue Value initially displayed in the editor.
* @param _location Location of the editor, relative to the origin of htmlElement or the window.
* @param _onCommit Function called when the OK button or the Enter key is pressed.
* @param _onCancel Function called when the Cancel button or the Escape key is pressed.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the editor was displayed, false if the editor could not be displayed.
*/
public showAngleEditor(_initialValue: number, _location: XAndY, _onCommit: OnNumberCommitFunc, _onCancel: OnCancelFunc, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Show an input editor for a length value at a particular location.
* @param _initialValue Value initially displayed in the editor.
* @param _location Location of the editor, relative to the origin of htmlElement or the window.
* @param _onCommit Function called when the OK button or the Enter key is pressed.
* @param _onCancel Function called when the Cancel button or the Escape key is pressed.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the editor was displayed, false if the editor could not be displayed.
*/
public showLengthEditor(_initialValue: number, _location: XAndY, _onCommit: OnNumberCommitFunc, _onCancel: OnCancelFunc, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Show an input editor for a height value at a particular location.
* @param _initialValue Value initially displayed in the editor.
* @param _location Location of the editor, relative to the origin of htmlElement or the window.
* @param _onCommit Function called when the OK button or the Enter key is pressed.
* @param _onCancel Function called when the Cancel button or the Escape key is pressed.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the editor was displayed, false if the editor could not be displayed.
*/
public showHeightEditor(_initialValue: number, _location: XAndY, _onCommit: OnNumberCommitFunc, _onCancel: OnCancelFunc, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Show an input editor for a primitive value at a particular location.
* @param _initialValue Value initially displayed in the editor.
* @param _propertyDescription Description of the primitive value property.
* @param _location Location of the editor, relative to the origin of htmlElement or the window.
* @param _onCommit Function called when the OK button or the Enter key is pressed.
* @param _onCancel Function called when the Cancel button or the Escape key is pressed.
* @param _htmlElement The HTMLElement that anchors the context menu. If undefined, the location is relative to the overall window.
* @return true if the editor was displayed, false if the editor could not be displayed.
*/
public showInputEditor(_initialValue: Primitives.Value, _propertyDescription: PropertyDescription, _location: XAndY, _onCommit: OnValueCommitFunc, _onCancel: OnCancelFunc, _htmlElement?: HTMLElement): boolean {
return false;
}
/** Hides the input editor. */
public hideInputEditor(): boolean { return false; }
/** Show an HTML element at a particular location.
* @param _displayElement The HTMLElement to display
* @param _location Location of the tool settings, relative to the origin of anchorElement or the window
* @param _offset Offset of the display element from the location
* @param _onCancel Function invoked when the Escape key is pressed or a click occurs outside the display element
* @param _relativePosition Position relative to the given location. Defaults to TopRight.
* @param _anchorElement The HTMLElement that anchors the display element. If undefined, the location is relative to the overall window.
* @return true if the display element was displayed, false if the display element could not be displayed.
*/
public showHTMLElement(
_displayElement: HTMLElement, _location: XAndY, _offset: XAndY, _onCancel: OnCancelFunc,
_relativePosition?: RelativePosition, _anchorElement?: HTMLElement): boolean {
return false;
}
/** Hides the HTML Element. */
public hideHTMLElement(): boolean { return false; }
/** Show a Card containing content, a title and a toolbar at a particular location.
* @param _content The HTMLElement of the content to display
* @param _title Title to display at the top of the card.
* @param _toolbarProps Properties of the Toolbar to display.
* @param _location Location of the Card, relative to the origin of anchorElement or the window.
* @param _offset Offset of the Card from the location.
* @param _onItemExecuted Function invoked after a Toolbar item is executed
* @param _onCancel Function invoked when the Escape key is pressed or a click occurs outside the Card
* @param _relativePosition Position relative to the given location. Defaults to TopRight.
* @param _anchorElement The HTMLElement that anchors the Card. If undefined, the location is relative to the overall window.
* @return true if the Card was displayed, false if the Card could not be displayed.
*/
public showCard(
_content: HTMLElement, _title: string | PropertyRecord | undefined, _toolbarProps: AbstractToolbarProps | undefined,
_location: XAndY, _offset: XAndY, _onItemExecuted: OnItemExecutedFunc, _onCancel: OnCancelFunc,
_relativePosition?: RelativePosition, _anchorElement?: HTMLElement): boolean {
return false;
}
/** Hides the Card. */
public hideCard(): boolean { return false; }
/** Opens a Tool Settings Ui popup at a particular location.
* @param _dataProvider The UiDataProvider for the tool settings
* @param _location Location of the tool settings, relative to the origin of anchorElement or the window
* @param _offset Offset of the tool settings from the location
* @param _onCancel Function invoked when the Escape key is pressed or a click occurs outside the tool settings
* @param _relativePosition Position relative to the given location. Defaults to TopRight.
* @param _anchorElement The HTMLElement that anchors the tool settings. If undefined, the location is relative to the overall window.
* @return true if the tool settings were displayed, false if the tool settings could not be displayed.
*/
public openToolSettingsPopup(
_dataProvider: UiDataProvider, _location: XAndY, _offset: XAndY, _onCancel: OnCancelFunc,
_relativePosition?: RelativePosition, _anchorElement?: HTMLElement): boolean {
return false;
}
/** Closes the Tool Settings Ui popup. */
public closeToolSettingsPopup(): boolean { return false; }
/** Show the Keyin Palette to display all support Tool key-ins.
* @param _htmlElement The HTMLElement that anchors the Keyin Palette. If undefined, the location is relative to the overall window.
* @return true if the Keyin Palette was displayed, false if it could not be displayed.
*/
public showKeyinPalette(_htmlElement?: HTMLElement): boolean { return false; }
/** Hides the Keyin Palette. */
public hideKeyinPalette(): boolean { return false; }
/** Send a UI event */
public static sendUiEvent(args: GenericUiEventArgs) {
UiAdmin.onGenericUiEvent.emit(args);
}
/** GenericUiEvent */
public static readonly onGenericUiEvent = new GenericUiEvent();
/** Opens a Dialog and automatically populates it using the properties defined by the UiDataProvider.
* @param _uiDataProvider The DialogLayoutDataProvider for the dialog
* @param _title Specify title for dialog.
* @param _isModal Specify if the dialog is opened as a modal or modeless.
* @param _id Id of the dialog that is used to close it.
* @param _optionalProps Optional props for Dialog construction.
* @return true if the tool settings were displayed, false if the tool settings could not be displayed.
*/
public openDialog(_uiDataProvider: DialogLayoutDataProvider, _title: string, _isModal: boolean, _id: string,
_optionalProps?: DialogProps): boolean {
return false;
}
/** Closes the Dialog with a given Id. */
public closeDialog(_dialogId: string): boolean { return false; }
}