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

Evaluate if an untitled backup exists in UntitledEditorInput

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