Skip to content

Commit

Permalink
workspace: return stat when executing the rename command (#12278)
Browse files Browse the repository at this point in the history
Closes #12101

The commit updates the `rename` command for files and folders to return the `stat` when a resource is successfully renamed, and `undefined` otherwise.

Signed-off-by: FernandoAscencio <[email protected]>
  • Loading branch information
FernandoAscencio authored Mar 29, 2023
1 parent f82e52b commit 964a022
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,33 +278,32 @@ export class WorkspaceCommandContribution implements CommandContribution {
registry.registerCommand(WorkspaceCommands.FILE_RENAME, this.newMultiUriAwareCommandHandler({
isEnabled: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
isVisible: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
execute: (uris): void => {
uris.forEach(async uri => {
const parent = await this.getParent(uri);
if (parent) {
const oldName = uri.path.base;
const dialog = new SingleTextInputDialog({
title: nls.localizeByDefault('Rename'),
initialValue: oldName,
initialSelectionRange: {
start: 0,
end: uri.path.name.length
},
validate: async (newName, mode) => {
if (oldName === newName && mode === 'preview') {
return false;
}
return this.validateFileRename(oldName, newName, parent);
execute: async uris => {
const uri = uris[0]; /* Since there is only one item in the array. */
const parent = await this.getParent(uri);
if (parent) {
const oldName = uri.path.base;
const dialog = new SingleTextInputDialog({
title: nls.localizeByDefault('Rename'),
initialValue: oldName,
initialSelectionRange: {
start: 0,
end: uri.path.name.length
},
validate: async (newName, mode) => {
if (oldName === newName && mode === 'preview') {
return false;
}
});
const fileName = await dialog.open();
if (fileName) {
const oldUri = uri;
const newUri = uri.parent.resolve(fileName);
this.fileService.move(oldUri, newUri);
return this.validateFileRename(oldName, newName, parent);
}
});
const fileName = await dialog.open();
if (fileName) {
const oldUri = uri;
const newUri = uri.parent.resolve(fileName);
return this.fileService.move(oldUri, newUri);
}
});
}
}
}));
registry.registerCommand(WorkspaceCommands.FILE_DUPLICATE, this.newMultiUriAwareCommandHandler(this.duplicateHandler));
Expand Down

0 comments on commit 964a022

Please sign in to comment.