提交 ab9f0b74 编写于 作者: B Benjamin Pasero

hot exit - add version id getters to models

上级 1816ae96
......@@ -133,14 +133,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
return null;
}
public getValue(): string {
if (this.cachedModel) {
return this.cachedModel.getValue();
}
return null;
}
public setEncoding(encoding: string, mode: EncodingMode /* ignored, we only have Encode */): void {
if (this.cachedModel) {
this.cachedModel.setEncoding(encoding);
......
......@@ -33,6 +33,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
private _onDidChangeDirty: Emitter<void>;
private _onDidChangeEncoding: Emitter<void>;
private versionId: number;
private contentChangeEventScheduler: RunOnceScheduler;
private configuredEncoding: string;
......@@ -54,6 +56,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
this.hasAssociatedFilePath = hasAssociatedFilePath;
this.dirty = false;
this.versionId = 0;
this._onDidChangeContent = new Emitter<void>();
this._onDidChangeDirty = new Emitter<void>();
......@@ -94,6 +97,10 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
this.configuredEncoding = configuration && configuration.files && configuration.files.encoding;
}
public getVersionId(): number {
return this.versionId;
}
public getValue(): string {
if (this.textEditorModel) {
return this.textEditorModel.getValue(EndOfLinePreference.TextDefined, true /* Preserve BOM */);
......@@ -179,6 +186,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
}
private onModelContentChanged(): void {
this.versionId++;
// mark the untitled editor as non-dirty once its content becomes empty and we do
// not have an associated path set. we never want dirty indicator in that case.
......
......@@ -65,9 +65,9 @@ export class BackupModelTracker implements IWorkbenchContribution {
if (this.backupService.isHotExitEnabled) {
const input = this.untitledEditorService.get(resource);
if (input.isDirty()) {
this.backupFileService.backupResource(resource, input.getValue());
input.resolve().then(model => this.backupFileService.backupResource(resource, model.getValue()));
} else {
this.backupFileService.discardResourceBackup(resource);
this.discardBackup(resource);
}
}
}
......
......@@ -14,17 +14,31 @@ import path = require('path');
import extfs = require('vs/base/node/extfs');
import pfs = require('vs/base/node/pfs');
import Uri from 'vs/base/common/uri';
import { TestEnvironmentService } from 'vs/test/utils/servicesTestUtils';
import { BackupFileService } from 'vs/workbench/services/backup/node/backupFileService';
import { FileService } from 'vs/workbench/services/files/node/fileService';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { parseArgs } from 'vs/platform/environment/node/argv';
class TestEnvironmentService extends EnvironmentService {
constructor(private _backupHome: string, private _backupWorkspacesPath: string) {
super(parseArgs(process.argv), process.execPath);
this._backupHome = this._backupHome || this.backupHome;
this._backupWorkspacesPath = this._backupWorkspacesPath || this.backupWorkspacesPath;
}
get backupHome(): string { return this._backupHome; }
get backupWorkspacesPath(): string { return this._backupWorkspacesPath; }
}
class TestBackupFileService extends BackupFileService {
constructor(workspace: Uri, backupHome: string, workspacesJsonPath: string) {
const fileService = new FileService(workspace.fsPath, { disableWatcher: true }, null);
super(workspace, TestEnvironmentService, fileService);
const testEnvironmentService = new TestEnvironmentService(backupHome, workspacesJsonPath);
this.backupHome = backupHome;
this.workspacesJsonPath = workspacesJsonPath;
super(workspace, testEnvironmentService, fileService);
}
}
......
......@@ -139,6 +139,13 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
return this._onDidStateChange.event;
}
/**
* The current version id of the model.
*/
public getVersionId(): number {
return this.versionId;
}
/**
* Set a save error handler to install code that executes when save errors occur.
*/
......
......@@ -209,6 +209,8 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport
onDidContentChange: Event<StateChange>;
onDidStateChange: Event<StateChange>;
getVersionId(): number;
getResource(): URI;
getLastSaveAttemptTime(): number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册