Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/features/autoLayout/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import { Command, CommandExecutionContext, SModelRootImpl, TYPES } from "sprotty
import { Action, IModelLayoutEngine, SGraph, SModelRoot } from "sprotty-protocol";
import { LoadDiagramCommand } from "../serialize/load";
import { LoadingIndicator } from "../../common/loadingIndicator";
import { LayoutMethod } from "../settingsMenu/LayoutMethod";
import { SettingsManager } from "../settingsMenu/SettingsManager";

export interface LayoutModelAction extends Action {
kind: typeof LayoutModelAction.KIND;
layoutMethod?: LayoutMethod;
}
export namespace LayoutModelAction {
export const KIND = "layoutModel";

export function create(): LayoutModelAction {
export function create(method?: LayoutMethod): LayoutModelAction {
return {
kind: KIND,
layoutMethod: method,
};
}
}
Expand All @@ -30,6 +34,13 @@ export class LayoutModelCommand extends Command {
private oldModelSchema?: SModelRoot;
private newModel?: SModelRootImpl;

constructor(
@inject(TYPES.Action) private readonly action: LayoutModelAction,
@inject(SettingsManager) private readonly settings: SettingsManager,
) {
super();
}

async execute(context: CommandExecutionContext): Promise<SModelRootImpl> {
this.loadingIndicator?.showIndicator("Layouting...");
this.oldModelSchema = context.modelFactory.createSchema(context.root);
Expand All @@ -42,7 +53,13 @@ export class LayoutModelCommand extends Command {
// Thankfully the node implementation classes have all needed properties as well.
// So we can just force cast the graph from the loaded version into the "json graph schema".
// Using of the "bounds" property that the implementation classes have is done using DfdElkLayoutEngine.
const oldMethod = this.settings.layoutMethod;
if (this.action.layoutMethod) {
this.settings.layoutMethod = this.action.layoutMethod;
}
const newModel = await this.layoutEngine.layout(context.root as unknown as SGraph);
this.settings.layoutMethod = oldMethod;

// Here we need to cast back.
this.newModel = newModel as unknown as SModelRootImpl;
this.loadingIndicator?.hideIndicator();
Expand Down
31 changes: 28 additions & 3 deletions src/features/commandPalette/commandPaletteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { LoadDFDandDDAction } from "../serialize/loadDFDandDD";
import { LoadPalladioAction } from "../serialize/loadPalladio";
import { SaveImageAction } from "../serialize/image";
import { SettingsManager } from "../settingsMenu/SettingsManager";
import { Action } from "sprotty-protocol";
import { LayoutMethod } from "../settingsMenu/LayoutMethod";

/**
* Provides possible actions for the command palette.
Expand Down Expand Up @@ -51,11 +53,33 @@ export class ServerCommandPaletteActionProvider implements ICommandPaletteAction

new LabeledAction("Load default diagram", [LoadDefaultDiagramAction.create(), commitAction], "clear-all"),
new LabeledAction("Fit to Screen", [fitToScreenAction], "screen-normal"),
new LabeledAction(
new FolderAction(
"Layout diagram (Method: " + this.settings.layoutMethod + ")",
[LayoutModelAction.create(), commitAction, fitToScreenAction],
[
new LabeledAction(
"Layout diagram (Method: Lines)",
[LayoutModelAction.create(LayoutMethod.LINES), commitAction, fitToScreenAction],
"grabber",
),
new LabeledAction(
"Layout diagram (Method: Wrapping Lines)",
[LayoutModelAction.create(LayoutMethod.WRAPPING), commitAction, fitToScreenAction],
"word-wrap",
),
new LabeledAction(
"Layout diagram (Method: Circles)",
[LayoutModelAction.create(LayoutMethod.CIRCLES), commitAction, fitToScreenAction],
"circle-large",
),
],
"layout",
[LayoutModelAction.create(), commitAction, fitToScreenAction],
),
/*new LabeledAction(
"Layout diagram (Method: " + this.settings.layoutMethod + ")",
[LayoutModelAction.create(), commitAction, fitToScreenAction],
"layout",
),*/
];
}
}
Expand All @@ -65,7 +89,8 @@ export class FolderAction extends LabeledAction {
label: string,
readonly children: LabeledAction[],
icon?: string,
actions: Action[] = [],
) {
super(label, [], icon);
super(label, actions, icon);
}
}