mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Auto incrementing default name when adding object to database project (#12013)
* adding auto increment * changing while to do while * streamlining code
This commit is contained in:
@@ -283,17 +283,20 @@ export class ProjectsController {
|
|||||||
|
|
||||||
public async addFolderPrompt(treeNode: BaseProjectTreeItem) {
|
public async addFolderPrompt(treeNode: BaseProjectTreeItem) {
|
||||||
const project = this.getProjectFromContext(treeNode);
|
const project = this.getProjectFromContext(treeNode);
|
||||||
const newFolderName = await this.promptForNewObjectName(new templates.ProjectScriptType(templates.folder, constants.folderFriendlyName, ''), project);
|
const relativePathToParent = this.getRelativePath(treeNode);
|
||||||
|
const absolutePathToParent = path.join(project.projectFolderPath, relativePathToParent);
|
||||||
|
const newFolderName = await this.promptForNewObjectName(new templates.ProjectScriptType(templates.folder, constants.folderFriendlyName, ''),
|
||||||
|
project, absolutePathToParent);
|
||||||
|
|
||||||
if (!newFolderName) {
|
if (!newFolderName) {
|
||||||
return; // user cancelled
|
return; // user cancelled
|
||||||
}
|
}
|
||||||
|
|
||||||
const relativeFolderPath = path.join(this.getRelativePath(treeNode), newFolderName);
|
const relativeFolderPath = path.join(relativePathToParent, newFolderName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// check if folder already exists or is a reserved folder
|
// check if folder already exists or is a reserved folder
|
||||||
const absoluteFolderPath = path.join(project.projectFolderPath, relativeFolderPath);
|
const absoluteFolderPath = path.join(absolutePathToParent, newFolderName);
|
||||||
const folderExists = await utils.exists(absoluteFolderPath);
|
const folderExists = await utils.exists(absoluteFolderPath);
|
||||||
|
|
||||||
if (folderExists || this.isReservedFolder(absoluteFolderPath, project.projectFolderPath)) {
|
if (folderExists || this.isReservedFolder(absoluteFolderPath, project.projectFolderPath)) {
|
||||||
@@ -335,7 +338,8 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const itemType = templates.projectScriptTypeMap()[itemTypeName.toLocaleLowerCase()];
|
const itemType = templates.projectScriptTypeMap()[itemTypeName.toLocaleLowerCase()];
|
||||||
let itemObjectName = await this.promptForNewObjectName(itemType, project);
|
const absolutePathToParent = path.join(project.projectFolderPath, relativePath);
|
||||||
|
let itemObjectName = await this.promptForNewObjectName(itemType, project, absolutePathToParent, constants.sqlFileExtension);
|
||||||
|
|
||||||
itemObjectName = itemObjectName?.trim();
|
itemObjectName = itemObjectName?.trim();
|
||||||
|
|
||||||
@@ -521,13 +525,18 @@ export class ProjectsController {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async promptForNewObjectName(itemType: templates.ProjectScriptType, _project: Project): Promise<string | undefined> {
|
private async promptForNewObjectName(itemType: templates.ProjectScriptType, _project: Project, folderPath: string, fileExtension?: string): Promise<string | undefined> {
|
||||||
// TODO: ask project for suggested name that doesn't conflict
|
const suggestedName = itemType.friendlyName.replace(/\s+/g, '');
|
||||||
const suggestedName = itemType.friendlyName.replace(/\s+/g, '') + '1';
|
let counter: number = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
counter++;
|
||||||
|
} while (counter < Number.MAX_SAFE_INTEGER
|
||||||
|
&& await utils.exists(path.join(folderPath, `${suggestedName}${counter}${(fileExtension ?? '')}`)));
|
||||||
|
|
||||||
const itemObjectName = await vscode.window.showInputBox({
|
const itemObjectName = await vscode.window.showInputBox({
|
||||||
prompt: constants.newObjectNamePrompt(itemType.friendlyName),
|
prompt: constants.newObjectNamePrompt(itemType.friendlyName),
|
||||||
value: suggestedName,
|
value: `${suggestedName}${counter}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return itemObjectName;
|
return itemObjectName;
|
||||||
|
|||||||
Reference in New Issue
Block a user