Skip to content

Commit f5a1ae4

Browse files
author
Alberto Iannaccone
committed
add commands to open sketchbook widgets
add commands to show sketchbook widgets
1 parent 0f1d379 commit f5a1ae4

File tree

5 files changed

+87
-9
lines changed

5 files changed

+87
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
832832

833833
bind(CloudSketchbookWidget).toSelf();
834834
rebind(SketchbookWidget).toService(CloudSketchbookWidget);
835+
bind(CommandContribution).toService(CloudSketchbookWidget);
835836
bind(CloudSketchbookTreeWidget).toDynamicValue(({ container }) =>
836837
createCloudSketchbookTreeWidget(container)
837838
);

arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-widget.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
1+
import {
2+
inject,
3+
injectable,
4+
postConstruct,
5+
} from '@theia/core/shared/inversify';
26
import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget';
37
import { SketchbookWidget } from '../sketchbook/sketchbook-widget';
48
import { ArduinoPreferences } from '../../arduino-preferences';
9+
import { Command, CommandContribution, CommandRegistry } from '@theia/core';
10+
import { ApplicationShell } from '@theia/core/lib/browser';
11+
12+
export const SHOW_CLOUD_SKETCHBOOK_WIDGET = Command.toLocalizedCommand(
13+
{
14+
id: 'arduino-sketchbook--show-cloud-sketchbook-widget',
15+
label: 'Show Cloud Sketchbook Widget',
16+
},
17+
'arduino/sketch/showCloudSketchbookWidget'
18+
);
519

