Skip to content

Commit

Permalink
feat: can create new folder
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Feb 23, 2024
1 parent 67e863d commit fb3c0ca
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -72,6 +79,37 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
);
}

private async newFolder(uri: URI | undefined): Promise<void> {
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<void> {
if (!uri) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fb3c0ca

Please sign in to comment.