提交 e9b07aeb 编写于 作者: D Daniel Imms

Evaluate if an untitled backup exists in UntitledEditorInput

上级 7f076284
...@@ -665,7 +665,7 @@ export class TestBackupFileService implements IBackupFileService { ...@@ -665,7 +665,7 @@ export class TestBackupFileService implements IBackupFileService {
return []; return [];
} }
public hasTextFileBackup(resource: URI): TPromise<boolean> { public hasBackup(resource: URI): TPromise<boolean> {
return TPromise.as(false); return TPromise.as(false);
} }
......
...@@ -30,7 +30,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { ...@@ -30,7 +30,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
private resource: URI; private resource: URI;
private hasAssociatedFilePath: boolean; private hasAssociatedFilePath: boolean;
private hasBackupToRestore: boolean;
private modeId: string; private modeId: string;
private cachedModel: UntitledEditorModel; private cachedModel: UntitledEditorModel;
...@@ -43,7 +42,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { ...@@ -43,7 +42,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
resource: URI, resource: URI,
hasAssociatedFilePath: boolean, hasAssociatedFilePath: boolean,
modeId: string, modeId: string,
hasBackupToRestore: boolean,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService, @IWorkspaceContextService private contextService: IWorkspaceContextService,
@IModeService private modeService: IModeService, @IModeService private modeService: IModeService,
...@@ -54,7 +52,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { ...@@ -54,7 +52,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
this.resource = resource; this.resource = resource;
this.hasAssociatedFilePath = hasAssociatedFilePath; this.hasAssociatedFilePath = hasAssociatedFilePath;
this.modeId = modeId; this.modeId = modeId;
this.hasBackupToRestore = hasBackupToRestore;
this.toUnbind = []; this.toUnbind = [];
this._onDidModelChangeContent = new Emitter<void>(); this._onDidModelChangeContent = new Emitter<void>();
this._onDidModelChangeEncoding = new Emitter<void>(); this._onDidModelChangeEncoding = new Emitter<void>();
...@@ -154,19 +151,17 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { ...@@ -154,19 +151,17 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
} }
// Otherwise Create Model and load, restoring from backup if necessary // Otherwise Create Model and load, restoring from backup if necessary
let restorePromise: TPromise<string>; return this.backupFileService.hasBackup(this.resource).then(hasBackup => {
if (this.hasBackupToRestore) { if (hasBackup) {
// TODO: Pass in only Untitled-x into the constructor, evaluate whether there is a backup here. // If the resource restored from backup it doesn't have an associated file path
const restoreResource = this.backupFileService.getBackupResource(this.resource); this.hasAssociatedFilePath = false;
restorePromise = this.textFileService.resolveTextContent(restoreResource).then(rawTextContent => rawTextContent.value.lines.join('\n'));
const restoreResource = this.backupFileService.getBackupResource(this.resource);
// If the resource restored from backup it doesn't have an associated file path return this.textFileService.resolveTextContent(restoreResource).then(rawTextContent => rawTextContent.value.lines.join('\n'));
this.hasAssociatedFilePath = false; }
} else {
restorePromise = TPromise.as('');
}
return restorePromise.then(content => { return '';
}).then(content => {
const model = this.createModel(content); const model = this.createModel(content);
return model.load().then((resolvedModel: UntitledEditorModel) => { return model.load().then((resolvedModel: UntitledEditorModel) => {
this.cachedModel = resolvedModel; this.cachedModel = resolvedModel;
......
...@@ -47,7 +47,7 @@ export interface IBackupFileService { ...@@ -47,7 +47,7 @@ export interface IBackupFileService {
* @param resource The resource to check. * @param resource The resource to check.
* @returns Whether the file has a backup. * @returns Whether the file has a backup.
*/ */
hasTextFileBackup(resource: Uri): TPromise<boolean>; hasBackup(resource: Uri): TPromise<boolean>;
/** /**
* Gets the backup resource for a particular resource within the current workspace. * Gets the backup resource for a particular resource within the current workspace.
......
...@@ -37,12 +37,12 @@ export class BackupFileService implements IBackupFileService { ...@@ -37,12 +37,12 @@ export class BackupFileService implements IBackupFileService {
}); });
} }
public hasTextFileBackup(resource: Uri): TPromise<boolean> { public hasBackup(resource: Uri): TPromise<boolean> {
const backupResource = this.getBackupResource(resource); const backupResource = this.getBackupResource(resource);
if (!backupResource) { if (!backupResource) {
return TPromise.as(false); return TPromise.as(false);
} }
return pfs.exists(this.getBackupResource(resource).fsPath); return pfs.exists(backupResource.fsPath);
} }
public getBackupResource(resource: Uri): Uri { public getBackupResource(resource: Uri): Uri {
......
...@@ -79,11 +79,11 @@ suite('BackupFileService', () => { ...@@ -79,11 +79,11 @@ suite('BackupFileService', () => {
}); });
test('doesTextFileHaveBackup should return whether a backup resource exists', done => { test('doesTextFileHaveBackup should return whether a backup resource exists', done => {
service.hasTextFileBackup(fooFile).then(exists => { service.hasBackup(fooFile).then(exists => {
assert.equal(exists, false); assert.equal(exists, false);
pfs.mkdirp(path.dirname(fooBackupPath)).then(() => { pfs.mkdirp(path.dirname(fooBackupPath)).then(() => {
fs.writeFileSync(fooBackupPath, 'foo'); fs.writeFileSync(fooBackupPath, 'foo');
service.hasTextFileBackup(fooFile).then(exists2 => { service.hasBackup(fooFile).then(exists2 => {
assert.equal(exists2, true); assert.equal(exists2, true);
done(); done();
}); });
......
...@@ -266,7 +266,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil ...@@ -266,7 +266,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
else { else {
diag('load() - created text editor model', this.resource, new Date()); diag('load() - created text editor model', this.resource, new Date());
return this.backupFileService.hasTextFileBackup(this.resource).then(backupExists => { return this.backupFileService.hasBackup(this.resource).then(backupExists => {
let getContentPromise: TPromise<IRawText>; let getContentPromise: TPromise<IRawText>;
if (backupExists) { if (backupExists) {
const restoreResource = this.backupFileService.getBackupResource(this.resource); const restoreResource = this.backupFileService.getBackupResource(this.resource);
......
...@@ -185,7 +185,7 @@ export class UntitledEditorService implements IUntitledEditorService { ...@@ -185,7 +185,7 @@ export class UntitledEditorService implements IUntitledEditorService {
} while (Object.keys(UntitledEditorService.CACHE).indexOf(resource.toString()) >= 0); } while (Object.keys(UntitledEditorService.CACHE).indexOf(resource.toString()) >= 0);
} }
const input = this.instantiationService.createInstance(UntitledEditorInput, resource, hasAssociatedFilePath, modeId, hasBackupToRestore); const input = this.instantiationService.createInstance(UntitledEditorInput, resource, hasAssociatedFilePath, modeId);
if (input.isDirty()) { if (input.isDirty()) {
setTimeout(() => { setTimeout(() => {
this._onDidChangeDirty.fire(resource); this._onDidChangeDirty.fire(resource);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册