提交 2ded2a75 编写于 作者: D Daniel Imms

Discard backups when the file is no longer dirty

Make content update trigger after dirty status is evaluated
上级 038f7564
......@@ -110,6 +110,11 @@ export interface IFileService {
*/
backupFile(resource: URI, content: string): TPromise<IFileStat>;
/**
* Discard the backup for the resource specified.
*/
discardBackup(resource: URI): TPromise<void>;
/**
* Discards all backups associated with this session.
*/
......
......@@ -145,8 +145,6 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
}
private onModelContentChanged(): void {
this._onDidChangeContent.fire();
// turn dirty if we were not
if (!this.dirty) {
this.dirty = true;
......@@ -159,6 +157,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
this.dirty = false;
this._onDidChangeDirty.fire();
}
this._onDidChangeContent.fire();
}
public dispose(): void {
......
......@@ -306,8 +306,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return;
}
this._onDidContentChange.fire(void 0);
// The contents changed as a matter of Undo and the version reached matches the saved one
// In this case we clear the dirty flag and emit a SAVED event to indicate this state.
// Note: we currently only do this check when auto-save is turned off because there you see
......@@ -324,6 +322,8 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
this._onDidStateChange.fire(StateChange.REVERTED);
}
this._onDidContentChange.fire(void 0);
return;
}
......@@ -340,6 +340,8 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
diag('makeDirty() - prevented save because we are in conflict resolution mode', this.resource, new Date());
}
}
this._onDidContentChange.fire(void 0);
}
private makeDirty(): void {
......
......@@ -76,8 +76,13 @@ export class DirtyFilesTracker implements IWorkbenchContribution {
// TODO: Delay/throttle
let untitledEditorInput = this.untitledEditorService.get(resource);
untitledEditorInput.resolve().then((model) => {
// TODO: Deal with encoding?
this.fileService.backupFile(resource, model.getValue());
if (model.isDirty()) {
// TODO: Deal with encoding?
this.fileService.backupFile(resource, model.getValue());
} else {
console.log('discard');
this.fileService.discardBackup(resource);
}
});
}
}
......@@ -100,12 +105,16 @@ export class DirtyFilesTracker implements IWorkbenchContribution {
if (this.textFileService.isHotExitEnabled()) {
let model = this.textFileService.models.get(resource);
this.fileService.backupFile(resource, model.getValue());
if (model.isDirty()) {
this.fileService.backupFile(resource, model.getValue());
} else {
console.log('discard');
this.fileService.discardBackup(resource);
}
}
}
private onTextFileDirty(e: TextFileModelChangeEvent): void {
console.log('onTextFileDirty', e);
if ((this.textFileService.getAutoSaveMode() !== AutoSaveMode.AFTER_SHORT_DELAY) && !this.isDocumentedEdited) {
this.updateDocumentEdited(); // no indication needed when auto save is enabled for short delay
......@@ -123,12 +132,6 @@ export class DirtyFilesTracker implements IWorkbenchContribution {
if (!this.pendingDirtyHandle) {
this.pendingDirtyHandle = setTimeout(() => this.doOpenDirtyResources(), 250);
}
if (this.textFileService.isHotExitEnabled()) {
console.log('trigger hot exit');
// TODO: Delay/throttle
this.textFileService.backup(e.resource);
}
}
private doOpenDirtyResources(): void {
......
......@@ -236,6 +236,10 @@ export class FileService implements IFileService {
return this.raw.backupFile(resource, content);
}
public discardBackup(resource: uri): TPromise<void> {
return this.raw.discardBackup(resource);
}
public discardBackups(): TPromise<void> {
return this.raw.discardBackups();
}
......
......@@ -437,14 +437,21 @@ export class FileService implements IFileService {
public backupFile(resource: uri, content: string): TPromise<IFileStat> {
// TODO: Implement properly
var backupName = paths.basename(resource.fsPath);
var backupPath = paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID, backupName);
const backupName = paths.basename(resource.fsPath);
const backupPath = paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID, backupName);
const backupResource = uri.file(backupPath);
let backupResource = uri.file(backupPath);
console.log(`Backing up to ${backupResource.fsPath}`);
return this.updateContent(backupResource, content);
}
public discardBackup(resource: uri): TPromise<void> {
const backupName = paths.basename(resource.fsPath);
const backupPath = paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID, backupName);
const backupResource = uri.file(backupPath);
return this.del(backupResource);
}
public discardBackups(): TPromise<void> {
return this.del(uri.file(paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID)));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册