Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit 222f421

Browse files
committed
add layout methods to command palette
1 parent b060477 commit 222f421

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/features/autoLayout/command.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import { Command, CommandExecutionContext, SModelRootImpl, TYPES } from "sprotty
33
import { Action, IModelLayoutEngine, SGraph, SModelRoot } from "sprotty-protocol";
44
import { LoadDiagramCommand } from "../serialize/load";
55
import { LoadingIndicator } from "../../common/loadingIndicator";
6+
import { LayoutMethod } from "../settingsMenu/LayoutMethod";
7+
import { SettingsManager } from "../settingsMenu/SettingsManager";
68

79
export interface LayoutModelAction extends Action {
810
kind: typeof LayoutModelAction.KIND;
11+
layoutMethod?: LayoutMethod;
912
}
1013
export namespace LayoutModelAction {
1114
export const KIND = "layoutModel";
1215

13-
export function create(): LayoutModelAction {
16+
export function create(method?: LayoutMethod): LayoutModelAction {
1417
return {
1518
kind: KIND,
19+
layoutMethod: method,
1620
};
1721
}
1822
}
@@ -30,6 +34,13 @@ export class LayoutModelCommand extends Command {
3034
private oldModelSchema?: SModelRoot;
3135
private newModel?: SModelRootImpl;
3236

37+
constructor(
38+
@inject(TYPES.Action) private readonly action: LayoutModelAction,
39+
@inject(SettingsManager) private readonly settings: SettingsManager,
40+
) {
41+
super();
42+
}
43+
3344
async execute(context: CommandExecutionContext): Promise<SModelRootImpl> {
3445
this.loadingIndicator?.showIndicator("Layouting...");
3546
this.oldModelSchema = context.modelFactory.createSchema(context.root);
@@ -42,7 +53,13 @@ export class LayoutModelCommand extends Command {
4253
// Thankfully the node implementation classes have all needed properties as well.
4354
// So we can just force cast the graph from the loaded version into the "json graph schema".
4455
// Using of the "bounds" property that the implementation classes have is done using DfdElkLayoutEngine.
56+
const oldMethod = this.settings.layoutMethod;
57+
if (this.action.layoutMethod) {
58+
this.settings.layoutMethod = this.action.layoutMethod;
59+
}
4560
const newModel = await this.layoutEngine.layout(context.root as unknown as SGraph);
61+
this.settings.layoutMethod = oldMethod;
62+
4663
// Here we need to cast back.
4764
this.newModel = newModel as unknown as SModelRootImpl;
4865
this.loadingIndicator?.hideIndicator();

src/features/commandPalette/commandPaletteProvider.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { LoadDFDandDDAction } from "../serialize/loadDFDandDD";
1313
import { LoadPalladioAction } from "../serialize/loadPalladio";
1414
import { SaveImageAction } from "../serialize/image";
1515
import { SettingsManager } from "../settingsMenu/SettingsManager";
16+
import { Action } from "sprotty-protocol";
17+
import { LayoutMethod } from "../settingsMenu/LayoutMethod";
1618

1719
/**
1820
* Provides possible actions for the command palette.
@@ -51,11 +53,33 @@ export class ServerCommandPaletteActionProvider implements ICommandPaletteAction
5153

5254
new LabeledAction("Load default diagram", [LoadDefaultDiagramAction.create(), commitAction], "clear-all"),
5355
new LabeledAction("Fit to Screen", [fitToScreenAction], "screen-normal"),
54-
new LabeledAction(
56+
new FolderAction(
5557
"Layout diagram (Method: " + this.settings.layoutMethod + ")",
56-
[LayoutModelAction.create(), commitAction, fitToScreenAction],
58+
[
59+
new LabeledAction(
60+
"Layout diagram (Method: Lines)",
61+
[LayoutModelAction.create(LayoutMethod.LINES), commitAction, fitToScreenAction],
62+
"grabber",
63+
),
64+
new LabeledAction(
65+
"Layout diagram (Method: Wrapping Lines)",
66+
[LayoutModelAction.create(LayoutMethod.WRAPPING), commitAction, fitToScreenAction],
67+
"word-wrap",
68+
),
69+
new LabeledAction(
70+
"Layout diagram (Method: Circles)",
71+
[LayoutModelAction.create(LayoutMethod.CIRCLES), commitAction, fitToScreenAction],
72+
"circle-large",
73+
),
74+
],
5775
"layout",
76+
[LayoutModelAction.create(), commitAction, fitToScreenAction],
5877
),
78+
/*new LabeledAction(
79+
"Layout diagram (Method: " + this.settings.layoutMethod + ")",
80+
[LayoutModelAction.create(), commitAction, fitToScreenAction],
81+
"layout",
82+
),*/
5983
];
6084
}
6185
}
@@ -65,7 +89,8 @@ export class FolderAction extends LabeledAction {
6589
label: string,
6690
readonly children: LabeledAction[],
6791
icon?: string,
92+
actions: Action[] = [],
6893
) {
69-
super(label, [], icon);
94+
super(label, actions, icon);
7095
}
7196
}

0 commit comments

Comments
 (0)