620
@injectable()
7-
export class CloudSketchbookWidget extends SketchbookWidget {
21+
export class CloudSketchbookWidget
22+
extends SketchbookWidget
23+
implements CommandContribution
24+
{
825
@inject(CloudSketchbookCompositeWidget)
9-
protected readonly widget: CloudSketchbookCompositeWidget;
26+
protected readonly cloudSketchbookCompositeWidget: CloudSketchbookCompositeWidget;
1027

1128
@inject(ArduinoPreferences)
1229
protected readonly arduinoPreferences: ArduinoPreferences;
1330

31+
@inject(ApplicationShell)
32+
protected readonly shell: ApplicationShell;
33+
1434
@postConstruct()
1535
protected override init(): void {
1636
super.init();
@@ -27,7 +47,9 @@ export class CloudSketchbookWidget extends SketchbookWidget {
2747

2848
checkCloudEnabled() {
2949
if (this.arduinoPreferences['arduino.cloud.enabled']) {
30-
this.sketchbookTreesContainer.activateWidget(this.widget);
50+
this.sketchbookTreesContainer.activateWidget(
51+
this.cloudSketchbookCompositeWidget
52+
);
3153
} else {
3254
this.sketchbookTreesContainer.activateWidget(
3355
this.localSketchbookTreeWidget
@@ -45,7 +67,9 @@ export class CloudSketchbookWidget extends SketchbookWidget {
4567
}
4668

4769
protected override onAfterAttach(msg: any): void {
48-
this.sketchbookTreesContainer.addWidget(this.widget);
70+
this.sketchbookTreesContainer.addWidget(
71+
this.cloudSketchbookCompositeWidget
72+
);
4973
this.setDocumentMode();
5074
this.arduinoPreferences.onPreferenceChanged((event) => {
5175
if (event.preferenceName === 'arduino.cloud.enabled') {
@@ -54,4 +78,23 @@ export class CloudSketchbookWidget extends SketchbookWidget {
5478
});
5579
super.onAfterAttach(msg);
5680
}
81+
82+
registerCommands(registry: CommandRegistry): void {
83+
this.sketchbookTreesContainer.addWidget(
84+
this.cloudSketchbookCompositeWidget
85+
);
86+
registry.registerCommand(SHOW_CLOUD_SKETCHBOOK_WIDGET, {
87+
execute: this.showCloudSketchbookWidget.bind(this),
88+
});
89+
}
90+
91+
showCloudSketchbookWidget(): void {
92+
if (this.arduinoPreferences['arduino.cloud.enabled']) {
93+
this.shell.activateWidget(this.id).then((widget) => {
94+
if (widget instanceof CloudSketchbookWidget) {
95+
widget.activateTreeWidget(this.cloudSketchbookCompositeWidget.id);
96+
}
97+
});
98+
}
99+
}
57100
}

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { Command } from '@theia/core/lib/common/command';
22

33
export namespace SketchbookCommands {
4+
export const TOGGLE_SKETCHBOOK_WIDGET: Command = {
5+
id: 'arduino-sketchbook-widget:toggle',
6+
};
7+
8+
export const SHOW_SKETCHBOOK_WIDGET = Command.toLocalizedCommand(
9+
{
10+
id: 'arduino-sketchbook--show-sketchbook-widget',
11+
label: 'Show Sketchbook Widget',
12+
},
13+
'arduino/sketch/showSketchbookWidget'
14+
);
15+
416
export const OPEN_NEW_WINDOW = Command.toLocalizedCommand(
517
{
618
id: 'arduino-sketchbook--open-sketch-new-window',

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class SketchbookWidgetContribution
7777
area: 'left',
7878
rank: 1,
7979
},
80-
toggleCommandId: 'arduino-sketchbook-widget:toggle',
80+
toggleCommandId: SketchbookCommands.TOGGLE_SKETCHBOOK_WIDGET.id,
8181
toggleKeybinding: 'CtrlCmd+Shift+B',
8282
});
8383
}
@@ -100,7 +100,9 @@ export class SketchbookWidgetContribution
100100

101101
override registerCommands(registry: CommandRegistry): void {
102102
super.registerCommands(registry);
103-
103+
registry.registerCommand(SketchbookCommands.SHOW_SKETCHBOOK_WIDGET, {
104+
execute: () => this.showSketchbookWidget(),
105+
});
104106
registry.registerCommand(SketchbookCommands.OPEN_NEW_WINDOW, {
105107
execute: async (arg) => {
106108
return this.workspaceService.open(arg.node.uri);
@@ -197,7 +199,7 @@ export class SketchbookWidgetContribution
197199

198200
// unregister main menu action
199201
registry.unregisterMenuAction({
200-
commandId: 'arduino-sketchbook-widget:toggle',
202+
commandId: SketchbookCommands.TOGGLE_SKETCHBOOK_WIDGET.id,
201203
});
202204

203205
registry.registerMenuAction(SKETCHBOOK__CONTEXT__MAIN_GROUP, {
@@ -230,4 +232,10 @@ export class SketchbookWidgetContribution
230232
protected onCurrentWidgetChangedHandler(): void {
231233
this.selectWidgetFileNode(this.shell.currentWidget);
232234
}
235+
236+
protected async showSketchbookWidget(): Promise<void> {
237+
const widget = await this.widget;
238+
await this.shell.activateWidget(widget.id);
239+
widget.activateTreeWidget(widget.getTreeWidget().id);
240+
}
233241
}

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
1+
import {
2+
inject,
3+
injectable,
4+
postConstruct,
5+
} from '@theia/core/shared/inversify';
26
import { toArray } from '@theia/core/shared/@phosphor/algorithm';
37
import { IDragEvent } from '@theia/core/shared/@phosphor/dragdrop';
48
import { DockPanel, Widget } from '@theia/core/shared/@phosphor/widgets';
@@ -45,6 +49,16 @@ export class SketchbookWidget extends BaseWidget {
4549
return this.localSketchbookTreeWidget;
4650
}
4751

52+
activateTreeWidget(treeWidgetId: string): boolean {
53+
for (const widget of toArray(this.sketchbookTreesContainer.widgets())) {
54+
if (widget.id === treeWidgetId) {
55+
this.sketchbookTreesContainer.activateWidget(widget);
56+
return true;
57+
}
58+
}
59+
return false;
60+
}
61+
4862
protected override onActivateRequest(message: Message): void {
4963
super.onActivateRequest(message);
5064

0 commit comments

Comments
 (0)