forked from eclipse-glsp/glsp-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate PRs from eclipsesource/graphical-lsp (eclipse-glsp#12)
+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
1 parent
1a9c544
commit 52b9e22
Showing
42 changed files
with
925 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/features/command-palette/server-command-palette-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
Oops, something went wrong.