Skip to content

Commit aadd403

Browse files
author
Akos Kitta
committed
refined label provide for unsaved sketches
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 6da702a commit aadd403

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ import { WorkspaceCommandContribution } from './theia/workspace/workspace-comman
113113
import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/workspace/lib/browser/workspace-delete-handler';
114114
import { WorkspaceDeleteHandler } from './theia/workspace/workspace-delete-handler';
115115
import { TabBarToolbar } from './theia/core/tab-bar-toolbar';
116+
import { EditorWidgetFactory as TheiaEditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
117+
import { EditorWidgetFactory } from './theia/editor/editor-widget-factory';
116118

117119
const ElementQueries = require('css-element-queries/src/ElementQueries');
118120

@@ -291,6 +293,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
291293
rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope();
292294
rebind(TheiaWorkspaceCommandContribution).to(WorkspaceCommandContribution).inSingletonScope();
293295
rebind(TheiaWorkspaceDeleteHandler).to(WorkspaceDeleteHandler).inSingletonScope();
296+
rebind(TheiaEditorWidgetFactory).to(EditorWidgetFactory).inSingletonScope();
294297
rebind(TabBarToolbarFactory).toFactory(({ container: parentContainer }) => () => {
295298
const container = parentContainer.createChild();
296299
container.bind(TabBarToolbar).toSelf().inSingletonScope();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { inject, injectable } from 'inversify';
2+
import URI from '@theia/core/lib/common/uri';
3+
import { EditorWidget } from '@theia/editor/lib/browser';
4+
import { LabelProvider } from '@theia/core/lib/browser';
5+
import { EditorWidgetFactory as TheiaEditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
6+
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
7+
import { SketchesService, Sketch } from '../../../common/protocol';
8+
9+
@injectable()
10+
export class EditorWidgetFactory extends TheiaEditorWidgetFactory {
11+
12+
@inject(SketchesService)
13+
protected readonly sketchesService: SketchesService;
14+
15+
@inject(SketchesServiceClientImpl)
16+
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
17+
18+
@inject(LabelProvider)
19+
protected readonly labelProvider: LabelProvider;
20+
21+
protected async createEditor(uri: URI): Promise<EditorWidget> {
22+
const widget = await super.createEditor(uri);
23+
return this.maybeUpdateCaption(widget);
24+
}
25+
26+
protected async maybeUpdateCaption(widget: EditorWidget): Promise<EditorWidget> {
27+
const sketch = await this.sketchesServiceClient.currentSketch();
28+
const { uri } = widget.editor;
29+
if (sketch && Sketch.isInSketch(uri, sketch)) {
30+
const isTemp = await this.sketchesService.isTemp(sketch);
31+
if (isTemp) {
32+
widget.title.caption = `Unsaved – ${this.labelProvider.getName(uri)}`;
33+
}
34+
}
35+
return widget;
36+
}
37+
38+
}

0 commit comments

Comments
 (0)