Skip to content

Commit

Permalink
(#3273) Fix issues in Rename command
Browse files Browse the repository at this point in the history
1) Disable rename option for workspace root.
2) Fix rename string displayed while renaming folders.

Signed-off-by: Karthik Bhat <kv.bhat@samsung.com>
  • Loading branch information
kvbhat authored and jbicker committed Oct 26, 2018
1 parent c86a33b commit 81c8a93
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,18 @@ export class WorkspaceCommandContribution implements CommandContribution {
})
}));
registry.registerCommand(WorkspaceCommands.FILE_RENAME, this.newUriAwareCommandHandler({
execute: uri => this.getParent(uri).then(parent => {
isVisible: uri => !this.isWorkspaceRoot(uri),
execute: uri => this.getParent(uri).then(async parent => {
if (parent) {
const initialValue = uri.path.base;
const stat = await this.fileSystem.getFileStat(uri.toString());
if (stat === undefined) {
throw new Error(`Unexpected error occurred when renaming. File does not exist. URI: ${uri.toString(true)}.`);
}
const fileType = stat.isDirectory ? 'Directory' : 'File';
const titleStr = `Rename ${fileType}`;
const dialog = new SingleTextInputDialog({
title: 'Rename File',
title: titleStr,
initialValue,
initialSelectionRange: {
start: 0,
Expand Down Expand Up @@ -376,6 +383,11 @@ export class WorkspaceCommandContribution implements CommandContribution {
return uris.every(uri => rootUris.has(uri.toString()));
}

protected isWorkspaceRoot(uri: URI): boolean {
const rootUris = new Set(this.workspaceService.tryGetRoots().map(root => root.uri));
return rootUris.has(uri.toString());
}

protected async removeFolderFromWorkspace(uris: URI[]): Promise<void> {
const roots = new Set(this.workspaceService.tryGetRoots().map(r => r.uri));
const toRemove = uris.filter(u => roots.has(u.toString()));
Expand Down

0 comments on commit 81c8a93

Please sign in to comment.