Skip to content

Commit 50e0233

Browse files
author
Alberto Iannaccone
committed
try merge show sketchbook commands
1 parent 9630eb2 commit 50e0233

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import {
2020
} from '../../../common/protocol/sketches-service';
2121
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
2222
import { BoardsConfig } from '../../boards/boards-config';
23-
import { Command } from '@theia/core';
23+
import { EncodableCommad } from '../../widgets/sketchbook/encoded-commands-contribution';
2424

2525
interface WorkspaceOptions extends WorkspaceInput {
26-
commands: Command[];
26+
commands: EncodableCommad[];
2727
}
2828

2929
@injectable()

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { Command, CommandRegistry, MaybePromise } from '@theia/core';
1+
import { CommandRegistry, MaybePromise } from '@theia/core';
22
import { inject, injectable } from '@theia/core/shared/inversify';
33
import { Contribution } from '../../contributions/contribution';
44

5+
export type EncodableCommad = {
6+
id: string;
7+
args?: any[];
8+
};
59
@injectable()
610
export class EncodedCommandsContribution extends Contribution {
711
@inject(CommandRegistry)
@@ -15,8 +19,8 @@ export class EncodedCommandsContribution extends Contribution {
1519
const commands = JSON.parse(decodeURIComponent(encoded));
1620

1721
if (Array.isArray(commands)) {
18-
commands.forEach((c: Command) => {
19-
this.commandRegistry.executeCommand(c.id);
22+
commands.forEach((c: EncodableCommad) => {
23+
this.commandRegistry.executeCommand(c.id, c.args);
2024
});
2125
}
2226
}

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Navigatable,
1818
RenderContextMenuOptions,
1919
SelectableTreeNode,
20+
TreeNode,
2021
Widget,
2122
} from '@theia/core/lib/browser';
2223
import {
@@ -29,9 +30,9 @@ import {
2930
} from '../../../common/protocol/sketches-service-client-impl';
3031
import { FileService } from '@theia/filesystem/lib/browser/file-service';
3132
import { URI } from '../../contributions/contribution';
32-
import { EditorManager } from '@theia/editor/lib/browser';
3333
import { SketchControl } from '../../contributions/sketch-control';
34-
import { CloudSketchbookCommands } from '../cloud-sketchbook/cloud-sketchbook-contributions';
34+
import { SketchbookTreeWidget } from './sketchbook-tree-widget';
35+
import { EncodableCommad } from './encoded-commands-contribution';
3536

3637
export const SKETCHBOOK__CONTEXT = ['arduino-sketchbook--context'];
3738

@@ -70,9 +71,6 @@ export class SketchbookWidgetContribution
7071
@inject(FileService)
7172
protected readonly fileService: FileService;
7273

73-
@inject(EditorManager)
74-
protected readonly editorManager: EditorManager;
75-
7674
@inject(SketchControl)
7775
protected readonly sketchControl: SketchControl;
7876

@@ -110,7 +108,8 @@ export class SketchbookWidgetContribution
110108
override registerCommands(registry: CommandRegistry): void {
111109
super.registerCommands(registry);
112110
registry.registerCommand(SketchbookCommands.SHOW_SKETCHBOOK_WIDGET, {
113-
execute: () => this.showLocalSketchbookWidget(),
111+
execute: (treeWidget: SketchbookTreeWidget, node: TreeNode) =>
112+
this.showSketchbookWidget(treeWidget, node),
114113
});
115114
registry.registerCommand(SketchbookCommands.OPEN_NEW_WINDOW, {
116115
execute: (arg) => this.openSketchInNewWindow(arg),
@@ -201,12 +200,16 @@ export class SketchbookWidgetContribution
201200
});
202201
}
203202

204-
openSketchInNewWindow(arg: any): any {
205-
const openSketchbookCommand = this.sketchControl.isCloudSketch(arg.node.uri)
206-
? CloudSketchbookCommands.SHOW_CLOUD_SKETCHBOOK_WIDGET
207-
: SketchbookCommands.SHOW_SKETCHBOOK_WIDGET;
203+
async openSketchInNewWindow(arg: any): Promise<any> {
204+
const treeWidget: SketchbookTreeWidget = (
205+
await this.widget
206+
).getTreeWidget();
207+
const command: EncodableCommad = {
208+
id: SketchbookCommands.SHOW_SKETCHBOOK_WIDGET.id,
209+
args: [treeWidget, arg.node],
210+
};
208211
return this.workspaceService.openWithCommands(arg.node.uri, {
209-
commands: [openSketchbookCommand],
212+
commands: [command],
210213
});
211214
}
212215

@@ -249,13 +252,19 @@ export class SketchbookWidgetContribution
249252
this.selectWidgetFileNode(this.shell.currentWidget);
250253
}
251254

252-
protected async showLocalSketchbookWidget(): Promise<void> {
255+
protected async showSketchbookWidget(
256+
treeWidget: SketchbookTreeWidget,
257+
node: TreeNode
258+
): Promise<void> {
253259
this.widget
254260
.then((widget) => this.shell.activateWidget(widget.id))
255261
.then((widget) => {
256262
if (widget instanceof SketchbookWidget) {
257-
widget.activateTreeWidget(widget.getTreeWidget().id);
258-
this.selectWidgetFileNode(this.editorManager.currentEditor);
263+
widget.activateTreeWidget(treeWidget.id);
264+
if (SelectableTreeNode.is(node)) {
265+
const { model } = treeWidget;
266+
model.selectNode(node);
267+
}
259268
}
260269
});
261270
}

0 commit comments

Comments
 (0)