mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-12 13:56:34 +00:00
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>
This commit is contained in:
parent
c20f832ddf
commit
c50d45c663
@ -1,5 +1,6 @@
|
|||||||
import * as PQueue from 'p-queue';
|
import * as PQueue from 'p-queue';
|
||||||
import { inject, injectable, postConstruct } from 'inversify';
|
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 { MenuPath, CompositeMenuNode, SubMenuOptions } from '@theia/core/lib/common/menu';
|
||||||
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
import { OpenSketch } from './open-sketch';
|
import { OpenSketch } from './open-sketch';
|
||||||
@ -93,12 +94,7 @@ export abstract class Examples extends SketchContribution {
|
|||||||
const { uri } = sketch;
|
const { uri } = sketch;
|
||||||
const commandId = `arduino-open-example-${submenuPath.join(':')}--${uri}`;
|
const commandId = `arduino-open-example-${submenuPath.join(':')}--${uri}`;
|
||||||
const command = { id: commandId };
|
const command = { id: commandId };
|
||||||
const handler = {
|
const handler = this.createHandler(uri);
|
||||||
execute: async () => {
|
|
||||||
const sketch = await this.sketchService.cloneExample(uri);
|
|
||||||
this.commandService.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pushToDispose.push(this.commandRegistry.registerCommand(command, handler));
|
pushToDispose.push(this.commandRegistry.registerCommand(command, handler));
|
||||||
this.menuRegistry.registerMenuAction(submenuPath, { commandId, label: sketch.name, order: sketch.name.toLocaleLowerCase() });
|
this.menuRegistry.registerMenuAction(submenuPath, { commandId, label: sketch.name, order: sketch.name.toLocaleLowerCase() });
|
||||||
pushToDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
|
pushToDispose.push(Disposable.create(() => this.menuRegistry.unregisterMenuAction(command)));
|
||||||
@ -106,6 +102,15 @@ export abstract class Examples extends SketchContribution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
@injectable()
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { CommandHandler } from '@theia/core/lib/common/command';
|
||||||
import { CommandRegistry, MenuModelRegistry } from './contribution';
|
import { CommandRegistry, MenuModelRegistry } from './contribution';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { MainMenuManager } from '../../common/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
import { NotificationCenter } from '../notification-center';
|
import { NotificationCenter } from '../notification-center';
|
||||||
import { Examples } from './examples';
|
import { Examples } from './examples';
|
||||||
import { SketchContainer } from '../../common/protocol';
|
import { SketchContainer } from '../../common/protocol';
|
||||||
|
import { OpenSketch } from './open-sketch';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Sketchbook extends Examples {
|
export class Sketchbook extends Examples {
|
||||||
@ -43,4 +45,13 @@ export class Sketchbook extends Examples {
|
|||||||
this.registerRecursively([...container.children, ...container.sketches], ArduinoMenus.FILE__SKETCHBOOK_SUBMENU, this.toDispose);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user