fix the save and save all for untitled file (#2526)

This commit is contained in:
Alan Ren
2018-09-11 17:06:28 -07:00
committed by Karl Burtram
parent ed861a6c96
commit 8887fe1eac
2 changed files with 23 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ import { getMultiSelectedEditorContexts } from 'vs/workbench/browser/parts/edito
import { Schemas } from 'vs/base/common/network';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorService, SIDE_GROUP, IResourceEditorReplacement } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { isEqual, basenameOrAuthority } from 'vs/base/common/resources';
import { ltrim } from 'vs/base/common/strings';
@@ -165,7 +165,7 @@ function save(
// {{SQL CARBON EDIT}}
queryEditorService.onSaveAsCompleted(resource, target);
return true;
});
});
});
}
@@ -215,14 +215,27 @@ function saveAll(saveAllArguments: any, editorService: IEditorService, untitledE
// Save all
return textFileService.saveAll(saveAllArguments).then((result) => {
groupIdToUntitledResourceInput.forEach((inputs, groupId) => {
// {{SQL CARBON EDIT}}
// Update untitled resources to the saved ones, so we open the proper files
let replacementPairs: IResourceEditorReplacement[] = [];
inputs.forEach(i => {
const targetResult = result.results.filter(r => r.success && r.source.toString() === i.resource.toString()).pop();
if (targetResult) {
i.resource = targetResult.target;
//i.resource = targetResult.target;
let editor = i;
const replacement: IResourceInput = {
resource: targetResult.target,
encoding: i.encoding,
options: {
pinned: true,
viewState: undefined
}
};
replacementPairs.push({ editor: editor, replacement: replacement });
}
});
editorService.openEditors(inputs, groupId);
editorService.replaceEditors(replacementPairs, groupId);
});
});
}

View File

@@ -233,18 +233,12 @@ export class EditorService extends Disposable implements EditorServiceImpl {
return this.doOpenEditor(targetGroup, editor, editorOptions);
}
// {{SQL CARBON EDIT}}
// Untyped Text Editor Support
const textInput = <IResourceEditor>editor;
let typedInput = this.createInput(textInput);
const typedInput = this.createInput(textInput);
if (typedInput) {
const editorOptions = TextEditorOptions.from(textInput);
const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as IEditorGroup | GroupIdentifier);
// {{SQL CARBON EDIT}}
// Convert input into custom type if it's one of the ones we support
typedInput = convertEditorInput(typedInput, editorOptions, this.instantiationService);
return this.doOpenEditor(targetGroup, typedInput, editorOptions);
}
@@ -501,12 +495,12 @@ export class EditorService extends Disposable implements EditorServiceImpl {
const untitledInput = <IUntitledResourceInput>input;
if (!untitledInput.resource || typeof untitledInput.filePath === 'string' || (untitledInput.resource instanceof URI && untitledInput.resource.scheme === Schemas.untitled)) {
// {{SQL CARBON EDIT}}
return this.untitledEditorService.createOrGet(
return convertEditorInput(this.untitledEditorService.createOrGet(
untitledInput.filePath ? URI.file(untitledInput.filePath) : untitledInput.resource,
'sql',
untitledInput.contents,
untitledInput.encoding
);
), undefined, this.instantiationService);
}
// Resource Editor Support
@@ -516,8 +510,9 @@ export class EditorService extends Disposable implements EditorServiceImpl {
if (!label && resourceInput.resource.scheme !== Schemas.data) {
label = basename(resourceInput.resource.fsPath); // derive the label from the path (but not for data URIs)
}
return this.createOrGet(resourceInput.resource, this.instantiationService, label, resourceInput.description, resourceInput.encoding, options && options.forceFileInput) as EditorInput;
// {{SQL CARBON EDIT}}
return convertEditorInput(this.createOrGet(resourceInput.resource, this.instantiationService, label, resourceInput.description, resourceInput.encoding, options && options.forceFileInput) as EditorInput,
undefined, this.instantiationService);
}
return null;