Skip to content

Commit

Permalink
GLSP-1362: Register GLSPDiagramManagers as open with handler (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
tortmayr authored Jul 6, 2024
1 parent 8866f5d commit e22d16c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/theia-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
theia_version: [1.45.1, 1.49.1, latest]
theia_version: [1.49.1, latest]
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ For details on building the project, please see the [README file of the theia-in
| 1.0.0-theia1.34.0 | >=1.34.0 < 1.39.0 |
| 2.0.0 | >=1.39.0 < 1.45.0 |
| 2.1.x | >=1.39.0 < 1.45.0 |
| 2.1.0-theia1.45.0 | >=1.45.0 < 1.50.0 |
| 2.1.0-theia1.50.0 | >=1.50.0 |
| next | >=1.50.0 |
| 2.1.0-theia1.45.0 | >=1.45.0 < 1.49.0 |
| 2.1.0-theia1.49.0 | >=1.49.0 |
| next | >=1.49.0 |

> Note: For versions <=1.0.0 it is not possible to safely restrict the maximum version of Theia packages. If you encounter build errors related to multiple resolved Theia versions please add a resolutions block to the `package.json` of your project e.g. for `1.0.0-theia1.27.0`:
Expand Down
5 changes: 3 additions & 2 deletions examples/workflow-theia/src/common/workflow-language.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2021 EclipseSource and others.
* Copyright (c) 2019-2024 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
Expand All @@ -17,7 +17,8 @@ import { GLSPDiagramLanguage } from '@eclipse-glsp/theia-integration/lib/common'

export const WorkflowLanguage: GLSPDiagramLanguage = {
contributionId: 'workflow',
label: 'Workflow Diagram',
label: 'Workflow Editor',
providerName: 'GLSP Diagram',
diagramType: 'workflow-diagram',
fileExtensions: ['.wf'],
iconClass: 'codicon codicon-type-hierarchy-sub'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import {
ApplicationShell,
FrontendApplicationContribution,
OpenHandler,
OpenWithHandler,
OpenWithService,
WidgetFactory,
WidgetOpenerOptions,
WidgetOpenHandler
} from '@theia/core/lib/browser';
import URI from '@theia/core/lib/common/uri';
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
import { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
import { EditorManager } from '@theia/editor/lib/browser';
import { DiagramServiceProvider } from '../diagram-service-provider';
import { TheiaOpenerOptionsNavigationService } from '../theia-opener-options-navigation-service';
Expand All @@ -48,7 +50,7 @@ export function registerDiagramManager(
}

@injectable()
export abstract class GLSPDiagramManager extends WidgetOpenHandler<GLSPDiagramWidget> implements WidgetFactory {
export abstract class GLSPDiagramManager extends WidgetOpenHandler<GLSPDiagramWidget> implements WidgetFactory, OpenWithHandler {
@inject(TheiaOpenerOptionsNavigationService)
protected readonly diagramNavigationService: TheiaOpenerOptionsNavigationService;

Expand All @@ -61,6 +63,9 @@ export abstract class GLSPDiagramManager extends WidgetOpenHandler<GLSPDiagramWi
@inject(EditorManager)
protected readonly editorManager: EditorManager;

@inject(OpenWithService)
protected openWithService: OpenWithService;

abstract get fileExtensions(): string[];

abstract get diagramType(): string;
Expand All @@ -69,6 +74,16 @@ export abstract class GLSPDiagramManager extends WidgetOpenHandler<GLSPDiagramWi

protected widgetCount = 0;

protected registerOpenWithHandler = true;

@postConstruct()
protected override init(): void {
super.init();
if (this.registerOpenWithHandler) {
this.openWithService.registerHandler(this);
}
}

override async doOpen(widget: GLSPDiagramWidget, maybeOptions?: WidgetOpenerOptions): Promise<void> {
const options: WidgetOpenerOptions = {
mode: 'activate',
Expand Down Expand Up @@ -170,6 +185,10 @@ export abstract class GLSPDiagramManager extends WidgetOpenHandler<GLSPDiagramWi
get iconClass(): string {
return codiconCSSString('type-hierarchy-sub');
}

get providerName(): string | undefined {
return undefined;
}
}

export interface GLSPWidgetOpenerOptions extends WidgetOpenerOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2021-2023 EclipseSource and others.
* Copyright (c) 2021-2024 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
Expand Down Expand Up @@ -213,13 +213,15 @@ class ConfigurableGLSPDiagramManager extends GLSPDiagramManager {
private _fileExtensions: string[] = [];
private _iconClass = codiconCSSString('type-hierarchy-sub');
private _contributionId: string;
private _providerName?: string;

public doConfigure(diagramLanguage: GLSPDiagramLanguage): void {
this._fileExtensions = diagramLanguage.fileExtensions;
this._diagramType = diagramLanguage.diagramType;
this._label = diagramLanguage.label;
this._iconClass = diagramLanguage.iconClass || this._iconClass;
this._contributionId = diagramLanguage.contributionId;
this._providerName = diagramLanguage.providerName;
}

get fileExtensions(): string[] {
Expand All @@ -241,6 +243,10 @@ class ConfigurableGLSPDiagramManager extends GLSPDiagramManager {
return this._contributionId;
}

override get providerName(): string | undefined {
return this._providerName;
}

override get iconClass(): string {
return this._iconClass;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/theia-integration/src/common/glsp-diagram-language.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2021 EclipseSource and others.
* Copyright (c) 2021-2024 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
Expand Down Expand Up @@ -27,9 +27,15 @@ export interface GLSPDiagramLanguage {
readonly fileExtensions: string[];
/** Display-label for this language. Is used in UI elements like the editor-widget title */
readonly label: string;
/**
* An optional provider name for this language. If defined, it will be used in supporting UI elements
* e.g. the open-with dialog.
*/
readonly providerName?: string;
/** The icon class that is associated with this language. If undefined, a default icon class will be used */
readonly iconClass?: string;
/** The id of the diagram manager that is responsible for this language. If undefined, a default id derived
/**
* The id of the diagram manager that is responsible for this language. If undefined, a default id derived
* from the diagram type will be used.
*/
readonly diagramManagerId?: string;
Expand Down

0 comments on commit e22d16c

Please sign in to comment.