From 222f42111133dd463e5b50abe3eb6bc4e2a53f6a Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Tue, 19 Aug 2025 09:01:12 +0200 Subject: [PATCH] add layout methods to command palette --- src/features/autoLayout/command.ts | 19 +++++++++++- .../commandPalette/commandPaletteProvider.ts | 31 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/features/autoLayout/command.ts b/src/features/autoLayout/command.ts index d34da57..f7f9050 100644 --- a/src/features/autoLayout/command.ts +++ b/src/features/autoLayout/command.ts @@ -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, }; } } @@ -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 { this.loadingIndicator?.showIndicator("Layouting..."); this.oldModelSchema = context.modelFactory.createSchema(context.root); @@ -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(); diff --git a/src/features/commandPalette/commandPaletteProvider.ts b/src/features/commandPalette/commandPaletteProvider.ts index b09c669..163b576 100644 --- a/src/features/commandPalette/commandPaletteProvider.ts +++ b/src/features/commandPalette/commandPaletteProvider.ts @@ -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. @@ -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", + ),*/ ]; } } @@ -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); } }