From aadd403cdb342a827594f8e5510025a7cf625f1c Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 3 Aug 2020 15:45:49 +0200 Subject: [PATCH] refined label provide for unsaved sketches Signed-off-by: Akos Kitta --- .../browser/arduino-ide-frontend-module.ts | 3 ++ .../theia/editor/editor-widget-factory.ts | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index 32bb0124..8d0cc6ee 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -113,6 +113,8 @@ import { WorkspaceCommandContribution } from './theia/workspace/workspace-comman import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/workspace/lib/browser/workspace-delete-handler'; import { WorkspaceDeleteHandler } from './theia/workspace/workspace-delete-handler'; import { TabBarToolbar } from './theia/core/tab-bar-toolbar'; +import { EditorWidgetFactory as TheiaEditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory'; +import { EditorWidgetFactory } from './theia/editor/editor-widget-factory'; const ElementQueries = require('css-element-queries/src/ElementQueries'); @@ -291,6 +293,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope(); rebind(TheiaWorkspaceCommandContribution).to(WorkspaceCommandContribution).inSingletonScope(); rebind(TheiaWorkspaceDeleteHandler).to(WorkspaceDeleteHandler).inSingletonScope(); + rebind(TheiaEditorWidgetFactory).to(EditorWidgetFactory).inSingletonScope(); rebind(TabBarToolbarFactory).toFactory(({ container: parentContainer }) => () => { const container = parentContainer.createChild(); container.bind(TabBarToolbar).toSelf().inSingletonScope(); diff --git a/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts b/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts new file mode 100644 index 00000000..3df395c3 --- /dev/null +++ b/arduino-ide-extension/src/browser/theia/editor/editor-widget-factory.ts @@ -0,0 +1,38 @@ +import { inject, injectable } from 'inversify'; +import URI from '@theia/core/lib/common/uri'; +import { EditorWidget } from '@theia/editor/lib/browser'; +import { LabelProvider } from '@theia/core/lib/browser'; +import { EditorWidgetFactory as TheiaEditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory'; +import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl'; +import { SketchesService, Sketch } from '../../../common/protocol'; + +@injectable() +export class EditorWidgetFactory extends TheiaEditorWidgetFactory { + + @inject(SketchesService) + protected readonly sketchesService: SketchesService; + + @inject(SketchesServiceClientImpl) + protected readonly sketchesServiceClient: SketchesServiceClientImpl; + + @inject(LabelProvider) + protected readonly labelProvider: LabelProvider; + + protected async createEditor(uri: URI): Promise { + const widget = await super.createEditor(uri); + return this.maybeUpdateCaption(widget); + } + + protected async maybeUpdateCaption(widget: EditorWidget): Promise { + const sketch = await this.sketchesServiceClient.currentSketch(); + const { uri } = widget.editor; + if (sketch && Sketch.isInSketch(uri, sketch)) { + const isTemp = await this.sketchesService.isTemp(sketch); + if (isTemp) { + widget.title.caption = `Unsaved – ${this.labelProvider.getName(uri)}`; + } + } + return widget; + } + +}