Skip to content

Commit 49f2e5c

Browse files
Akos KittaAlberto Iannaccone
authored andcommitted
pair session changes.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 50e0233 commit 49f2e5c

File tree

9 files changed

+170
-160
lines changed

9 files changed

+170
-160
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ import { CoreErrorHandler } from './contributions/core-error-handler';
302302
import { CompilerErrors } from './contributions/compiler-errors';
303303
import { WidgetManager } from './theia/core/widget-manager';
304304
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
305-
import { EncodedCommandsContribution } from './widgets/sketchbook/encoded-commands-contribution';
305+
import { StartupTask } from './widgets/sketchbook/startup-task';
306306

307307
MonacoThemingService.register({
308308
id: 'arduino-theme',
@@ -699,7 +699,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
699699
Contribution.configure(bind, PlotterFrontendContribution);
700700
Contribution.configure(bind, Format);
701701
Contribution.configure(bind, CompilerErrors);
702-
Contribution.configure(bind, EncodedCommandsContribution);
702+
Contribution.configure(bind, StartupTask);
703703

704704
// Disabled the quick-pick customization from Theia when multiple formatters are available.
705705
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.
@@ -834,7 +834,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
834834

835835
bind(CloudSketchbookWidget).toSelf();
836836
rebind(SketchbookWidget).toService(CloudSketchbookWidget);
837-
bind(CommandContribution).toService(CloudSketchbookWidget);
838837
bind(CloudSketchbookTreeWidget).toDynamicValue(({ container }) =>
839838
createCloudSketchbookTreeWidget(container)
840839
);

arduino-ide-extension/src/browser/contributions/sketch-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class SketchControl extends SketchContribution {
250250
});
251251
}
252252

