Skip to content

Commit

Permalink
Migrate PRs from eclipsesource/graphical-lsp (eclipse-glsp#12)
Browse files Browse the repository at this point in the history
+Fix eclipse-glsp#401 Node creation  (eclipse-glsp#402)
+ Resolve eclipse-glsp#398 Refactor TypeHints API (eclipse-glsp#399)
+ Resolve eclipse-glsp#396 RouterKind for FeedbackEdge (eclipse-glsp#397)
+ Reuse Sprotty's request/response system and remove custom solution(eclipse-glsp#404)
+ Add support for context menu and harmonize with command palette (eclipse-glsp#405)
  • Loading branch information
tortmayr authored and holkerveen committed Dec 21, 2024
1 parent 1a9c544 commit 52b9e22
Show file tree
Hide file tree
Showing 42 changed files with 925 additions and 662 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"tslint": "^5.5.0",
"typescript": "3.6.4"
},
"resolutions": {
"**/sprotty": "0.8.0-next.1d772ad"
},
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib",
Expand Down
72 changes: 0 additions & 72 deletions src/base/edit-config/edit-config.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/base/model/update-model-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class SetModelActionHandler implements IActionHandler {
return new UpdateModelAction(action.newRoot, false);
}
}

handledActionKinds = [SetModelCommand.KIND];
}

