mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Pass restore resource to UntitledEditorInput as resource
Part of #14067
This commit is contained in:
@@ -18,6 +18,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
|
||||
|
||||
/**
|
||||
* An editor input to be used for untitled text buffers.
|
||||
@@ -28,8 +29,8 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
public static SCHEMA: string = 'untitled';
|
||||
|
||||
private resource: URI;
|
||||
private restoreResource: URI;
|
||||
private hasAssociatedFilePath: boolean;
|
||||
private hasBackupToRestore: boolean;
|
||||
private modeId: string;
|
||||
private cachedModel: UntitledEditorModel;
|
||||
|
||||
@@ -42,17 +43,18 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
resource: URI,
|
||||
hasAssociatedFilePath: boolean,
|
||||
modeId: string,
|
||||
restoreResource: URI,
|
||||
hasBackupToRestore: boolean,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@IWorkspaceContextService private contextService: IWorkspaceContextService,
|
||||
@IModeService private modeService: IModeService,
|
||||
@IBackupFileService private backupFileService: IBackupFileService,
|
||||
@ITextFileService private textFileService: ITextFileService
|
||||
) {
|
||||
super();
|
||||
this.resource = resource;
|
||||
this.restoreResource = restoreResource;
|
||||
this.hasAssociatedFilePath = hasAssociatedFilePath;
|
||||
this.modeId = modeId;
|
||||
this.hasBackupToRestore = hasBackupToRestore;
|
||||
this.toUnbind = [];
|
||||
this._onDidModelChangeContent = new Emitter<void>();
|
||||
this._onDidModelChangeEncoding = new Emitter<void>();
|
||||
@@ -87,8 +89,8 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
return this.cachedModel.isDirty();
|
||||
}
|
||||
|
||||
// untitled files with an associated path or restore resource are always dirty
|
||||
return this.hasAssociatedFilePath || !!this.restoreResource;
|
||||
// untitled files with an associated path or associated resource
|
||||
return this.hasAssociatedFilePath || !!this.resource;
|
||||
}
|
||||
|
||||
public confirmSave(): ConfirmResult {
|
||||
@@ -153,8 +155,12 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
|
||||
|
||||
// Otherwise Create Model and load, restoring from backup if necessary
|
||||
let restorePromise: TPromise<string>;
|
||||
if (this.restoreResource) {
|
||||
restorePromise = this.textFileService.resolveTextContent(this.restoreResource).then(rawTextContent => rawTextContent.value.lines.join('\n'));
|
||||
if (this.hasBackupToRestore) {
|
||||
// TODO: Pass in only Untitled-x into the constructor, evaluate whether there is a backup here.
|
||||
const restoreResource = URI.from({ scheme: 'file', path: this.resource.fsPath });
|
||||
restorePromise = this.textFileService.resolveTextContent(restoreResource).then(rawTextContent => rawTextContent.value.lines.join('\n'));
|
||||
this.resource = URI.from({ scheme: UntitledEditorInput.SCHEMA, path: paths.basename(this.resource.fsPath) });
|
||||
this.hasAssociatedFilePath = false;
|
||||
} else {
|
||||
restorePromise = TPromise.as('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user