253-
isCloudSketch(uri: string): boolean {
253+
protected isCloudSketch(uri: string): boolean {
254254
try {
255255
const cloudCacheLocation = this.localCacheFsProvider.from(new URI(uri));
256256

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

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ import {
2020
} from '../../../common/protocol/sketches-service';
2121
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
2222
import { BoardsConfig } from '../../boards/boards-config';
23-
import { EncodableCommad } from '../../widgets/sketchbook/encoded-commands-contribution';
24-
25-
interface WorkspaceOptions extends WorkspaceInput {
26-
commands: EncodableCommad[];
27-
}
23+
import { FileStat } from '@theia/filesystem/lib/common/files';
24+
import { StartupTask } from '../../widgets/sketchbook/startup-task';
2825

2926
@injectable()
3027
export class WorkspaceService extends TheiaWorkspaceService {
@@ -90,11 +87,13 @@ export class WorkspaceService extends TheiaWorkspaceService {
9087
}
9188
}
9289

93-
/*
94-
This method mostly duplicates super.doOpen and super.openWindow because they didn't let pass any custom
95-
option to openNewWindow
96-
*/
97-
async openWithCommands(uri: URI, options?: WorkspaceOptions): Promise<void> {
90+
/**
91+
* Copied from Theia as-is to be able to pass the original `options` down.
92+
*/
93+
protected override async doOpen(
94+
uri: URI,
95+
options?: WorkspaceInput
96+
): Promise<URI | undefined> {
9897
const stat = await this.toFileStat(uri);
9998
if (stat) {
10099
if (!stat.isDirectory && !this.isWorkspaceFile(stat)) {
@@ -114,41 +113,46 @@ export class WorkspaceService extends TheiaWorkspaceService {
114113
if (preserveWindow) {
115114
this._workspace = stat;
116115
}
117-
118-
const workspacePath = stat.resource.path.toString();
119-
120-
if (this.shouldPreserveWindow(options)) {
121-
this.reloadWindow();
122-
} else {
123-
try {
124-
this.openNewWindow(workspacePath, options);
125-
return;
126-
} catch (error) {
127-
// Fall back to reloading the current window in case the browser has blocked the new window
128-
this._workspace = stat;
129-
this.logger.error(error.toString()).then(() => this.reloadWindow());
130-
}
131-
}
116+
this.openWindow(stat, Object.assign(options ?? {}, { preserveWindow }));
117+
return;
132118
}
133119
throw new Error(
134120
'Invalid workspace root URI. Expected an existing directory or workspace file.'
135121
);
136122
}
137123

124+
/**
125+
* Copied from Theia. Can pass the `options` further down the chain.
126+
*/
127+
protected override openWindow(uri: FileStat, options?: WorkspaceInput): void {
128+
const workspacePath = uri.resource.path.toString();
129+
if (this.shouldPreserveWindow(options)) {
130+
this.reloadWindow();
131+
} else {
132+
try {
133+
this.openNewWindow(workspacePath, options); // Unlike Theia, IDE2 passes the `input` downstream.
134+
} catch (error) {
135+
// Fall back to reloading the current window in case the browser has blocked the new window
136+
this._workspace = uri;
137+
this.logger.error(error.toString()).then(() => this.reloadWindow());
138+
}
139+
}
140+
}
141+
138142
protected override openNewWindow(
139143
workspacePath: string,
140-
options?: WorkspaceOptions
144+
options?: WorkspaceInput
141145
): void {
142146
const { boardsConfig } = this.boardsServiceProvider;
143147
const url = BoardsConfig.Config.setConfig(
144148
boardsConfig,
145149
new URL(window.location.href)
146150
); // Set the current boards config for the new browser window.
147151
url.hash = workspacePath;
148-
if (options?.commands) {
152+
if (StartupTask.WorkspaceInput.is(options)) {
149153
url.searchParams.set(
150-
'commands',
151-
encodeURIComponent(JSON.stringify(options.commands))
154+
StartupTask.QUERY_STRING,
155+
encodeURIComponent(JSON.stringify(options.tasks))
152156
);
153157
}
154158

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
1-
import {
2-
inject,
3-
injectable,
4-
postConstruct,
5-
} from '@theia/core/shared/inversify';
1+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
62
import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget';
73
import { SketchbookWidget } from '../sketchbook/sketchbook-widget';
84
import { ArduinoPreferences } from '../../arduino-preferences';
9-
import { CommandContribution, CommandRegistry } from '@theia/core';
10-
import { ApplicationShell } from '@theia/core/lib/browser';
11-
import { CloudSketchbookCommands } from './cloud-sketchbook-contributions';
12-
import { EditorManager } from '@theia/editor/lib/browser';
13-
import { SketchbookWidgetContribution } from '../sketchbook/sketchbook-widget-contribution';
145

156
@injectable()
16-
export class CloudSketchbookWidget
17-
extends SketchbookWidget
18-
implements CommandContribution
19-
{
7+
export class CloudSketchbookWidget extends SketchbookWidget {
208
@inject(CloudSketchbookCompositeWidget)
21-
private readonly cloudSketchbookCompositeWidget: CloudSketchbookCompositeWidget;
9+
protected readonly widget: CloudSketchbookCompositeWidget;
2210

2311
@inject(ArduinoPreferences)
24-
private readonly arduinoPreferences: ArduinoPreferences;
25-
26-
@inject(ApplicationShell)
27-
private readonly shell: ApplicationShell;
28-
29-
@inject(SketchbookWidgetContribution)
30-
private readonly sketchbookWidgetContribution: SketchbookWidgetContribution;
31-
32-
@inject(EditorManager)
33-
private readonly editorManager: EditorManager;
12+
protected readonly arduinoPreferences: ArduinoPreferences;
3413

3514
@postConstruct()
3615
protected override init(): void {
@@ -48,9 +27,7 @@ export class CloudSketchbookWidget
4827

4928
checkCloudEnabled() {
5029
if (this.arduinoPreferences['arduino.cloud.enabled']) {
51-
this.sketchbookTreesContainer.activateWidget(
52-
this.cloudSketchbookCompositeWidget
53-
);
30+
this.sketchbookTreesContainer.activateWidget(this.widget);
5431
} else {
5532
this.sketchbookTreesContainer.activateWidget(
5633
this.localSketchbookTreeWidget
@@ -68,9 +45,7 @@ export class CloudSketchbookWidget
6845
}
6946

7047
protected override onAfterAttach(msg: any): void {
71-
this.sketchbookTreesContainer.addWidget(
72-
this.cloudSketchbookCompositeWidget
73-
);
48+
this.sketchbookTreesContainer.addWidget(this.widget);
7449
this.setDocumentMode();
7550
this.arduinoPreferences.onPreferenceChanged((event) => {
7651
if (event.preferenceName === 'arduino.cloud.enabled') {
@@ -79,29 +54,4 @@ export class CloudSketchbookWidget
7954
});
8055
super.onAfterAttach(msg);
8156
}
82-
83-
registerCommands(registry: CommandRegistry): void {
84-
this.sketchbookTreesContainer.addWidget(
85-
this.cloudSketchbookCompositeWidget
86-
);
87-
registry.registerCommand(
88-
CloudSketchbookCommands.SHOW_CLOUD_SKETCHBOOK_WIDGET,
89-
{
90-
execute: () => this.showCloudSketchbookWidget(),
91-
}
92-
);
93-
}
94-
95-
showCloudSketchbookWidget(): void {
96-
if (this.arduinoPreferences['arduino.cloud.enabled']) {
97-
this.shell.activateWidget(this.id).then((widget) => {
98-
if (widget instanceof CloudSketchbookWidget) {
99-
widget.activateTreeWidget(this.cloudSketchbookCompositeWidget.id);
100-
}
101-
this.sketchbookWidgetContribution.selectWidgetFileNode(
102-
this.editorManager.currentEditor
103-
);
104-
});
105-
}
106-
}
10757
}

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ export namespace SketchbookCommands {
55
id: 'arduino-sketchbook-widget:toggle',
66
};
77

8-
export const SHOW_SKETCHBOOK_WIDGET = Command.toLocalizedCommand(
8+
export const REVEAL_SKETCH_NODE = Command.toLocalizedCommand(
99
{
10-
id: 'arduino-sketchbook--show-sketchbook-widget',
11-
label: 'Show Sketchbook Widget',
10+
id: 'arduino-sketchbook--reveal-sketch-node',
1211
},
13-
'arduino/sketch/showSketchbookWidget'
12+
'arduino/sketch/revealSketchNode'
1413
);
1514

1615
export const OPEN_NEW_WINDOW = Command.toLocalizedCommand(

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

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
Navigatable,
1818
RenderContextMenuOptions,
1919
SelectableTreeNode,
20-
TreeNode,
2120
Widget,
2221
} from '@theia/core/lib/browser';
2322
import {
@@ -30,9 +29,7 @@ import {
3029
} from '../../../common/protocol/sketches-service-client-impl';
3130
import { FileService } from '@theia/filesystem/lib/browser/file-service';
3231
import { URI } from '../../contributions/contribution';
33-
import { SketchControl } from '../../contributions/sketch-control';
34-
import { SketchbookTreeWidget } from './sketchbook-tree-widget';
35-
import { EncodableCommad } from './encoded-commands-contribution';
32+
import { WorkspaceInput } from '@theia/workspace/lib/browser';
3633

3734
export const SKETCHBOOK__CONTEXT = ['arduino-sketchbook--context'];
3835

@@ -71,9 +68,6 @@ export class SketchbookWidgetContribution
7168
@inject(FileService)
7269
protected readonly fileService: FileService;
7370

74-
@inject(SketchControl)
75-
protected readonly sketchControl: SketchControl;
76-
7771
protected readonly toDisposeBeforeNewContextMenu = new DisposableCollection();
7872

7973
constructor() {
@@ -107,12 +101,32 @@ export class SketchbookWidgetContribution
107101

108102
override registerCommands(registry: CommandRegistry): void {
109103
super.registerCommands(registry);
110-
registry.registerCommand(SketchbookCommands.SHOW_SKETCHBOOK_WIDGET, {
111-
execute: (treeWidget: SketchbookTreeWidget, node: TreeNode) =>
112-
this.showSketchbookWidget(treeWidget, node),
104+
registry.registerCommand(SketchbookCommands.REVEAL_SKETCH_NODE, {
105+
execute: (treeWidgetId: string, nodeId: string) =>
106+
this.revealSketchNode(treeWidgetId, nodeId),
113107
});
114108
registry.registerCommand(SketchbookCommands.OPEN_NEW_WINDOW, {
115-
execute: (arg) => this.openSketchInNewWindow(arg),
109+
execute: (arg) => {
110+
const widget = this.tryGetWidget();
111+
if (widget) {
112+
const treeWidgetId = widget.activeTreeWidgetId();
113+
if (!treeWidgetId) {
114+
console.warn(`Could not retrieve active sketchbook tree ID.`);
115+
return;
116+
}
117+
const nodeId = arg.node.id;
118+
const options: WorkspaceInput = {};
119+
Object.assign(options, {
120+
tasks: [
121+
{
122+
command: SketchbookCommands.REVEAL_SKETCH_NODE.id,
123+
args: [treeWidgetId, nodeId],
124+
},
125+
],
126+
});
127+
return this.workspaceService.open(arg.node.uri, options);
128+
}
129+
},
116130
isEnabled: (arg) =>
117131
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
118132
isVisible: (arg) =>
@@ -200,19 +214,6 @@ export class SketchbookWidgetContribution
200214
});
201215
}
202216

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-
};
211-
return this.workspaceService.openWithCommands(arg.node.uri, {
212-
commands: [command],
213-
});
214-
}
215-
216217
override registerMenus(registry: MenuModelRegistry): void {
217218
super.registerMenus(registry);
218219

@@ -252,19 +253,15 @@ export class SketchbookWidgetContribution
252253
this.selectWidgetFileNode(this.shell.currentWidget);
253254
}
254255

255-
protected async showSketchbookWidget(
256-
treeWidget: SketchbookTreeWidget,
257-
node: TreeNode
256+
private async revealSketchNode(
257+
treeWidgetId: string,
258+
nodeId: string
258259
): Promise<void> {
259-
this.widget
260+
return this.widget
260261
.then((widget) => this.shell.activateWidget(widget.id))
261262
.then((widget) => {
262263
if (widget instanceof SketchbookWidget) {
263-
widget.activateTreeWidget(treeWidget.id);
264-
if (SelectableTreeNode.is(node)) {
265-
const { model } = treeWidget;
266-
model.selectNode(node);
267-
}
264+
return widget.revealSketchNode(treeWidgetId, nodeId);
268265
}
269266
});
270267
}

0 commit comments

Comments
 (0)