mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Kenvh/editdatatabname (#2906)
* Remove unnecessary string encoding on edit data naming * Cleaning up duplication in the naming methods. * fix typo in method name
This commit is contained in:
@@ -124,7 +124,7 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
try {
|
try {
|
||||||
// Create file path and file URI
|
// Create file path and file URI
|
||||||
let objectName = schemaName ? schemaName + '.' + tableName : tableName;
|
let objectName = schemaName ? schemaName + '.' + tableName : tableName;
|
||||||
let filePath = this.createEditDataFileName(objectName);
|
let filePath = this.createPrefixedSqlFilePath(objectName);
|
||||||
let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath });
|
let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath });
|
||||||
|
|
||||||
// Create a sql document pane with accoutrements
|
// Create a sql document pane with accoutrements
|
||||||
@@ -265,45 +265,26 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
////// Private functions
|
////// Private functions
|
||||||
|
|
||||||
private createUntitledSqlFilePath(): string {
|
private createUntitledSqlFilePath(): string {
|
||||||
let sqlFileName = (counter: number): string => {
|
return this.createPrefixedSqlFilePath(untitledFilePrefix);
|
||||||
return `${untitledFilePrefix}${counter}`;
|
}
|
||||||
|
|
||||||
|
private createPrefixedSqlFilePath(prefix: string): string {
|
||||||
|
let prefixFileName = (counter: number): string => {
|
||||||
|
return `${prefix}_${counter}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
// Get document name and check if it exists
|
// Get document name and check if it exists
|
||||||
let filePath = sqlFileName(counter);
|
let filePath = prefixFileName(counter);
|
||||||
while (fs.existsSync(filePath)) {
|
while (fs.existsSync(filePath)) {
|
||||||
counter++;
|
counter++;
|
||||||
filePath = sqlFileName(counter);
|
filePath = prefixFileName(counter);
|
||||||
}
|
|
||||||
|
|
||||||
// check if this document name already exists in any open documents
|
|
||||||
let untitledEditors = this._untitledEditorService.getAll();
|
|
||||||
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
|
|
||||||
counter++;
|
|
||||||
filePath = sqlFileName(counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private createEditDataFileName(tableName: string): string {
|
|
||||||
let editDataFileName = (counter: number): string => {
|
|
||||||
return encodeURIComponent(`${tableName}_${counter}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
let counter = 1;
|
|
||||||
// Get document name and check if it exists
|
|
||||||
let filePath = editDataFileName(counter);
|
|
||||||
while (fs.existsSync(filePath)) {
|
|
||||||
counter++;
|
|
||||||
filePath = editDataFileName(counter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let untitledEditors = this._untitledEditorService.getAll();
|
let untitledEditors = this._untitledEditorService.getAll();
|
||||||
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
|
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
|
||||||
counter++;
|
counter++;
|
||||||
filePath = editDataFileName(counter);
|
filePath = prefixFileName(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filePath;
|
return filePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user