提交 4447915b 编写于 作者: R rebornix

saveAs

上级 b4dd66bc
......@@ -309,4 +309,9 @@ export class MainThreadNotebookController implements IMainNotebookController {
async save(uri: URI, token: CancellationToken): Promise<boolean> {
return this._proxy.$saveNotebook(this._viewType, uri, token);
}
async saveAs(uri: URI, target: URI, token: CancellationToken): Promise<boolean> {
return this._proxy.$saveNotebookAs(this._viewType, uri, target, token);
}
}
......@@ -1556,6 +1556,7 @@ export interface ExtHostNotebookShape {
$resolveNotebookData(viewType: string, uri: UriComponents): Promise<NotebookDataDto | undefined>;
$executeNotebook(viewType: string, uri: UriComponents, cellHandle: number | undefined, token: CancellationToken): Promise<void>;
$saveNotebook(viewType: string, uri: UriComponents, token: CancellationToken): Promise<boolean>;
$saveNotebookAs(viewType: string, uri: UriComponents, target: UriComponents, token: CancellationToken): Promise<boolean>;
$acceptDisplayOrder(displayOrder: INotebookDisplayOrder): void;
$onDidReceiveMessage(uri: UriComponents, message: any): void;
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEvent): void;
......
......@@ -846,10 +846,22 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
return true;
}
let provider = this._notebookContentProviders.get(viewType);
return false;
}
async $saveNotebookAs(viewType: string, uri: UriComponents, target: UriComponents, token: CancellationToken): Promise<boolean> {
let document = this._documents.get(URI.revive(uri).toString());
if (!document) {
return false;
}
if (this._notebookContentProviders.has(viewType)) {
try {
await this._notebookContentProviders.get(viewType)!.provider.saveNotebookAs(URI.revive(target), document, token);
} catch (e) {
return false;
}
if (provider && document) {
await provider.provider.saveNotebook(document, token);
return true;
}
......
......@@ -6,10 +6,12 @@
import { EditorInput, IEditorInput, GroupIdentifier, ISaveOptions } from 'vs/workbench/common/editor';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { URI } from 'vs/base/common/uri';
import { isEqual } from 'vs/base/common/resources';
import { isEqual, basename } from 'vs/base/common/resources';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { NotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookEditorModel';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
export class NotebookEditorInput extends EditorInput {
......@@ -39,7 +41,10 @@ export class NotebookEditorInput extends EditorInput {
public name: string,
public readonly viewType: string | undefined,
@INotebookService private readonly notebookService: INotebookService,
@IFilesConfigurationService private readonly filesConfigurationService: IFilesConfigurationService
@IFilesConfigurationService private readonly filesConfigurationService: IFilesConfigurationService,
@IFileDialogService private readonly fileDialogService: IFileDialogService,
@IEditorService private readonly editorService: IEditorService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
}
......@@ -86,7 +91,26 @@ export class NotebookEditorInput extends EditorInput {
}
async saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
return this;
if (!this.textModel) {
return undefined;
}
const dialogPath = this.textModel.resource;
const target = await this.fileDialogService.pickFileToSave(dialogPath, options?.availableFileSystems);
if (!target) {
return undefined; // save cancelled
}
if (!await this.textModel.saveAs(target)) {
return undefined;
}
return this._move(group, target)?.editor;
}
_move(group: GroupIdentifier, newResource: URI): { editor: IEditorInput } | undefined {
const editorInput = NotebookEditorInput.getOrCreate(this.instantiationService, newResource, basename(newResource), this.viewType);
return { editor: editorInput };
}
async revert(group: GroupIdentifier): Promise<void> {
......
......@@ -324,6 +324,16 @@ export class NotebookService extends Disposable implements INotebookService, ICu
return false;
}
async saveAs(viewType: string, resource: URI, target: URI, token: CancellationToken): Promise<boolean> {
let provider = this._notebookProviders.get(viewType);
if (provider) {
return provider.controller.saveAs(resource, target, token);
}
return false;
}
onDidReceiveMessage(viewType: string, uri: URI, message: any): void {
let provider = this._notebookProviders.get(viewType);
......
......@@ -161,7 +161,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
async saveAs(targetResource: URI): Promise<boolean> {
const tokenSource = new CancellationTokenSource();
await this.notebookService.save(this.notebook.viewType, this.notebook.uri, tokenSource.token);
await this.notebookService.saveAs(this.notebook.viewType, this.notebook.uri, targetResource, tokenSource.token);
this._dirty = false;
this._onDidChangeDirty.fire();
return true;
......
......@@ -23,6 +23,7 @@ export interface IMainNotebookController {
executeNotebookCell(uri: URI, handle: number, token: CancellationToken): Promise<void>;
removeNotebookDocument(notebook: INotebookTextModel): Promise<void>;
save(uri: URI, token: CancellationToken): Promise<boolean>;
saveAs(uri: URI, target: URI, token: CancellationToken): Promise<boolean>;
}
export interface INotebookService {
......@@ -46,6 +47,7 @@ export interface INotebookService {
destoryNotebookDocument(viewType: string, notebook: INotebookTextModel): void;
updateActiveNotebookDocument(viewType: string, resource: URI): void;
save(viewType: string, resource: URI, token: CancellationToken): Promise<boolean>;
saveAs(viewType: string, resource: URI, target: URI, token: CancellationToken): Promise<boolean>;
onDidReceiveMessage(viewType: string, uri: URI, message: any): void;
setToCopy(items: NotebookCellTextModel[]): void;
getToCopy(): NotebookCellTextModel[] | undefined;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册