Skip to content

Commit c50d45c

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
GH-297: Fixed the open from Sketchbook handler.
When running the handler for the `Sketchbook` menu, do not clone the sketch. Closes #297 Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent c20f832 commit c50d45c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

arduino-ide-extension/src/browser/contributions/examples.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as PQueue from 'p-queue';
22
import { inject, injectable, postConstruct } from 'inversify';
3+
import { CommandHandler } from '@theia/core/lib/common/command';
34
import { MenuPath, CompositeMenuNode, SubMenuOptions } from '@theia/core/lib/common/menu';
45
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
56
import { OpenSketch } from './open-sketch';
@@ -93,19 +94,23 @@ export abstract class Examples extends SketchContribution {
9394
const { uri } = sketch;
9495
const commandId = `arduino-open-example-${submenuPath.join(':')}--${uri}`;
9596
const command = { id: commandId };
96-
const handler = {
97-
execute: async () => {
98-
const sketch = await this.sketchService.cloneExample(uri);
99-
this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
100-
}
101-
};
97+
const handler = this.createHandler(uri);
10298
pushToDispose.push(this.commandRegistry.registerCommand(command, handler));
10399
this.menuRegistry.registerMenuAction(submenuPath, { commandId, label: sketch.name, order: sketch.name.toLocaleLowerCase() });
104100
pushToDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
105101
}
106102
}
107103
}
108104

105+
protected createHandler(uri: string): CommandHandler {
106+
return {
107+
execute: async () => {
108+
const sketch = await this.sketchService.cloneExample(uri);
109+
return this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
110+
}
111+
}
112+
}
113+
109114
}
110115

111116
@injectable()

arduino-ide-extension/src/browser/contributions/sketchbook.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { inject, injectable } from 'inversify';
2+
import { CommandHandler } from '@theia/core/lib/common/command';
23
import { CommandRegistry, MenuModelRegistry } from './contribution';
34
import { ArduinoMenus } from '../menu/arduino-menus';
45
import { MainMenuManager } from '../../common/main-menu-manager';
56
import { NotificationCenter } from '../notification-center';
67
import { Examples } from './examples';
78
import { SketchContainer } from '../../common/protocol';
9+
import { OpenSketch } from './open-sketch';
810

911
@injectable()
1012
export class Sketchbook extends Examples {
@@ -43,4 +45,13 @@ export class Sketchbook extends Examples {
4345
this.registerRecursively([...container.children, ...container.sketches], ArduinoMenus.FILE__SKETCHBOOK_SUBMENU, this.toDispose);
4446
}
4547

48+
protected createHandler(uri: string): CommandHandler {
49+
return {
50+
execute: async () => {
51+
const sketch = await this.sketchService.loadSketch(uri);
52+
return this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
53+
}
54+
}
55+
}
56+
4657
}

0 commit comments

Comments
 (0)