提交 02b2629d 编写于 作者: J Johannes Rieken

cleanup, all notebooks must support backup

上级 fa6c46b7
......@@ -739,7 +739,7 @@ export class NotebookService extends Disposable implements INotebookService, ICu
if (this._models.has(uri)) {
throw new Error(`notebook for ${uri} already exists`);
}
const notebookModel = this._instantiationService.createInstance(NotebookTextModel, viewType, true, uri, data.cells, data.metadata, transientOptions);
const notebookModel = this._instantiationService.createInstance(NotebookTextModel, viewType, uri, data.cells, data.metadata, transientOptions);
this._models.set(uri, new ModelData(notebookModel, this._onWillDisposeDocument.bind(this)));
this._onDidAddNotebookDocument.fire(notebookModel);
return notebookModel;
......
......@@ -229,7 +229,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
constructor(
readonly viewType: string,
readonly supportBackup: boolean, //TODO@jrieken,@rebornix all support backup, right?
readonly uri: URI,
cells: ICellDto2[],
metadata: NotebookDocumentMetadata,
......
......@@ -11,7 +11,7 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { URI } from 'vs/base/common/uri';
import { IWorkingCopyService, IWorkingCopy, IWorkingCopyBackup, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { Schemas } from 'vs/base/common/network';
import { IFileStatWithMetadata, IFileService, FileChangeType } from 'vs/platform/files/common/files';
......@@ -114,35 +114,23 @@ export class NotebookEditorModel extends EditorModel implements INotebookEditorM
async backup(token: CancellationToken): Promise<IWorkingCopyBackup<NotebookDocumentBackupData>> {
if (!this.isResolved()) {
throw new Error('CANNOT call backup before notebook is resolved');
return {};
}
if (this.notebook.supportBackup) {
const tokenSource = new CancellationTokenSource(token);
const backupId = await this._notebookService.backup(this.viewType, this.resource, tokenSource.token);
if (token.isCancellationRequested) {
return {};
}
const stats = await this._resolveStats(this.resource);
return {
meta: {
mtime: stats?.mtime || new Date().getTime(),
name: this._name,
viewType: this.notebook.viewType,
backupId: backupId
}
};
} else {
return {
meta: {
mtime: new Date().getTime(),
name: this._name,
viewType: this.notebook.viewType
},
content: this.notebook.createSnapshot(true)
};
const backupId = await this._notebookService.backup(this.viewType, this.resource, token);
if (token.isCancellationRequested) {
return {};
}
const stats = await this._resolveStats(this.resource);
return {
meta: {
mtime: stats?.mtime ?? Date.now(),
name: this._name,
viewType: this.notebook.viewType,
backupId: backupId
}
};
}
async revert(options?: IRevertOptions | undefined): Promise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册