diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index 425c8759ea1849e3767925d5649b135522ca1614..3840200ff8b6903c7259cbbeb644e68a46e86400 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -110,6 +110,11 @@ export interface IFileService { */ backupFile(resource: URI, content: string): TPromise; + /** + * Discard the backup for the resource specified. + */ + discardBackup(resource: URI): TPromise; + /** * Discards all backups associated with this session. */ diff --git a/src/vs/workbench/common/editor/untitledEditorModel.ts b/src/vs/workbench/common/editor/untitledEditorModel.ts index c56db79b8274cdfe7deb1a2c936abc0cca90bf88..3b5e66d42a1c13a4a856e4804351c87d52d7c2bd 100644 --- a/src/vs/workbench/common/editor/untitledEditorModel.ts +++ b/src/vs/workbench/common/editor/untitledEditorModel.ts @@ -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 { diff --git a/src/vs/workbench/parts/files/common/editors/textFileEditorModel.ts b/src/vs/workbench/parts/files/common/editors/textFileEditorModel.ts index efe0af392f8bba0d8b3661619c75b4067b6d8936..e95a4328a59bbfd6b7c9e90d56b15f9ca345b3e2 100644 --- a/src/vs/workbench/parts/files/common/editors/textFileEditorModel.ts +++ b/src/vs/workbench/parts/files/common/editors/textFileEditorModel.ts @@ -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 { diff --git a/src/vs/workbench/parts/files/electron-browser/dirtyFilesTracker.ts b/src/vs/workbench/parts/files/electron-browser/dirtyFilesTracker.ts index 7b10b096c0cda322771b6b1802f6d299d20298de..ef73716f61f5ca56eebb1865128ce57ae8f0dd10 100644 --- a/src/vs/workbench/parts/files/electron-browser/dirtyFilesTracker.ts +++ b/src/vs/workbench/parts/files/electron-browser/dirtyFilesTracker.ts @@ -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 { diff --git a/src/vs/workbench/services/files/electron-browser/fileService.ts b/src/vs/workbench/services/files/electron-browser/fileService.ts index 50fb8bc05d995d2f98a6e52898a06c791cbc4cb2..0b1c233f2772fd6507b2554938c0437b727fea00 100644 --- a/src/vs/workbench/services/files/electron-browser/fileService.ts +++ b/src/vs/workbench/services/files/electron-browser/fileService.ts @@ -236,6 +236,10 @@ export class FileService implements IFileService { return this.raw.backupFile(resource, content); } + public discardBackup(resource: uri): TPromise { + return this.raw.discardBackup(resource); + } + public discardBackups(): TPromise { return this.raw.discardBackups(); } diff --git a/src/vs/workbench/services/files/node/fileService.ts b/src/vs/workbench/services/files/node/fileService.ts index f7d45003d131ebb17bdb510bef3e39dfa5da49a3..ec2b175c70f581d5b18a5fc07d1b7c31a548c17a 100644 --- a/src/vs/workbench/services/files/node/fileService.ts +++ b/src/vs/workbench/services/files/node/fileService.ts @@ -437,14 +437,21 @@ export class FileService implements IFileService { public backupFile(resource: uri, content: string): TPromise { // 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 { + 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 { return this.del(uri.file(paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID))); }