8000 feat: can create new folder · arduino/arduino-ide@fb3c0ca · GitHub
[go: up one dir, main page]

Skip to content

Commit fb3c0ca

Browse files
author
Akos Kitta
committed
feat: can create new folder
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 67e863d commit fb3c0ca

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

arduino-ide-extension/src/browser/theia/workspace/workspace-commands.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
5858
execute: (uri) => this.newFile(uri),
5959
})
6060
);
61+
registry.unregisterCommand(WorkspaceCommands.NEW_FOLDER);
62+
registry.registerCommand(
63+
WorkspaceCommands.NEW_FOLDER,
64+
this.newWorkspaceRootUriAwareCommandHandler({
65+
execute: (uri) => this.newFolder(uri),
66+
})
67+
);
6168
registry.unregisterCommand(< 8000 /span>WorkspaceCommands.FILE_RENAME);
6269
registry.registerCommand(
6370
WorkspaceCommands.FILE_RENAME,
@@ -72,6 +79,37 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
7279
);
7380
}
7481

82+
private async newFolder(uri: URI | undefined): Promise<void> {
83+
if (!uri) {
84+
return;
85+
}
86+
87+
const parent = await this.getDirectory(uri);
88+
if (!parent) {
89+
return;
90+
}
91+
92+
const dialog = new WorkspaceInputDialog(
93+
{
94+
title: nls.localizeByDefault('New Folder...'),
95+
parentUri: uri,
96+
placeholder: nls.localize(
97+
'theia/workspace/newFolderPlaceholder',
98+
'Folder Name'
99+
),
100+
validate: (name) => this.validateFileName(name, parent, true),
101+
},
102+
this.labelProvider
103+
);
104+
const name = await this.openDialog(dialog, uri);
105+
if (!name) {
106+
return;
107+
}
108+
const folderUri = uri.resolve(name);
109+
await this.fileService.createFolder(folderUri);
110+
this.fireCreateNewFile({ parent: uri, uri: folderUri });
111+
}
112+
75113
private async newFile(uri: URI | undefined): Promise<void> {
76114
if (!uri) {
77115
return;

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ export namespace SketchbookCommands {
2525
'arduino/sketch/openFolder'
2626
);
2727

28+
export const NEW_FOLDER = Command.toLocalizedCommand(
29+
{
30+
id: 'arduino-sketchbook--new-folder',
31+
label: 'New Folder',
32+
},
33+
'arduino/sketch/newFolder'
34+
);
35+
2836
export const OPEN_SKETCHBOOK_CONTEXT_MENU: Command = {
2937
id: 'arduino-sketchbook--open-sketch-context-menu',
3038
iconClass: 'sketchbook-tree__opts',

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import {
2828
} from '../../sketches-service-client-impl';
2929
import { FileService } from '@theia/filesystem/lib/browser/file-service';
3030
import { URI } from '../../contributions/contribution';
31-
import { WorkspaceInput } from '@theia/workspace/lib/browser';
31+
import {
32+
WorkspaceCommands,
33+
WorkspaceInput,
34+
} from '@theia/workspace/lib/browser';
3235

3336
export const SKETCHBOOK__CONTEXT = ['arduino-sketchbook--context'];
3437

@@ -130,6 +133,21 @@ export class SketchbookWidgetContribution
130133
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
131134
});
132135

136+
registry.registerCommand(SketchbookCommands.NEW_FOLDER, {
137+
execute: async (arg) => {
138+
if (arg.node.uri) {
139+
return registry.executeCommand(
140+
WorkspaceCommands.NEW_FOLDER.id,
141+
arg.node.uri
142+
);
143+
}
144+
},
145+
isEnabled: (arg) =>
146+
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
147+
isVisible: (arg) =>
148+
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
149+
});
150+
133151
registry.registerCommand(SketchbookCommands.OPEN_SKETCHBOOK_CONTEXT_MENU, {
134152
isEnabled: (arg) =>
135153
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
@@ -206,6 +224,12 @@ export class SketchbookWidgetContribution
206224
label: SketchbookCommands.REVEAL_IN_FINDER.label,
207225
order: '0',
208226
});
227+
228+
registry.registerMenuAction(SKETCHBOOK__CONTEXT__MAIN_GROUP, {
229+
commandId: SketchbookCommands.NEW_FOLDER.id,
230+
label: SketchbookCommands.NEW_FOLDER.label,
231+
order: '1',
232+
});
209233
}
210234

211235
private openNewWindow(

0 commit comments

Comments
 (0)
0