Skip to content

Commit

Permalink
EditorPreviewManager extends EditorManager
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
  • Loading branch information
Colin Grant committed May 25, 2021
1 parent 583220b commit ce92832
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 659 deletions.
15 changes: 7 additions & 8 deletions examples/api-tests/src/typescript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('TypeScript', function () {
const { CommandRegistry } = require('@theia/core/lib/common/command');
const { KeybindingRegistry } = require('@theia/core/lib/browser/keybinding');
const { OpenerService, open } = require('@theia/core/lib/browser/opener-service');
const { EditorPreviewWidget } = require('@theia/editor-preview/lib/browser/editor-preview-widget');
const { animationFrame } = require('@theia/core/lib/browser/browser');
const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser/preferences/preference-service');
const { ProgressStatusBarItem } = require('@theia/core/lib/browser/progress-status-bar-item');
Expand Down Expand Up @@ -157,7 +156,7 @@ module.exports = (port, host, argv) => Promise.resolve()
*/
async function openEditor(uri, preview = false) {
const widget = await open(openerService, uri, { mode: 'activate', preview });
const editorWidget = widget instanceof EditorPreviewWidget ? widget.editorWidget : widget instanceof EditorWidget ? widget : undefined;
const editorWidget = widget instanceof EditorWidget ? widget : undefined;
const editor = MonacoEditor.get(editorWidget);
assert.isDefined(editor);

Expand Down Expand Up @@ -284,7 +283,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const activeEditor = /** @type {MonacoEditor} */ (MonacoEditor.get(editorManager.activeEditor));
// @ts-ignore
assert.equal(editorManager.activeEditor.parent instanceof EditorPreviewWidget, preview);
assert.equal(editorManager.activeEditor.isPreview, preview);
assert.equal(activeEditor.uri.toString(), serverUri.toString());
// const |container = new Container();
// @ts-ignore
Expand All @@ -307,7 +306,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const activeEditor = /** @type {MonacoEditor} */ (MonacoEditor.get(editorManager.activeEditor));
// @ts-ignore
assert.isFalse(editorManager.activeEditor.parent instanceof EditorPreviewWidget);
assert.isFalse(editorManager.activeEditor.isPreview);
assert.equal(activeEditor.uri.toString(), inversifyUri.toString());
// export { |Container } from "./container/container";
// @ts-ignore
Expand All @@ -328,7 +327,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const activeEditor = /** @type {MonacoEditor} */ (MonacoEditor.get(editorManager.activeEditor));
// @ts-ignore
assert.isTrue(editorManager.activeEditor.parent instanceof EditorPreviewWidget);
assert.isTrue(editorManager.activeEditor.isPreview);
assert.equal(activeEditor.uri.toString(), inversifyUri.toString());
// export { |Container } from "./container/container";
// @ts-ignore
Expand Down Expand Up @@ -356,7 +355,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const activeEditor = /** @type {MonacoEditor} */ (MonacoEditor.get(editorManager.activeEditor));
// @ts-ignore
assert.equal(editorManager.activeEditor.parent instanceof EditorPreviewWidget, preview);
assert.equal(editorManager.activeEditor.isPreview, preview);
assert.equal(activeEditor.uri.toString(), serverUri.toString());
// const |container = new Container();
// @ts-ignore
Expand All @@ -382,7 +381,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const activeEditor = /** @type {MonacoEditor} */ (MonacoEditor.get(editorManager.activeEditor));
// @ts-ignore
assert.isFalse(editorManager.activeEditor.parent instanceof EditorPreviewWidget);
assert.isFalse(editorManager.activeEditor.isPreview);
assert.equal(activeEditor.uri.toString(), inversifyUri.toString());
// export { |Container } from "./container/container";
// @ts-ignore
Expand All @@ -406,7 +405,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const activeEditor = /** @type {MonacoEditor} */ (MonacoEditor.get(editorManager.activeEditor));
// @ts-ignore
assert.isTrue(editorManager.activeEditor.parent instanceof EditorPreviewWidget);
assert.isTrue(editorManager.activeEditor.isPreview);
assert.equal(activeEditor.uri.toString(), inversifyUri.toString());
// export { |Container } from "./container/container";
// @ts-ignore
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/browser/widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,13 @@ export class WidgetManager {
*
* @returns a promise resolving to the widget if available, else `undefined`.
*/
async getWidget<T extends Widget>(factoryId: string, options?: any): Promise<T | undefined> {
getWidget<T extends Widget>(factoryId: string, options?: any): MaybePromise<T> | undefined {
const key = this.toKey({ factoryId, options });
const pendingWidget = this.doGetWidget<T>(key);
const widget = pendingWidget && await pendingWidget;
return widget;
return this.doGetWidget<T>(key);
}

protected doGetWidget<T extends Widget>(key: string): MaybePromise<T> | undefined {
const pendingWidget = this.widgetPromises.get(key) || this.pendingWidgetPromises.get(key);
const pendingWidget = this.widgetPromises.get(key) ?? this.pendingWidgetPromises.get(key);
if (pendingWidget) {
return pendingWidget as MaybePromise<T>;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/widget-open-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export abstract class WidgetOpenHandler<W extends BaseWidget> implements OpenHan
*
* @returns a promise that resolves to the existing widget or `undefined` if no widget for the given uri exists.
*/
getByUri(uri: URI): Promise<W | undefined> {
getByUri(uri: URI): MaybePromise<W> | undefined {
return this.getWidget(uri);
}

Expand All @@ -136,7 +136,7 @@ export abstract class WidgetOpenHandler<W extends BaseWidget> implements OpenHan
return this.widgetManager.getWidgets(this.id) as W[];
}

protected getWidget(uri: URI, options?: WidgetOpenerOptions): Promise<W | undefined> {
protected getWidget(uri: URI, options?: WidgetOpenerOptions): MaybePromise<W> | undefined {
const widgetOptions = this.createWidgetOptions(uri, options);
return this.widgetManager.getWidget<W>(this.id, widgetOptions);
}
Expand Down
91 changes: 0 additions & 91 deletions packages/editor-preview/src/browser/editor-preview-factory.spec.ts

This file was deleted.

62 changes: 0 additions & 62 deletions packages/editor-preview/src/browser/editor-preview-factory.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import '../../src/browser/style/index.css';
import { OpenHandler, WidgetFactory } from '@theia/core/lib/browser';
import { ContainerModule } from '@theia/core/shared/inversify';
import { EditorPreviewManager } from './editor-preview-manager';
import { EditorPreviewWidgetFactory } from './editor-preview-factory';
import { bindEditorPreviewPreferences } from './editor-preview-preferences';
import { EditorPreviewManager } from './editor-preview-manager';
import { EditorManager } from '@theia/editor/lib/browser';
import { EditorPreviewWidgetFactory } from './editor-preview-widget-factory';

import '../../src/browser/style/index.css';

export default new ContainerModule(bind => {
export default new ContainerModule((bind, unbind, isBound, rebind) => {

bind(WidgetFactory).to(EditorPreviewWidgetFactory).inSingletonScope();
bind(EditorPreviewWidgetFactory).toSelf().inSingletonScope();
bind(WidgetFactory).toService(EditorPreviewWidgetFactory);

bind(EditorPreviewManager).toSelf().inSingletonScope();
bind(OpenHandler).to(EditorPreviewManager);
rebind(EditorManager).toService(EditorPreviewManager);
bind(OpenHandler).toService(EditorPreviewManager);

bindEditorPreviewPreferences(bind);
});
Loading

0 comments on commit ce92832

Please sign in to comment.