export function isSetModelAction(action: Action): action is SetModelAction {
Expand Down
14 changes: 8 additions & 6 deletions src/features/change-bounds/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ import {
SChildElement,
Selectable,
SModelElement,
SNode,
SParentElement
} from "sprotty/lib";

import { isConfigurableNode, NodeEditConfig } from "../../base/edit-config/edit-config";
export const resizeFeature = Symbol("resizeFeature");

export interface Resizable extends BoundsAware, Selectable {
}

export function isResizable(element: SModelElement): element is SParentElement & Resizable {
return isBoundsAware(element) && isSelectable(element) && element instanceof SParentElement && element.hasFeature(resizeFeature);
}

export enum ResizeHandleLocation {
TopLeft = "top-left",
Expand All @@ -37,10 +43,6 @@ export enum ResizeHandleLocation {
BottomRight = "bottom-right"
}

export function isResizeable(element: SModelElement): element is SNode & SParentElement & BoundsAware & Selectable & NodeEditConfig {
return isConfigurableNode(element) && element.resizable && isBoundsAware(element) && isSelectable(element) && element instanceof SParentElement;
}

export function isBoundsAwareMoveable(element: SModelElement): element is SModelElement & Locateable & BoundsAware {
return isMoveable(element) && isBoundsAware(element);
}
Expand Down
36 changes: 0 additions & 36 deletions src/features/command-palette/action-definitions.ts

This file was deleted.

69 changes: 0 additions & 69 deletions src/features/command-palette/action-provider.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/features/command-palette/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import "../../../css/command-palette.css";
import { ContainerModule } from "inversify";
import { TYPES } from "sprotty/lib";

import { NavigationCommandPaletteActionProvider, ServerCommandPaletteActionProvider } from "./action-provider";
import { ServerCommandPaletteActionProvider } from "./server-command-palette-provider";

const glspCommandPaletteModule = new ContainerModule((bind, unbind, isBound, rebind) => {
bind(TYPES.ICommandPaletteActionProvider).to(NavigationCommandPaletteActionProvider);
bind(ServerCommandPaletteActionProvider).toSelf().inSingletonScope();
const glspCommandPaletteModule = new ContainerModule((bind) => {
bind(TYPES.ICommandPaletteActionProvider).to(ServerCommandPaletteActionProvider);
});

Expand Down
50 changes: 50 additions & 0 deletions src/features/command-palette/server-command-palette-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { inject, injectable } from "inversify";
import { Action, ICommandPaletteActionProvider, LabeledAction, Point, SModelElement, TYPES } from "sprotty/lib";

import { isSelected } from "../../utils/smodel-util";
import { ContextActions, isSetContextActionsAction, RequestContextActions } from "../context-actions/action-definitions";
import { GLSPActionDispatcher } from "../request-response/glsp-action-dispatcher";

export namespace ServerCommandPalette {
export const KEY = "command-palette";
export const TEXT = "text";
export const INDEX = "index";
}

@injectable()
export class ServerCommandPaletteActionProvider implements ICommandPaletteActionProvider {

constructor(@inject(TYPES.IActionDispatcher) protected actionDispatcher: GLSPActionDispatcher) { }

getActions(root: Readonly<SModelElement>, text: string, lastMousePosition?: Point, index?: number): Promise<LabeledAction[]> {
const selectedElementIds = Array.from(root.index.all().filter(isSelected).map(e => e.id));
const requestAction = new RequestContextActions(selectedElementIds, lastMousePosition, {
[ContextActions.UI_CONTROL_KEY]: ServerCommandPalette.KEY,
[ServerCommandPalette.TEXT]: text,
[ServerCommandPalette.INDEX]: index ? index : 0
});
return this.actionDispatcher.requestUntil(requestAction).then(response => this.getPaletteActionsFromResponse(response));
}

getPaletteActionsFromResponse(action: Action): LabeledAction[] {
if (isSetContextActionsAction(action)) {
return action.actions;
}
return [];
}
}
42 changes: 42 additions & 0 deletions src/features/context-actions/action-definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action, generateRequestId, LabeledAction, Point, RequestAction, ResponseAction } from "sprotty/lib";

export namespace ContextActions {
export const UI_CONTROL_KEY = "ui-control";
}

export class RequestContextActions implements RequestAction<SetContextActions> {
static readonly KIND = "requestContextActions";
kind = RequestContextActions.KIND;
constructor(
public readonly selectedElementIds: string[] = [],
public readonly lastMousePosition?: Point,
public readonly args?: { [key: string]: string | number | boolean },
public readonly requestId: string = generateRequestId()) { }
}

export class SetContextActions implements ResponseAction {
static readonly KIND = "setContextActions";
kind = SetContextActions.KIND;
constructor(public readonly actions: LabeledAction[],
public readonly responseId: string = '') { }
}

export function isSetContextActionsAction(action: Action): action is SetContextActions {
return action !== undefined && (action.kind === SetContextActions.KIND)
&& (<SetContextActions>action).actions !== undefined;
}
51 changes: 51 additions & 0 deletions src/features/context-menu/context-menu-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { LabeledAction } from "sprotty";

export interface MenuItem extends LabeledAction {
/** Technical id of the menu item. */
readonly id: string;
/** String indicating the order. */
readonly sortString?: string;
/** String indicating the grouping (separators). Items with equal group will be in the same group. */
readonly group?: string;
/**
* The optional parent id can be used to add this element as a child of another element provided by anohter menu provider.
* The `parentId` must be fully qualified in the form of `a.b.c`, whereas `a`, `b` and `c` are referring to the IDs of other elements.
* Note that this attribute will only be considered for root items of a provider and not for children of provided items.
*/
readonly parentId?: string;
/** Function determining whether the element is enabled. */
readonly isEnabled?: () => boolean;
/** Function determining whether the element is visible. */
readonly isVisible?: () => boolean;
/** Function determining whether the element is toggled on or off. */
readonly isToggled?: () => boolean;
/** Children of this item. If this item has children, they will be added into a submenu of this item. */
children?: MenuItem[];
}

export type Anchor = MouseEvent | { x: number, y: number };

export function toAnchor(anchor: HTMLElement | { x: number, y: number }): Anchor {
return anchor instanceof HTMLElement ? { x: anchor.offsetLeft, y: anchor.offsetTop } : anchor;
}

export interface IContextMenuService {
show(items: MenuItem[], anchor: Anchor, onHide?: () => void): void;
}

export type IContextMenuServiceProvider = () => Promise<IContextMenuService>;
Loading

0 comments on commit 52b9e22

Please sign in to comment.