Skip to content

Commit 9a97eee

Browse files
committed
6636-custom-editor: Adds a prototype of custom editors contributed by extensions with this functionality:
- Adds a new contribution point for custom editors. - Adds API for registering a custom editor providers. - Implements CustomEditor extension API - based on VSCode (excluding backup functionality not implemented in this PR). - Adds CustomEditorWidget extending WebviewWidget containing a model reference to CustomEditorModel. - Supports two CustomEditorModel implementations: CustomTextEditorModel for text documents and MainCustomEditorModel for binary documents. - Registers openHandlers for CustomEditors. - Adds `openWith` command for selecting which editor to use when openning a resource. - Adds Undo/Redo functionality for CustomEditors. Signed-off-by: Dan Arad <dan.arad@sap.com>
1 parent 0e33a85 commit 9a97eee

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

packages/callhierarchy/src/common/glob.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import * as paths from './paths';
2525
import { CharCode } from '@theia/core/lib/common/char-code';
2626

2727
/* eslint-disable @typescript-eslint/no-shadow, no-null/no-null */
28-
2928
export interface IExpression {
3029
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3130
[pattern: string]: boolean | SiblingClause | any;

packages/core/src/browser/opener-service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface OpenerService {
7676
*/
7777
getOpener(uri: URI, options?: OpenerOptions): Promise<OpenHandler>;
7878
/**
79-
* Event that fires when a new opener is added or removed
79+
* Event that fires when a new opener is added or removed.
8080
*/
8181
onOpenersStateChanged?: Event<void>;
8282
}
@@ -88,8 +88,8 @@ export async function open(openerService: OpenerService, uri: URI, options?: Ope
8888

8989
@injectable()
9090
export class DefaultOpenerService implements OpenerService {
91-
// Containing OpenHandlers created for CustomEditor contributions
92-
protected readonly additionalHandlers: OpenHandler[] = [];
91+
// Collection of open-handlers for custom-editor contributions.
92+
protected readonly customEditorOpenHandlers: OpenHandler[] = [];
9393

9494
protected readonly onOpenersStateChangedEmitter = new Emitter<void>();
9595
readonly onOpenersStateChanged = this.onOpenersStateChangedEmitter.event;
@@ -100,11 +100,11 @@ export class DefaultOpenerService implements OpenerService {
100100
) { }
101101

102102
public addHandler(openHandler: OpenHandler): Disposable {
103-
this.additionalHandlers.push(openHandler);
103+
this.customEditorOpenHandlers.push(openHandler);
104104
this.onOpenersStateChangedEmitter.fire();
105105

106106
return Disposable.create(() => {
107-
this.additionalHandlers.splice(this.additionalHandlers.indexOf(openHandler), 1);
107+
this.customEditorOpenHandlers.splice(this.customEditorOpenHandlers.indexOf(openHandler), 1);
108108
this.onOpenersStateChangedEmitter.fire();
109109
});
110110
}
@@ -135,7 +135,7 @@ export class DefaultOpenerService implements OpenerService {
135135
protected getHandlers(): OpenHandler[] {
136136
return [
137137
...this.handlersProvider.getContributions(),
138-
...this.additionalHandlers
138+
...this.customEditorOpenHandlers
139139
];
140140
}
141141

packages/monaco/src/browser/monaco-editor-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import { OpenerService, open, WidgetOpenMode, ApplicationShell, PreferenceServic
2020
import { EditorWidget, EditorOpenerOptions, EditorManager, CustomEditorWidget } from '@theia/editor/lib/browser';
2121
import { MonacoEditor } from './monaco-editor';
2222
import { MonacoToProtocolConverter } from './monaco-to-protocol-converter';
23+
import { MonacoEditorModel } from './monaco-editor-model';
2324

2425
import ICodeEditor = monaco.editor.ICodeEditor;
2526
import CommonCodeEditor = monaco.editor.CommonCodeEditor;
2627
import IResourceInput = monaco.editor.IResourceInput;
27-
import { MonacoEditorModel } from './monaco-editor-model';
2828

2929
decorate(injectable(), monaco.services.CodeEditorServiceImpl);
3030

packages/plugin-ext/src/main/browser/custom-editors/custom-editor-contribution.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,16 @@
1515
********************************************************************************/
1616

1717
import { injectable, inject } from 'inversify';
18-
import { CommandRegistry, CommandContribution, SelectionService } from '@theia/core/lib/common';
18+
import { CommandRegistry, CommandContribution } from '@theia/core/lib/common';
1919
import { ApplicationShell, CommonCommands } from '@theia/core/lib/browser';
2020
import { CustomEditorWidget } from './custom-editor-widget';
21-
import { FileService } from '@theia/filesystem/lib/browser/file-service';
22-
import { FileDialogService } from '@theia/filesystem/lib/browser';
2321

2422
@injectable()
2523
export class CustomEditorContribution implements CommandContribution {
2624

2725
@inject(ApplicationShell)
2826
protected readonly shell: ApplicationShell;
2927

30-
@inject(FileService)
31-
protected readonly fileService: FileService;
32-
33-
@inject(FileDialogService)
34-
protected readonly fileDialogService: FileDialogService;
35-
36-
@inject(SelectionService)
37-
protected readonly selectionService: SelectionService;
38-
3928
registerCommands(commands: CommandRegistry): void {
4029
commands.registerHandler(CommonCommands.UNDO.id, {
4130
isEnabled: () => this.shell.activeWidget instanceof CustomEditorWidget,

packages/workspace/src/browser/workspace-commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export class WorkspaceCommandContribution implements CommandContribution {
346346
registry.registerCommand(openWithCommand, this.newUriAwareCommandHandler({
347347
execute: uri => opener.open(uri),
348348
isEnabled: uri => opener.canHandle(uri) > 0,
349-
isVisible: uri => opener.canHandle(uri) > 0 && this.areMultipleOpenHandlersPresent(uri)
349+
isVisible: uri => opener.canHandle(uri) > 0 && this.areMultipleOpenHandlersPresent(this.openers, uri)
350350
}));
351351
}
352352
}
@@ -485,9 +485,9 @@ export class WorkspaceCommandContribution implements CommandContribution {
485485
}
486486
}
487487

488-
protected areMultipleOpenHandlersPresent(uri: URI): boolean {
488+
protected areMultipleOpenHandlersPresent(openers: OpenHandler[], uri: URI): boolean {
489489
let count = 0;
490-
for (const opener of this.openers) {
490+
for (const opener of openers) {
491491
if (opener.canHandle(uri) > 0) {
492492
count++;
493493
}

0 commit comments

Comments
 (0)