Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rebind of CommandPalette optional #65

Merged
merged 2 commits into from
Feb 12, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EditorContextService,
EnableToolPaletteAction,
FocusStateChangedAction,
FocusTracker,
GLSP_TYPES,
IActionDispatcher,
ICopyPasteHandler,
Expand All @@ -32,11 +33,11 @@ import {
TYPES
} from "@eclipse-glsp/client";
import { Message } from "@phosphor/messaging/lib";
import { ApplicationShell, Saveable, SaveableSource } from "@theia/core/lib/browser";
import { ApplicationShell, Saveable, SaveableSource, Widget } from "@theia/core/lib/browser";
import { Disposable, DisposableCollection, Emitter, Event, MaybePromise } from "@theia/core/lib/common";
import { EditorPreferences } from "@theia/editor/lib/browser";
import { Container } from "inversify";
import { DiagramWidget, DiagramWidgetOptions, TheiaSprottyConnector } from "sprotty-theia";
import { DiagramWidget, DiagramWidgetOptions, isDiagramWidgetContainer, TheiaSprottyConnector } from "sprotty-theia";

import { GLSPWidgetOpenerOptions, GLSPWidgetOptions } from "./glsp-diagram-manager";
import { DirtyStateNotifier, GLSPTheiaDiagramServer } from "./glsp-theia-diagram-server";
Expand Down Expand Up @@ -99,16 +100,6 @@ export class GLSPDiagramWidget extends DiagramWidget implements SaveableSource {
}
}

listenToFocusState(shell: ApplicationShell) {
this.toDispose.push(shell.onDidChangeActiveWidget((event) => {
if (event.newValue === undefined || (event.newValue && event.newValue.id !== this.id)) {
this.actionDispatcher.dispatch(new FocusStateChangedAction(false));
} else if ((event.newValue && event.newValue.id === this.id)) {
this.actionDispatcher.dispatch(new FocusStateChangedAction(true));
}
}));
}

get diagramType(): string {
return this.options.diagramType;
}
Expand Down Expand Up @@ -138,6 +129,43 @@ export class GLSPDiagramWidget extends DiagramWidget implements SaveableSource {
this.copyPasteHandler.handlePaste(e);
}
}

listenToFocusState(shell: ApplicationShell): void {
this.toDispose.push(shell.onDidChangeActiveWidget((event) => {
const focusedWidget = event.newValue;
if (this.hasFocus && !this.isThisWidget(focusedWidget)) {
this.actionDispatcher.dispatch(new FocusStateChangedAction(false));
} else if (!this.hasFocus && this.isThisWidget(focusedWidget)) {
this.actionDispatcher.dispatch(new FocusStateChangedAction(true));
}
}));
}

protected isThisWidget(widget: Widget | null): boolean {
if (widget === null) return false;
const diagramWidget = getDiagramWidget(widget);
return diagramWidget !== undefined && diagramWidget.id === this.id;
}

get hasFocus(): boolean | undefined {
let focusTracker: FocusTracker | undefined;
if (this.diContainer.isBound(FocusTracker)) {
focusTracker = this.diContainer.get(FocusTracker);
}
if (focusTracker) {
return focusTracker.hasFocus;
}
return undefined;
}
}

export function getDiagramWidget(widget: Widget): GLSPDiagramWidget | undefined {
if (widget instanceof GLSPDiagramWidget) {
return widget as GLSPDiagramWidget;
} else if (isDiagramWidgetContainer(widget) && widget.diagramWidget instanceof GLSPDiagramWidget) {
return widget.diagramWidget as GLSPDiagramWidget;
}
return undefined;
}

export class SaveableGLSPModelSource implements Saveable, Disposable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export abstract class GLSPTheiaDiagramConfiguration implements DiagramConfigurat
container.bind(OpenerService).toConstantValue(this.openerService);
container.bind(CommandService).toConstantValue(this.commandService);
container.bind(ExternalModelSourceChangedHandler).toConstantValue(this.modelSourceChangedHandler);
container.rebind(CommandPalette).to(TheiaCommandPalette);
if (container.isBound(CommandPalette)) {
container.rebind(CommandPalette).to(TheiaCommandPalette);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but shouldn't we do a "normal" bind if it is not already bound?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it doesn't really make sense to bind it if the CommandPalette isn't bound. If it isn't bound, the diagram editor doesn't want to have one, so we shouldn't then bind the TheiaCommandPalette either. Wdyt?

Copy link
Contributor

@martin-fleck-at martin-fleck-at Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, sorry, I somehow was not thinking about that! You are absolutely right! Or is there a way to bind an "empty" command palette? @tortmayr


connectTheiaContextMenuService(container, this.contextMenuServiceFactory);
connectTheiaMarkerManager(container, this.theiaMarkerManager, this.diagramType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import { Action, ExternalModelSourceChangedHandler, ViewerOptions } from "@eclipse-glsp/client";
import { ApplicationShell, ConfirmDialog, Widget } from "@theia/core/lib/browser";
import { inject, injectable } from "inversify";
import { isDiagramWidgetContainer } from "sprotty-theia";

import { GLSPDiagramWidget } from "./diagram";
import { getDiagramWidget } from "./diagram/glsp-diagram-widget";

@injectable()
export class TheiaModelSourceChangedHandler extends ExternalModelSourceChangedHandler {
Expand All @@ -37,7 +36,7 @@ export class TheiaModelSourceChangedHandler extends ExternalModelSourceChangedHa
}

protected async notifyModelSourceChangedWithWidget(widget: Widget, modelSourceName: string): Promise<Action[]> {
const diagramWidget = this.getDiagramWidget(widget);
const diagramWidget = getDiagramWidget(widget);
if (!diagramWidget) {
return [];
}
Expand All @@ -57,15 +56,6 @@ export class TheiaModelSourceChangedHandler extends ExternalModelSourceChangedHa
return false;
}

protected getDiagramWidget(widget: Widget): GLSPDiagramWidget | undefined {
if (widget instanceof GLSPDiagramWidget) {
return widget as GLSPDiagramWidget;
} else if (isDiagramWidgetContainer(widget) && widget.diagramWidget instanceof GLSPDiagramWidget) {
return widget.diagramWidget as GLSPDiagramWidget;
}
return undefined;
}

protected showDialog(widgetTitle: string, modelSourceName: string): Promise<boolean | undefined> {
const dialog = new ConfirmDialog({
title: `Source of editor '${widgetTitle}' changed`,
Expand Down