diff --git a/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts b/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts index ed960356..f4a608bc 100644 --- a/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts +++ b/arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts @@ -58,6 +58,13 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut execute: (uri) => this.newFile(uri), }) ); + registry.unregisterCommand(WorkspaceCommands.NEW_FOLDER); + registry.registerCommand( + WorkspaceCommands.NEW_FOLDER, + this.newWorkspaceRootUriAwareCommandHandler({ + execute: (uri) => this.newFolder(uri), + }) + ); registry.unregisterCommand(WorkspaceCommands.FILE_RENAME); registry.registerCommand( WorkspaceCommands.FILE_RENAME, @@ -72,6 +79,37 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut ); } + private async newFolder(uri: URI | undefined): Promise { + if (!uri) { + return; + } + + const parent = await this.getDirectory(uri); + if (!parent) { + return; + } + + const dialog = new WorkspaceInputDialog( + { + title: nls.localizeByDefault('New Folder...'), + parentUri: uri, + placeholder: nls.localize( + 'theia/workspace/newFolderPlaceholder', + 'Folder Name' + ), + validate: (name) => this.validateFileName(name, parent, true), + }, + this.labelProvider + ); + const name = await this.openDialog(dialog, uri); + if (!name) { + return; + } + const folderUri = uri.resolve(name); + await this.fileService.createFolder(folderUri); + this.fireCreateNewFile({ parent: uri, uri: folderUri }); + } + private async newFile(uri: URI | undefined): Promise { if (!uri) { return; diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts index c8935d66..625cf6fd 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts @@ -25,6 +25,14 @@ export namespace SketchbookCommands { 'arduino/sketch/openFolder' ); + export const NEW_FOLDER = Command.toLocalizedCommand( + { + id: 'arduino-sketchbook--new-folder', + label: 'New Folder', + }, + 'arduino/sketch/newFolder' + ); + export const OPEN_SKETCHBOOK_CONTEXT_MENU: Command = { id: 'arduino-sketchbook--open-sketch-context-menu', iconClass: 'sketchbook-tree__opts', diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts index e73bb7e2..0c368f7e 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts @@ -28,7 +28,10 @@ import { } from '../../sketches-service-client-impl'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; import { URI } from '../../contributions/contribution'; -import { WorkspaceInput } from '@theia/workspace/lib/browser'; +import { + WorkspaceCommands, + WorkspaceInput, +} from '@theia/workspace/lib/browser'; export const SKETCHBOOK__CONTEXT = ['arduino-sketchbook--context']; @@ -130,6 +133,21 @@ export class SketchbookWidgetContribution !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node), }); + registry.registerCommand(SketchbookCommands.NEW_FOLDER, { + execute: async (arg) => { + if (arg.node.uri) { + return registry.executeCommand( + WorkspaceCommands.NEW_FOLDER.id, + arg.node.uri + ); + } + }, + isEnabled: (arg) => + !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node), + isVisible: (arg) => + !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node), + }); + registry.registerCommand(SketchbookCommands.OPEN_SKETCHBOOK_CONTEXT_MENU, { isEnabled: (arg) => !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node), @@ -206,6 +224,12 @@ export class SketchbookWidgetContribution label: SketchbookCommands.REVEAL_IN_FINDER.label, order: '0', }); + + registry.registerMenuAction(SKETCHBOOK__CONTEXT__MAIN_GROUP, { + commandId: SketchbookCommands.NEW_FOLDER.id, + label: SketchbookCommands.NEW_FOLDER.label, + order: '1', + }); } private openNewWindow(