-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppNotificationManager.ts
192 lines (173 loc) · 6.32 KB
/
AppNotificationManager.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Notification
*/
import type { XAndY } from "@itwin/core-geometry";
import type {
ActivityMessageDetails,
MessageBoxIconType,
MessageBoxType,
MessageBoxValue,
NotifyMessageDetails,
ToolAssistanceInstructions,
ToolTipOptions,
} from "@itwin/core-frontend";
import {
ActivityMessageEndReason,
NotificationManager,
ToolAssistance,
} from "@itwin/core-frontend";
import type { RelativePosition } from "@itwin/appui-abstract";
import { ElementTooltip } from "../feedback/ElementTooltip";
import { UiFramework } from "../UiFramework";
import { MessageManager } from "./MessageManager";
import { PointerMessage } from "./Pointer";
/** Subclass of `NotificationManager` in `@itwin/core-frontend` to be used to initialize `IModelApp`.
*
* This implementation uses themed react components to display alerts, messages, prompts and tooltips.
*
* ```ts
* await IModelApp.startup({
* notifications: new AppNotificationManager()
* });
* ```
* @public
*/
export class AppNotificationManager extends NotificationManager {
/** Output a prompt, given an i18n key.
*/
public override outputPromptByKey(key: string): void {
this.outputPrompt(UiFramework.translate(key));
}
/** Output a prompt to the user. A 'prompt' indicates an action the user should take to proceed.
*/
public override outputPrompt(prompt: string): void {
MessageManager.outputPrompt(prompt);
const mainInstruction = ToolAssistance.createInstruction("", prompt);
const instructions = ToolAssistance.createInstructions(mainInstruction);
MessageManager.setToolAssistance(instructions);
}
/** Output a message and/or alert to the user. */
public override outputMessage(message: NotifyMessageDetails): void {
MessageManager.outputMessage(message);
}
/** Output a MessageBox and wait for response from the user.
* @param mbType The MessageBox type.
* @param message The message to display.
* @param icon The MessageBox icon type.
* @return the response from the user.
*/
public override async openMessageBox(
mbType: MessageBoxType,
message: HTMLElement | string,
icon: MessageBoxIconType
): Promise<MessageBoxValue> {
return MessageManager.openMessageBox(mbType, message, icon);
}
/**
* Set up for activity messages.
* @param details The activity message details.
* @return true if the message was displayed, false if an invalid priority is specified.
*/
public override setupActivityMessage(
details: ActivityMessageDetails
): boolean {
return MessageManager.setupActivityMessageDetails(details);
}
/**
* Output an activity message to the user.
* @param messageText The message text.
* @param percentComplete The percentage of completion.
* @return true if the message was displayed, false if the message could not be displayed.
*/
public override outputActivityMessage(
messageText: HTMLElement | string,
percentComplete: number
): boolean {
return MessageManager.setupActivityMessageValues(
messageText,
percentComplete
);
}
/**
* End an activity message.
* @param reason Reason for the end of the Activity Message.
* @return true if the message was ended successfully, false if the activityMessage could not be ended.
*/
public override endActivityMessage(
reason: ActivityMessageEndReason
): boolean {
let result = false;
switch (reason) {
case ActivityMessageEndReason.Completed:
result = MessageManager.endActivityMessage(true);
break;
case ActivityMessageEndReason.Cancelled:
result = MessageManager.endActivityMessage(false);
break;
}
return result;
}
/** Update message position created with [[OutputMessageType.Pointer]].
* @param displayPoint Point at which to display the Pointer type message.
* @param relativePosition Position relative to displayPoint at which to display the Pointer type message.
*/
public override updatePointerMessage(
displayPoint: XAndY,
relativePosition: RelativePosition
): void {
PointerMessage.updateMessage(displayPoint, relativePosition);
}
/** Hides the Pointer message. */
public override closePointerMessage(): void {
PointerMessage.hideMessage();
}
/** Return true if _showTooltip has an implementation and will display a tooltip. */
public override get isToolTipSupported(): boolean {
return true;
}
/** Return true if the tooltip is currently open. */
public override get isToolTipOpen(): boolean {
return ElementTooltip.isTooltipVisible;
}
/** Clear the ToolTip if it is currently open. If not open, does nothing. */
public override clearToolTip(): void {
// istanbul ignore else
if (this.isToolTipOpen) ElementTooltip.hideTooltip();
}
/** Show a ToolTip window.
* @param el The HTMLElement that anchors the toolTip.
* @param message The message to display inside the ToolTip
* @param pt An optional location, relative to the origin of el, for the ToolTip. If undefined, center of el.
* @param options Options that supply additional information about how the ToolTip should function.
*/
protected override _showToolTip(
el: HTMLElement,
message: HTMLElement | string,
pt?: XAndY,
options?: ToolTipOptions
): void {
ElementTooltip.showTooltip(el, message, pt, options);
}
/** Hide a InputField message. */
public override closeInputFieldMessage(): void {
MessageManager.hideInputFieldMessage();
}
/** Setup tool assistance instructions for a tool. The instructions include the main instruction, which includes the current prompt.
* @param instructions The tool assistance instructions.
* @public
*/
public override setToolAssistance(
instructions: ToolAssistanceInstructions | undefined
) {
MessageManager.outputPrompt(
instructions
? instructions.mainInstruction.text
: /* istanbul ignore next */ ""
);
MessageManager.setToolAssistance(instructions);
}
}