mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -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 {
|
||||
// Create file path and file URI
|
||||
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 });
|
||||
|
||||
// Create a sql document pane with accoutrements
|
||||
@@ -265,45 +265,26 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
////// Private functions
|
||||
|
||||
private createUntitledSqlFilePath(): string {
|
||||
let sqlFileName = (counter: number): string => {
|
||||
return `${untitledFilePrefix}${counter}`;
|
||||
};
|
||||
|
||||
let counter = 1;
|
||||
// Get document name and check if it exists
|
||||
let filePath = sqlFileName(counter);
|
||||
while (fs.existsSync(filePath)) {
|
||||
counter++;
|
||||
filePath = sqlFileName(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;
|
||||
return this.createPrefixedSqlFilePath(untitledFilePrefix);
|
||||
}
|
||||
|
||||
private createEditDataFileName(tableName: string): string {
|
||||
let editDataFileName = (counter: number): string => {
|
||||
return encodeURIComponent(`${tableName}_${counter}`);
|
||||
private createPrefixedSqlFilePath(prefix: string): string {
|
||||
let prefixFileName = (counter: number): string => {
|
||||
return `${prefix}_${counter}`;
|
||||
};
|
||||
|
||||
let counter = 1;
|
||||
// Get document name and check if it exists
|
||||
let filePath = editDataFileName(counter);
|
||||
let filePath = prefixFileName(counter);
|
||||
while (fs.existsSync(filePath)) {
|
||||
counter++;
|
||||
filePath = editDataFileName(counter);
|
||||
filePath = prefixFileName(counter);
|
||||
}
|
||||
|
||||
let untitledEditors = this._untitledEditorService.getAll();
|
||||
while (untitledEditors.find(x => x.getName().toUpperCase() === filePath.toUpperCase())) {
|
||||
counter++;
|
||||
filePath = editDataFileName(counter);
|
||||
filePath = prefixFileName(counter);
|
||||
}
|
||||
|
||||
return filePath;
|
||||
|
||||
Reference in New Issue
Block a user