-
Notifications
You must be signed in to change notification settings - Fork 2
/
RestoreLayoutTool.ts
79 lines (71 loc) · 2.51 KB
/
RestoreLayoutTool.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Tools
*/
import {
IModelApp,
NotifyMessageDetails,
OutputMessagePriority,
Tool,
} from "@itwin/core-frontend";
import type { FrontstageDef } from "../frontstage/FrontstageDef";
import { InternalFrontstageManager } from "../frontstage/InternalFrontstageManager";
import { UiFramework } from "../UiFramework";
import svgViewLayouts from "@bentley/icons-generic/icons/view-layouts.svg";
/**
* Immediate tool that will reset the layout to that specified in the stage definition. A stage Id
* may be passed in, if not the active stage is used. The stage Id is case sensitive.
* @public
*/
export class RestoreFrontstageLayoutTool extends Tool {
public static override toolId = "RestoreFrontstageLayout";
public static override iconSpec = svgViewLayouts;
// istanbul ignore next
public static override get minArgs() {
return 0;
}
// istanbul ignore next
public static override get maxArgs() {
return 1;
}
public override async run(frontstageId?: string): Promise<boolean> {
let frontstageDef: FrontstageDef | undefined;
if (frontstageId) {
frontstageDef = await UiFramework.frontstages.getFrontstageDef(
frontstageId
);
} else {
frontstageDef = UiFramework.frontstages.activeFrontstageDef;
}
if (frontstageDef) frontstageDef.restoreLayout();
else
IModelApp.notifications.outputMessage(
new NotifyMessageDetails(
OutputMessagePriority.Info,
UiFramework.translate("tools.RestoreFrontstageLayout.noStageFound")
)
);
return true;
}
public override async parseAndRun(...args: string[]): Promise<boolean> {
return this.run(args[0]);
}
}
/**
* Immediate tool that will reset the layout of all frontstages to that specified in the stage definition.
* @public
*/
export class RestoreAllFrontstagesTool extends Tool {
public static override toolId = "RestoreAllFrontstages";
public static override iconSpec = svgViewLayouts;
public override async run() {
const frontstages = InternalFrontstageManager.frontstageDefs;
for (const [, frontstage] of frontstages) {
frontstage.restoreLayout();
}
return true;
}
}