Skip to content

Commit

Permalink
Merge pull request #29 from isfopo:issue/Create-command-to-rename-file
Browse files Browse the repository at this point in the history
creates command to rename file
  • Loading branch information
isfopo authored Jul 15, 2024
2 parents 5e294eb + 984e05b commit f4bf23d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"command": "environments.add",
"title": "Add",
"icon": "$(add)"
},
{
"command": "environments.rename",
"title": "Rename"
}
],
"menus": {
Expand All @@ -71,6 +75,10 @@
"when": "viewItem == file",
"group": "inline"
},
{
"command": "environments.rename",
"when": "viewItem == file"
},
{
"command": "environments.edit",
"when": "viewItem == keyValue-string",
Expand Down Expand Up @@ -147,4 +155,4 @@
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4"
}
}
}
36 changes: 36 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,42 @@ export function activate(context: vscode.ExtensionContext) {
}
}
);

vscode.commands.registerCommand(
"environments.rename",
async (element: EnvironmentFileTreeItem) => {
const newFile = await vscode.window.showInputBox({
prompt: "Enter the new name for the environment file",
value: element.name,
});

if (!newFile) {
return;
}

try {
await vscode.workspace.fs.rename(
element.uri,
vscode.Uri.joinPath(
element.uri.with({
path: element.uri.path.substring(
0,
element.uri.path.lastIndexOf("/")
),
}),
newFile
)
);

treeDataProvider.refresh();
vscode.window.showInformationMessage(`File renamed to ${newFile}`);
} catch (error: any) {
vscode.window.showErrorMessage(
`Failed to rename file: ${error.message}`
);
}
}
);
}

// this method is called when your extension is deactivated
Expand Down

0 comments on commit f4bf23d

Please sign in to comment.