mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-13 14:26:37 +00:00
feat: can create new folder
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
parent
67e863d9ea
commit
fb3c0cab7f
@ -58,6 +58,13 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
|
|||||||
execute: (uri) => this.newFile(uri),
|
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.unregisterCommand(WorkspaceCommands.FILE_RENAME);
|
||||||
registry.registerCommand(
|
registry.registerCommand(
|
||||||
WorkspaceCommands.FILE_RENAME,
|
WorkspaceCommands.FILE_RENAME,
|
||||||
@ -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> {
|
private async newFile(uri: URI | undefined): Promise<void> {
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
return;
|
return;
|
||||||
|
@ -25,6 +25,14 @@ export namespace SketchbookCommands {
|
|||||||
'arduino/sketch/openFolder'
|
'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 = {
|
export const OPEN_SKETCHBOOK_CONTEXT_MENU: Command = {
|
||||||
id: 'arduino-sketchbook--open-sketch-context-menu',
|
id: 'arduino-sketchbook--open-sketch-context-menu',
|
||||||
iconClass: 'sketchbook-tree__opts',
|
iconClass: 'sketchbook-tree__opts',
|
||||||
|
@ -28,7 +28,10 @@ import {
|
|||||||
} from '../../sketches-service-client-impl';
|
} from '../../sketches-service-client-impl';
|
||||||
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
||||||
import { URI } from '../../contributions/contribution';
|
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'];
|
export const SKETCHBOOK__CONTEXT = ['arduino-sketchbook--context'];
|
||||||
|
|
||||||
@ -130,6 +133,21 @@ export class SketchbookWidgetContribution
|
|||||||
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
|
!!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, {
|
registry.registerCommand(SketchbookCommands.OPEN_SKETCHBOOK_CONTEXT_MENU, {
|
||||||
isEnabled: (arg) =>
|
isEnabled: (arg) =>
|
||||||
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
|
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
|
||||||
@ -206,6 +224,12 @@ export class SketchbookWidgetContribution
|
|||||||
label: SketchbookCommands.REVEAL_IN_FINDER.label,
|
label: SketchbookCommands.REVEAL_IN_FINDER.label,
|
||||||
order: '0',
|
order: '0',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registry.registerMenuAction(SKETCHBOOK__CONTEXT__MAIN_GROUP, {
|
||||||
|
commandId: SketchbookCommands.NEW_FOLDER.id,
|
||||||
|
label: SketchbookCommands.NEW_FOLDER.label,
|
||||||
|
order: '1',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private openNewWindow(
|
private openNewWindow(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user