mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-27 19:07:16 +00:00
Overwritten EditorWidgetFactory, made editor widget not closable.
Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
@@ -96,28 +96,24 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
id: ArduinoCommands.VERIFY.id,
|
||||
command: ArduinoCommands.VERIFY.id,
|
||||
tooltip: 'Verify',
|
||||
group: 'arduino',
|
||||
text: '$(check)'
|
||||
});
|
||||
registry.registerItem({
|
||||
id: ArduinoCommands.UPLOAD.id,
|
||||
command: ArduinoCommands.UPLOAD.id,
|
||||
tooltip: 'Upload',
|
||||
group: 'arduino',
|
||||
text: '$(arrow-right)'
|
||||
});
|
||||
registry.registerItem({
|
||||
id: ArduinoCommands.SHOW_OPEN_CONTEXT_MENU.id,
|
||||
command: ArduinoCommands.SHOW_OPEN_CONTEXT_MENU.id,
|
||||
tooltip: 'Open',
|
||||
group: 'arduino',
|
||||
text: '$(arrow-up)'
|
||||
});
|
||||
registry.registerItem({
|
||||
id: ArduinoCommands.SAVE_SKETCH.id,
|
||||
command: ArduinoCommands.SAVE_SKETCH.id,
|
||||
tooltip: 'Save',
|
||||
group: 'arduino',
|
||||
text: '$(arrow-down)'
|
||||
});
|
||||
registry.registerItem({
|
||||
|
||||
@@ -46,6 +46,8 @@ import { SilentMonacoStatusBarContribution } from './customization/silent-monaco
|
||||
import { ApplicationShell } from '@theia/core/lib/browser';
|
||||
import { CustomApplicationShell } from './customization/custom-application-shell';
|
||||
import { CustomFrontendApplication } from './customization/custom-frontend-application';
|
||||
import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
|
||||
import { CustomEditorWidgetFactory } from './customization/custom-editor-widget-factory';
|
||||
|
||||
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
|
||||
// Commands and toolbar items
|
||||
@@ -140,4 +142,6 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
|
||||
bind(ApplicationShell).to(CustomApplicationShell).inSingletonScope();
|
||||
unbind(FrontendApplication);
|
||||
bind(FrontendApplication).to(CustomFrontendApplication).inSingletonScope();
|
||||
unbind(EditorWidgetFactory);
|
||||
bind(EditorWidgetFactory).to(CustomEditorWidgetFactory).inSingletonScope();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { injectable } from "inversify";
|
||||
import { EditorWidgetFactory } from "@theia/editor/lib/browser/editor-widget-factory";
|
||||
import URI from "@theia/core/lib/common/uri";
|
||||
import { EditorWidget } from "@theia/editor/lib/browser";
|
||||
|
||||
@injectable()
|
||||
export class CustomEditorWidgetFactory extends EditorWidgetFactory {
|
||||
|
||||
protected async createEditor(uri: URI): Promise<EditorWidget> {
|
||||
const icon = await this.labelProvider.getIcon(uri);
|
||||
return this.editorProvider(uri).then(textEditor => {
|
||||
const newEditor = new EditorWidget(textEditor, this.selectionService);
|
||||
newEditor.id = this.id + ':' + uri.toString();
|
||||
newEditor.title.closable = false;
|
||||
newEditor.title.label = this.labelProvider.getName(uri);
|
||||
newEditor.title.iconClass = icon + ' file-icon';
|
||||
newEditor.title.caption = this.labelProvider.getLongName(uri);
|
||||
return newEditor;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { TabBarToolbar, TabBarToolbarRegistry, TabBarToolbarItem, ReactTabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||
import { LabelParser } from '@theia/core/lib/browser/label-parser';
|
||||
import { CommandRegistry } from '@theia/core/lib/common/command';
|
||||
import { ReactWidget } from '@theia/core/lib/browser';
|
||||
import { LabelParser } from '@theia/core/lib/browser/label-parser';
|
||||
|
||||
export const ARDUINO_TOOLBAR_ITEM_CLASS = 'arduino-tool-item';
|
||||
|
||||
@@ -20,7 +21,7 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
|
||||
|
||||
constructor(props: ArduinoToolbarComponent.Props) {
|
||||
super(props);
|
||||
this.state = {tootip: ''};
|
||||
this.state = { tootip: '' };
|
||||
}
|
||||
|
||||
protected renderItem(item: TabBarToolbarItem): React.ReactNode {
|
||||
@@ -51,21 +52,33 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
|
||||
}
|
||||
}
|
||||
|
||||
export class ArduinoToolbar extends TabBarToolbar {
|
||||
export class ArduinoToolbar extends ReactWidget {
|
||||
|
||||
protected items = new Map<string, TabBarToolbarItem | ReactTabBarToolbarItem>();
|
||||
|
||||
constructor(
|
||||
protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry,
|
||||
commands: CommandRegistry, labelParser: LabelParser
|
||||
protected readonly commands: CommandRegistry,
|
||||
protected readonly labelParser: LabelParser
|
||||
) {
|
||||
super(commands, labelParser);
|
||||
super();
|
||||
this.id = 'arduino-toolbar';
|
||||
this.addClass(TabBarToolbar.Styles.TAB_BAR_TOOLBAR);
|
||||
this.init();
|
||||
this.tabBarToolbarRegistry.onDidChange(() => this.updateToolbar());
|
||||
}
|
||||
|
||||
protected updateItems(items: Array<TabBarToolbarItem | ReactTabBarToolbarItem>): void {
|
||||
this.items.clear();
|
||||
for (const item of items.sort(TabBarToolbarItem.PRIORITY_COMPARATOR).reverse()) {
|
||||
this.items.set(item.id, item);
|
||||
}
|
||||
this.update();
|
||||
}
|
||||
|
||||
protected updateToolbar(): void {
|
||||
const items = this ? this.tabBarToolbarRegistry.visibleItems(this) : [];
|
||||
this.updateItems(items, this);
|
||||
this.updateItems(items);
|
||||
}
|
||||
|
||||
protected init(): void {
|
||||
@@ -74,6 +87,10 @@ export class ArduinoToolbar extends TabBarToolbar {
|
||||
}
|
||||
|
||||
protected readonly doCommandIsEnabled = (id: string) => this.commandIsEnabled(id);
|
||||
protected commandIsEnabled(command: string): boolean {
|
||||
return this.commands.isEnabled(command, this);
|
||||
}
|
||||
|
||||
protected render(): React.ReactNode {
|
||||
return <ArduinoToolbarComponent
|
||||
items={[...this.items.values()]}
|
||||
@@ -89,5 +106,4 @@ export class ArduinoToolbar extends TabBarToolbar {
|
||||
this.commands.executeCommand(item.command, this, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user