mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-13 12:19:29 +00:00
Added toolbar to top panel.
Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { FrontendApplicationContribution, FrontendApplication } from "@theia/core/lib/browser";
|
||||
import { injectable, inject } from "inversify";
|
||||
import { ArduinoToolbar } from "./arduino-toolbar";
|
||||
import { TabBarToolbarRegistry, TabBarToolbarFactory, TabBarToolbar } from "@theia/core/lib/browser/shell/tab-bar-toolbar";
|
||||
|
||||
@injectable()
|
||||
export class ArduinoToolbarContribution implements FrontendApplicationContribution {
|
||||
|
||||
protected toolbarWidget: ArduinoToolbar;
|
||||
|
||||
constructor(
|
||||
@inject(TabBarToolbarRegistry) protected tabBarToolBarRegistry: TabBarToolbarRegistry,
|
||||
@inject(TabBarToolbarFactory) protected tabBarToolBarFactory: () => TabBarToolbar) {
|
||||
this.toolbarWidget = new ArduinoToolbar(this.tabBarToolBarRegistry, this.tabBarToolBarFactory);
|
||||
}
|
||||
|
||||
onStart(app: FrontendApplication) {
|
||||
app.shell.addWidget(this.toolbarWidget, {
|
||||
area: 'top'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Widget } from '@phosphor/widgets';
|
||||
import { Message } from '@phosphor/messaging';
|
||||
import { TabBarToolbar, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
||||
|
||||
export class ArduinoToolbar extends Widget {
|
||||
|
||||
protected toolbar: TabBarToolbar | undefined;
|
||||
|
||||
constructor(
|
||||
protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry,
|
||||
protected readonly tabBarToolbarFactory: () => TabBarToolbar
|
||||
) {
|
||||
super();
|
||||
this.id = 'arduino-toolbar';
|
||||
this.init();
|
||||
this.tabBarToolbarRegistry.onDidChange(() => this.update());
|
||||
}
|
||||
|
||||
protected onAfterAttach(msg: Message): void {
|
||||
if (this.toolbar) {
|
||||
if (this.toolbar.isAttached) {
|
||||
Widget.detach(this.toolbar);
|
||||
}
|
||||
Widget.attach(this.toolbar, this.node);
|
||||
}
|
||||
super.onAfterAttach(msg);
|
||||
}
|
||||
|
||||
protected onBeforeDetach(msg: Message): void {
|
||||
if (this.toolbar && this.toolbar.isAttached) {
|
||||
Widget.detach(this.toolbar);
|
||||
}
|
||||
super.onBeforeDetach(msg);
|
||||
}
|
||||
|
||||
protected onUpdateRequest(msg: Message): void {
|
||||
super.onUpdateRequest(msg);
|
||||
this.updateToolbar();
|
||||
}
|
||||
|
||||
protected updateToolbar(): void {
|
||||
if (!this.toolbar) {
|
||||
return;
|
||||
}
|
||||
const items = this ? this.tabBarToolbarRegistry.visibleItems(this) : [];
|
||||
this.toolbar.updateItems(items, this);
|
||||
}
|
||||
|
||||
protected init(): void {
|
||||
this.node.classList.add('theia-arduino-toolbar');
|
||||
this.toolbar = this.tabBarToolbarFactory();
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user