mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-28 05:36:35 +00:00
App doesn't show "open..." anymore if there are no sketches in default sketch folder.
Opens file navigator directly instead. Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
parent
6e0a0a19c5
commit
c2fbccc9e8
@ -1,10 +1,7 @@
|
|||||||
import { injectable, inject } from "inversify";
|
import { injectable, inject } from "inversify";
|
||||||
import { MenuContribution, MenuModelRegistry, MenuPath, CommandRegistry, Command } from "@theia/core";
|
import { MenuContribution, MenuModelRegistry, MenuPath } from "@theia/core";
|
||||||
import { CommonMenus } from "@theia/core/lib/browser";
|
import { CommonMenus } from "@theia/core/lib/browser";
|
||||||
import { ArduinoCommands } from "./arduino-commands";
|
import { ArduinoCommands } from "./arduino-commands";
|
||||||
import { SketchesService, Sketch } from "../common/protocol/sketches-service";
|
|
||||||
import { AWorkspaceService } from "./arduino-workspace-service";
|
|
||||||
import { BoardsService } from "../common/protocol/boards-service";
|
|
||||||
|
|
||||||
export namespace ArduinoToolbarContextMenu {
|
export namespace ArduinoToolbarContextMenu {
|
||||||
export const OPEN_SKETCH_PATH: MenuPath = ['arduino-open-sketch-context-menu'];
|
export const OPEN_SKETCH_PATH: MenuPath = ['arduino-open-sketch-context-menu'];
|
||||||
@ -20,55 +17,14 @@ export namespace ArduinoToolbarContextMenu {
|
|||||||
@injectable()
|
@injectable()
|
||||||
export class ArduinoToolbarMenuContribution implements MenuContribution {
|
export class ArduinoToolbarMenuContribution implements MenuContribution {
|
||||||
|
|
||||||
@inject(CommandRegistry)
|
|
||||||
protected readonly commands: CommandRegistry;
|
|
||||||
|
|
||||||
@inject(SketchesService)
|
|
||||||
protected readonly sketches: SketchesService;
|
|
||||||
|
|
||||||
@inject(BoardsService)
|
|
||||||
protected readonly boardsService: BoardsService;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject(AWorkspaceService) protected readonly workspaceService: AWorkspaceService,
|
|
||||||
@inject(MenuModelRegistry) protected readonly menuRegistry: MenuModelRegistry) {
|
@inject(MenuModelRegistry) protected readonly menuRegistry: MenuModelRegistry) {
|
||||||
workspaceService.onWorkspaceChanged(() => {
|
|
||||||
if (this.workspaceService.workspace) {
|
|
||||||
this.registerSketchesInMenu(menuRegistry);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async registerSketchesInMenu(registry: MenuModelRegistry) {
|
|
||||||
const sketches = await this.getWorkspaceSketches();
|
|
||||||
sketches.forEach(sketch => {
|
|
||||||
const command: Command = {
|
|
||||||
id: 'openSketch' + sketch.name
|
|
||||||
}
|
|
||||||
this.commands.registerCommand(command, {
|
|
||||||
execute: () => this.commands.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
|
|
||||||
});
|
|
||||||
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
|
|
||||||
commandId: command.id,
|
|
||||||
label: sketch.name
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async getWorkspaceSketches(): Promise<Sketch[]> {
|
|
||||||
const sketches = this.sketches.getSketches(this.workspaceService.workspace);
|
|
||||||
return sketches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry) {
|
registerMenus(registry: MenuModelRegistry) {
|
||||||
registry.registerMenuAction([...CommonMenus.FILE, '0_new_sletch'], {
|
registry.registerMenuAction([...CommonMenus.FILE, '0_new_sletch'], {
|
||||||
commandId: ArduinoCommands.NEW_SKETCH.id
|
commandId: ArduinoCommands.NEW_SKETCH.id
|
||||||
});
|
})
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoToolbarContextMenu.OPEN_GROUP, {
|
|
||||||
commandId: ArduinoCommands.OPEN_FILE_NAVIGATOR.id,
|
|
||||||
label: 'Open...'
|
|
||||||
});
|
|
||||||
|
|
||||||
registry.registerMenuAction(ArduinoToolbarContextMenu.OPEN_BOARDS_DIALOG_GROUP, {
|
registry.registerMenuAction(ArduinoToolbarContextMenu.OPEN_BOARDS_DIALOG_GROUP, {
|
||||||
commandId: ArduinoCommands.OPEN_BOARDS_DIALOG.id,
|
commandId: ArduinoCommands.OPEN_BOARDS_DIALOG.id,
|
||||||
|
@ -66,9 +66,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
@inject(BoardsNotificationService)
|
@inject(BoardsNotificationService)
|
||||||
protected readonly boardsNotificationService: BoardsNotificationService;
|
protected readonly boardsNotificationService: BoardsNotificationService;
|
||||||
|
|
||||||
@inject(WorkspaceService)
|
|
||||||
protected readonly workspaceService: WorkspaceService;
|
|
||||||
|
|
||||||
@inject(SelectionService)
|
@inject(SelectionService)
|
||||||
protected readonly selectionService: SelectionService;
|
protected readonly selectionService: SelectionService;
|
||||||
|
|
||||||
@ -108,6 +105,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
protected boardsToolbarItem: BoardsToolBarItem | null;
|
protected boardsToolbarItem: BoardsToolBarItem | null;
|
||||||
protected attachedBoards: Board[];
|
protected attachedBoards: Board[];
|
||||||
protected selectedBoard: Board;
|
protected selectedBoard: Board;
|
||||||
|
protected wsSketchCount: number = 0;
|
||||||
|
|
||||||
|
constructor(@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) {
|
||||||
|
this.workspaceService.onWorkspaceChanged(() => {
|
||||||
|
if (this.workspaceService.workspace) {
|
||||||
|
this.registerSketchesInMenu(this.menuRegistry);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
@postConstruct()
|
@postConstruct()
|
||||||
protected async init(): Promise<void> {
|
protected async init(): Promise<void> {
|
||||||
@ -233,12 +239,16 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
isVisible: widget => this.isArduinoToolbar(widget),
|
isVisible: widget => this.isArduinoToolbar(widget),
|
||||||
isEnabled: widget => this.isArduinoToolbar(widget),
|
isEnabled: widget => this.isArduinoToolbar(widget),
|
||||||
execute: async (widget: Widget, target: EventTarget) => {
|
execute: async (widget: Widget, target: EventTarget) => {
|
||||||
const el = (target as HTMLElement).parentElement;
|
if (this.wsSketchCount) {
|
||||||
if (el) {
|
const el = (target as HTMLElement).parentElement;
|
||||||
this.contextMenuRenderer.render(ArduinoToolbarContextMenu.OPEN_SKETCH_PATH, {
|
if (el) {
|
||||||
x: el.getBoundingClientRect().left,
|
this.contextMenuRenderer.render(ArduinoToolbarContextMenu.OPEN_SKETCH_PATH, {
|
||||||
y: el.getBoundingClientRect().top + el.offsetHeight
|
x: el.getBoundingClientRect().left,
|
||||||
});
|
y: el.getBoundingClientRect().top + el.offsetHeight
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.commands.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -332,6 +342,10 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
label: 'Upload',
|
label: 'Upload',
|
||||||
order: '2'
|
order: '2'
|
||||||
});
|
});
|
||||||
|
registry.registerMenuAction(ArduinoToolbarContextMenu.OPEN_GROUP, {
|
||||||
|
commandId: ArduinoCommands.OPEN_FILE_NAVIGATOR.id,
|
||||||
|
label: 'Open...'
|
||||||
|
});
|
||||||
|
|
||||||
registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools');
|
registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools');
|
||||||
}
|
}
|
||||||
@ -342,6 +356,30 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
return menuId;
|
return menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected registerSketchesInMenu(registry: MenuModelRegistry) {
|
||||||
|
this.getWorkspaceSketches().then(sketches => {
|
||||||
|
this.wsSketchCount = sketches.length;
|
||||||
|
sketches.forEach(sketch => {
|
||||||
|
const command: Command = {
|
||||||
|
id: 'openSketch' + sketch.name
|
||||||
|
}
|
||||||
|
this.commands.registerCommand(command, {
|
||||||
|
execute: () => this.commands.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
|
||||||
|
commandId: command.id,
|
||||||
|
label: sketch.name
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async getWorkspaceSketches(): Promise<Sketch[]> {
|
||||||
|
const sketches = this.sketches.getSketches(this.workspaceService.workspace);
|
||||||
|
return sketches;
|
||||||
|
}
|
||||||
|
|
||||||
protected async openSketchFilesInNewWindow(uri: string) {
|
protected async openSketchFilesInNewWindow(uri: string) {
|
||||||
const location = new URL(window.location.href);
|
const location = new URL(window.location.href);
|
||||||
location.searchParams.set('sketch', uri);
|
location.searchParams.set('sketch', uri);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user