Skip to content

Commit c54ae96

Browse files
committed
Overwritten EditorWidgetFactory, made editor widget not closable.
Signed-off-by: jbicker <jan.bicker@typefox.io>
1 parent 54d90d5 commit c54ae96

File tree

5 files changed

+204
-136
lines changed

5 files changed

+204
-136
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,24 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
9696
id: ArduinoCommands.VERIFY.id,
9797
command: ArduinoCommands.VERIFY.id,
9898
tooltip: 'Verify',
99-
group: 'arduino',
10099
text: '$(check)'
101100
});
102101
registry.registerItem({
103102
id: ArduinoCommands.UPLOAD.id,
104103
command: ArduinoCommands.UPLOAD.id,
105104
tooltip: 'Upload',
106-
group: 'arduino',
107105
text: '$(arrow-right)'
108106
});
109107
registry.registerItem({
110108
id: ArduinoCommands.SHOW_OPEN_CONTEXT_MENU.id,
111109
command: ArduinoCommands.SHOW_OPEN_CONTEXT_MENU.id,
112110
tooltip: 'Open',
113-
group: 'arduino',
114111
text: '$(arrow-up)'
115112
});
116113
registry.registerItem({
117114
id: ArduinoCommands.SAVE_SKETCH.id,
118115
command: ArduinoCommands.SAVE_SKETCH.id,
119116
tooltip: 'Save',
120-
group: 'arduino',
121117
text: '$(arrow-down)'
122118
});
123119
registry.registerItem({

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

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import { SilentMonacoStatusBarContribution } from './customization/silent-monaco
4646
import { ApplicationShell } from '@theia/core/lib/browser';
4747
import { CustomApplicationShell } from './customization/custom-application-shell';
4848
import { CustomFrontendApplication } from './customization/custom-frontend-application';
49+
import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
50+
import { CustomEditorWidgetFactory } from './customization/custom-editor-widget-factory';
4951

5052
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
5153
// Commands and toolbar items
@@ -140,4 +142,6 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
140142
bind(ApplicationShell).to(CustomApplicationShell).inSingletonScope();
141143
unbind(FrontendApplication);
142144
bind(FrontendApplication).to(CustomFrontendApplication).inSingletonScope();
145+
unbind(EditorWidgetFactory);
146+
bind(EditorWidgetFactory).to(CustomEditorWidgetFactory).inSingletonScope();
143147
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { injectable } from "inversify";
2+
import { EditorWidgetFactory } from "@theia/editor/lib/browser/editor-widget-factory";
3+
import URI from "@theia/core/lib/common/uri";
4+
import { EditorWidget } from "@theia/editor/lib/browser";
5+
6+
@injectable()
7+
export class CustomEditorWidgetFactory extends EditorWidgetFactory {
8+
9+
protected async createEditor(uri: URI): Promise<EditorWidget> {
10+
const icon = await this.labelProvider.getIcon(uri);
11+
return this.editorProvider(uri).then(textEditor => {
12+
const newEditor = new EditorWidget(textEditor, this.selectionService);
13+
newEditor.id = this.id + ':' + uri.toString();
14+
newEditor.title.closable = false;
15+
newEditor.title.label = this.labelProvider.getName(uri);
16+
newEditor.title.iconClass = icon + ' file-icon';
17+
newEditor.title.caption = this.labelProvider.getLongName(uri);
18+
return newEditor;
19+
});
20+
}
21+
22+
}

arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as React from 'react';
22
import { TabBarToolbar, TabBarToolbarRegistry, TabBarToolbarItem, ReactTabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
3-
import { LabelParser } from '@theia/core/lib/browser/label-parser';
43
import { CommandRegistry } from '@theia/core/lib/common/command';
4+
import { ReactWidget } from '@theia/core/lib/browser';
5+
import { LabelParser } from '@theia/core/lib/browser/label-parser';
56

67
export const ARDUINO_TOOLBAR_ITEM_CLASS = 'arduino-tool-item';
78

@@ -20,7 +21,7 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
2021

2122
constructor(props: ArduinoToolbarComponent.Props) {
2223
super(props);
23-
this.state = {tootip: ''};
24+
this.state = { tootip: '' };
2425
}
2526

2627
protected renderItem(item: TabBarToolbarItem): React.ReactNode {
@@ -51,21 +52,33 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
5152
}
5253
}
5354

54-
export class ArduinoToolbar extends TabBarToolbar {
55+
export class ArduinoToolbar extends ReactWidget {
56+
57+
protected items = new Map<string, TabBarToolbarItem | ReactTabBarToolbarItem>();
5558

5659
constructor(
5760
protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry,
58-
commands: CommandRegistry, labelParser: LabelParser
61+
protected readonly commands: CommandRegistry,
62+
protected readonly labelParser: LabelParser
5963
) {
60-
super(commands, labelParser);
64+
super();
6165
this.id = 'arduino-toolbar';
66+
this.addClass(TabBarToolbar.Styles.TAB_BAR_TOOLBAR);
6267
this.init();
6368
this.tabBarToolbarRegistry.onDidChange(() => this.updateToolbar());
6469
}
6570

71+
protected updateItems(items: Array<TabBarToolbarItem | ReactTabBarToolbarItem>): void {
72+
this.items.clear();
73+
for (const item of items.sort(TabBarToolbarItem.PRIORITY_COMPARATOR).reverse()) {
74+
this.items.set(item.id, item);
75+
}
76+
this.update();
77+
}
78+
6679
protected updateToolbar(): void {
6780
const items = this ? this.tabBarToolbarRegistry.visibleItems(this) : [];
68-
this.updateItems(items, this);
81+
this.updateItems(items);
6982
}
7083

7184
protected init(): void {
@@ -74,6 +87,10 @@ export class ArduinoToolbar extends TabBarToolbar {
7487
}
7588

7689
protected readonly doCommandIsEnabled = (id: string) => this.commandIsEnabled(id);
90+
protected commandIsEnabled(command: string): boolean {
91+
return this.commands.isEnabled(command, this);
92+
}
93+
7794
protected render(): React.ReactNode {
7895
return <ArduinoToolbarComponent
7996
items={[...this.items.values()]}
@@ -89,5 +106,4 @@ export class ArduinoToolbar extends TabBarToolbar {
89106
this.commands.executeCommand(item.command, this, e);
90107
}
91108
}
92-
93109
}

0 commit comments

Comments
 (0)