提交 17680ec6 编写于 作者: B Benjamin Pasero

ITextFileService.save() should trigger more UI updating (fixes #939)

上级 48375210
...@@ -209,7 +209,15 @@ export class EditorPart extends Part implements IEditorPart { ...@@ -209,7 +209,15 @@ export class EditorPart extends Part implements IEditorPart {
// Close editor when input provided and input gets disposed // Close editor when input provided and input gets disposed
if (input) { if (input) {
this.visibleInputListeners[position] = input.addListener(EventType.DISPOSE, () => { this.visibleInputListeners[position] = input.addListener(EventType.DISPOSE, () => {
this.closeEditors(false, input).done(null, errors.onUnexpectedError);
// To prevent race conditions, we call the close in a timeout because it can well be
// that an input is being disposed with the intent to replace it with some other input
// right after.
setTimeout(() => {
if (input === this.visibleInputs[position]) {
this.closeEditors(false, input).done(null, errors.onUnexpectedError);
}
}, 0);
}); });
} }
......
...@@ -1527,9 +1527,8 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting { ...@@ -1527,9 +1527,8 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting {
encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file! encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file!
} }
let savePromise: TPromise<URI>;
// Special case: an untitled file with associated path gets saved directly unless "saveAs" is true // Special case: an untitled file with associated path gets saved directly unless "saveAs" is true
let savePromise: TPromise<URI>;
if (!this.isSaveAs() && source.scheme === 'untitled' && this.untitledEditorService.hasAssociatedFilePath(source)) { if (!this.isSaveAs() && source.scheme === 'untitled' && this.untitledEditorService.hasAssociatedFilePath(source)) {
savePromise = this.textFileService.save(source).then((result) => { savePromise = this.textFileService.save(source).then((result) => {
if (result) { if (result) {
...@@ -1550,9 +1549,6 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting { ...@@ -1550,9 +1549,6 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting {
return; return;
} }
// Add to working files
this.textFileService.getWorkingFilesModel().addEntry(target);
// Reopen editors for the resource based on the positions // Reopen editors for the resource based on the positions
let reopenPromise = Promise.as(null); let reopenPromise = Promise.as(null);
if (target.toString() !== source.toString() && positionsOfSource.length) { if (target.toString() !== source.toString() && positionsOfSource.length) {
...@@ -1569,11 +1565,7 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting { ...@@ -1569,11 +1565,7 @@ export abstract class BaseSaveFileAction extends BaseActionWithErrorReporting {
}); });
} }
return reopenPromise.then(() => { return reopenPromise;
// Revert source
this.textFileService.revert(source);
});
}); });
} }
...@@ -1653,16 +1645,17 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting { ...@@ -1653,16 +1645,17 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting {
protected doRun(): TPromise<boolean> { protected doRun(): TPromise<boolean> {
// Store mimes per untitled file to restore later
const mapUntitledToProperties: {[resource:string]: { mime: string; encoding: string; }} = Object.create(null);
this.textFileService.getDirty()
.filter(r => r.scheme === 'untitled') // All untitled resources^
.map(r => this.untitledEditorService.get(r)) // Mapped to their inputs
.filter(i => !!i) // If possible :)
.forEach(i => mapUntitledToProperties[i.getResource().toString()] = { mime: i.getMime(), encoding: i.getEncoding() });
// Save all // Save all
return this.textFileService.saveAll(this.includeUntitled()).then((result) => { return this.textFileService.saveAll(this.includeUntitled()).then((result) => {
// add all targets to working files
result.results.forEach((res) => {
if (res.success && res.target) {
this.textFileService.getWorkingFilesModel().addEntry(res.target);
}
});
// all saved - now try to reopen saved untitled ones // all saved - now try to reopen saved untitled ones
if (this.includeUntitled()) { if (this.includeUntitled()) {
let untitledResults = result.results.filter((res) => res.source.scheme === 'untitled'); let untitledResults = result.results.filter((res) => res.source.scheme === 'untitled');
...@@ -1674,12 +1667,12 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting { ...@@ -1674,12 +1667,12 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting {
let positions = findSaveAsPositions(this.editorService, res.source); let positions = findSaveAsPositions(this.editorService, res.source);
let mimeOfSource: string; let mimeOfSource: string;
let selectedMime = this.untitledEditorService.get(res.source).getMime(); let selectedMime = mapUntitledToProperties[res.source.toString()] && mapUntitledToProperties[res.source.toString()].mime;
if (!isUnspecific(selectedMime)) { if (!isUnspecific(selectedMime)) {
mimeOfSource = [selectedMime, MIME_TEXT].join(', '); mimeOfSource = [selectedMime, MIME_TEXT].join(', ');
} }
let encodingOfSource: string = this.untitledEditorService.get(res.source).getEncoding(); let encodingOfSource: string = mapUntitledToProperties[res.source.toString()] && mapUntitledToProperties[res.source.toString()].encoding;
let targetInput = this.instantiationService.createInstance(FileEditorInput, res.target, mimeOfSource, encodingOfSource); let targetInput = this.instantiationService.createInstance(FileEditorInput, res.target, mimeOfSource, encodingOfSource);
...@@ -1708,17 +1701,7 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting { ...@@ -1708,17 +1701,7 @@ export abstract class BaseSaveAllAction extends BaseActionWithErrorReporting {
}); });
} }
// After reopen, revert untitled ones return reopenPromise;
return reopenPromise.then(() => {
return Promise.join(untitledResults.map((res) => {
let revertPromise = Promise.as(null);
if (res.success) {
revertPromise = this.textFileService.revert(res.source);
}
return revertPromise;
}));
});
} }
}); });
} }
......
...@@ -70,17 +70,6 @@ export class TextFileService extends BrowserTextFileService { ...@@ -70,17 +70,6 @@ export class TextFileService extends BrowserTextFileService {
// Save // Save
if (confirm === ConfirmResult.SAVE) { if (confirm === ConfirmResult.SAVE) {
return this.saveAll(true /* includeUntitled */).then((result) => { return this.saveAll(true /* includeUntitled */).then((result) => {
// Dispose saved untitled ones to not leave them around as dirty
result.results.forEach((res) => {
if (res.success && res.source.scheme === 'untitled') {
let input = this.untitledEditorService.get(res.source);
if (input) {
input.dispose();
}
}
});
if (result.results.some((r) => !r.success)) { if (result.results.some((r) => !r.success)) {
return true; // veto if some saves failed return true; // veto if some saves failed
} }
...@@ -326,13 +315,22 @@ export class TextFileService extends BrowserTextFileService { ...@@ -326,13 +315,22 @@ export class TextFileService extends BrowserTextFileService {
// We have a model: Use it (can be null e.g. if this file is binary and not a text file or was never opened before) // We have a model: Use it (can be null e.g. if this file is binary and not a text file or was never opened before)
if (model) { if (model) {
return this.fileService.updateContent(target, model.getValue(), { charset: model.getEncoding() }).then(() => { return this.fileService.updateContent(target, model.getValue(), { charset: model.getEncoding() });
return target;
});
} }
// Otherwise we can only copy // Otherwise we can only copy
return this.fileService.copyFile(resource, target).then(() => target); return this.fileService.copyFile(resource, target);
}).then(() => {
// Add target to working files because this is an operation that indicates activity
this.getWorkingFilesModel().addEntry(target);
// Revert the source
return this.revert(resource).then(() => {
// Done: return target
return target;
});
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册