Added toolbar to top panel.

Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
jbicker
2019-06-13 16:45:36 +02:00
parent 4c3becd3e8
commit 6a956afbcd
5 changed files with 98 additions and 12 deletions

View File

@@ -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'
})
}
}

View File

@@ -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();
}
}