Skip to content

Commit

Permalink
arduinoGH-297: Fixed the open from Sketchbook handler.
Browse files Browse the repository at this point in the history
When running the handler for the `Sketchbook` menu, do not clone the
sketch.

Closes arduino#297

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta authored and kittaakos committed Apr 14, 2021
1 parent c20f832 commit c50d45c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions arduino-ide-extension/src/browser/contributions/examples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as PQueue from 'p-queue';
import { inject, injectable, postConstruct } from 'inversify';
import { CommandHandler } from '@theia/core/lib/common/command';
import { MenuPath, CompositeMenuNode, SubMenuOptions } from '@theia/core/lib/common/menu';
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
import { OpenSketch } from './open-sketch';
Expand Down Expand Up @@ -93,19 +94,23 @@ export abstract class Examples extends SketchContribution {
const { uri } = sketch;
const commandId = `arduino-open-example-${submenuPath.join(':')}--${uri}`;
const command = { id: commandId };
const handler = {
execute: async () => {
const sketch = await this.sketchService.cloneExample(uri);
this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
}
};
const handler = this.createHandler(uri);
pushToDispose.push(this.commandRegistry.registerCommand(command, handler));
this.menuRegistry.registerMenuAction(submenuPath, { commandId, label: sketch.name, order: sketch.name.toLocaleLowerCase() });
pushToDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
}
}
}

protected createHandler(uri: string): CommandHandler {
return {
execute: async () => {
const sketch = await this.sketchService.cloneExample(uri);
return this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
}
}
}

}

@injectable()
Expand Down
11 changes: 11 additions & 0 deletions arduino-ide-extension/src/browser/contributions/sketchbook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { inject, injectable } from 'inversify';
import { CommandHandler } from '@theia/core/lib/common/command';
import { CommandRegistry, MenuModelRegistry } from './contribution';
import { ArduinoMenus } from '../menu/arduino-menus';
import { MainMenuManager } from '../../common/main-menu-manager';
import { NotificationCenter } from '../notification-center';
import { Examples } from './examples';
import { SketchContainer } from '../../common/protocol';
import { OpenSketch } from './open-sketch';

@injectable()
export class Sketchbook extends Examples {
Expand Down Expand Up @@ -43,4 +45,13 @@ export class Sketchbook extends Examples {
this.registerRecursively([...container.children, ...container.sketches], ArduinoMenus.FILE__SKETCHBOOK_SUBMENU, this.toDispose);
}

protected createHandler(uri: string): CommandHandler {
return {
execute: async () => {
const sketch = await this.sketchService.loadSketch(uri);
return this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
}
}
}

}

0 comments on commit c50d45c

Please sign in to comment.