mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 01:25:36 -05:00
Introduce Trust Book in Book Viewlet (#9414)
This commit is contained in:
@@ -362,6 +362,11 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
|
||||
return Promise.resolve(this.doOpenEditor(resource, options));
|
||||
}
|
||||
|
||||
$trySetTrusted(uriComponent: UriComponents, isTrusted: boolean): Promise<boolean> {
|
||||
let uri = URI.revive(uriComponent);
|
||||
return this._notebookService.setTrusted(uri, isTrusted);
|
||||
}
|
||||
|
||||
$tryApplyEdits(id: string, modelVersionId: number, edits: ISingleNotebookEditOperation[], opts: IUndoStopOptions): Promise<boolean> {
|
||||
let editor = this.getEditor(id);
|
||||
if (!editor) {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ok } from 'vs/base/common/assert';
|
||||
@@ -50,6 +49,7 @@ export class ExtHostNotebookDocumentData implements IDisposable {
|
||||
get cells() { return data._cells; },
|
||||
get kernelSpec() { return data._kernelSpec; },
|
||||
save() { return data._save(); },
|
||||
setTrusted(isTrusted) { data._setTrusted(isTrusted); },
|
||||
validateCellRange(range) { return data._validateRange(range); },
|
||||
};
|
||||
}
|
||||
@@ -61,7 +61,13 @@ export class ExtHostNotebookDocumentData implements IDisposable {
|
||||
return Promise.reject(new Error('Document has been closed'));
|
||||
}
|
||||
return this._proxy.$trySaveDocument(this._uri);
|
||||
}
|
||||
|
||||
private _setTrusted(isTrusted: boolean): Thenable<boolean> {
|
||||
if (this._isDisposed) {
|
||||
return Promise.reject(new Error('Document has been closed'));
|
||||
}
|
||||
return this._proxy.$trySetTrusted(this._uri, isTrusted);
|
||||
}
|
||||
|
||||
public onModelChanged(data: INotebookModelChangedData) {
|
||||
|
||||
@@ -82,6 +82,10 @@ export class NotebookEditorEdit {
|
||||
return range;
|
||||
}
|
||||
|
||||
setTrusted(isTrusted: boolean) {
|
||||
this._document.setTrusted(isTrusted);
|
||||
}
|
||||
|
||||
insertCell(value: Partial<azdata.nb.ICellContents>, index?: number, collapsed?: boolean): void {
|
||||
if (index === null || index === undefined) {
|
||||
// If not specified, assume adding to end of list
|
||||
|
||||
@@ -891,6 +891,7 @@ export interface ExtHostNotebookDocumentsAndEditorsShape {
|
||||
}
|
||||
|
||||
export interface MainThreadNotebookDocumentsAndEditorsShape extends IDisposable {
|
||||
$trySetTrusted(_uri: UriComponents, isTrusted: boolean): Thenable<boolean>;
|
||||
$trySaveDocument(uri: UriComponents): Thenable<boolean>;
|
||||
$tryShowNotebookDocument(resource: UriComponents, options: INotebookShowOptions): Promise<string>;
|
||||
$tryApplyEdits(id: string, modelVersionId: number, edits: ISingleNotebookEditOperation[], opts: IUndoStopOptions): Promise<boolean>;
|
||||
|
||||
@@ -58,7 +58,7 @@ export class LinkHandlerDirective {
|
||||
// ignore
|
||||
}
|
||||
if (uri && this.openerService && this.isSupportedLink(uri)) {
|
||||
if (uri.fragment && uri.fragment.length > 0 && uri.fsPath === this.workbenchFilePath.fsPath) {
|
||||
if (uri.fragment && uri.fragment.length > 0 && uri.path === this.workbenchFilePath.path) {
|
||||
this.notebookService.navigateTo(this.notebookUri, uri.fragment);
|
||||
} else {
|
||||
this.openerService.open(uri).catch(onUnexpectedError);
|
||||
|
||||
@@ -205,6 +205,9 @@ export class NotebookServiceStub implements INotebookService {
|
||||
get languageMagics(): ILanguageMagic[] {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
registerProvider(providerId: string, provider: INotebookProvider): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
@@ -233,6 +233,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
|
||||
public set trustedMode(isTrusted: boolean) {
|
||||
this._trustedMode = isTrusted;
|
||||
|
||||
if (this._cells) {
|
||||
this._cells.forEach(c => {
|
||||
c.trustedMode = this._trustedMode;
|
||||
@@ -290,6 +291,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
public async loadContents(isTrusted: boolean = false): Promise<void> {
|
||||
try {
|
||||
this._trustedMode = isTrusted;
|
||||
|
||||
let contents = null;
|
||||
|
||||
if (this._notebookOptions && this._notebookOptions.contentManager) {
|
||||
|
||||
@@ -112,6 +112,13 @@ export interface INotebookService {
|
||||
* @param sectionId ID of the section to navigate to
|
||||
*/
|
||||
navigateTo(notebookUri: URI, sectionId: string): void;
|
||||
|
||||
/**
|
||||
* Sets the trusted mode for the sepcified notebook.
|
||||
* @param notebookUri URI of the notebook to navigate to
|
||||
* @param isTrusted True if notebook is to be set to trusted, false otherwise.
|
||||
*/
|
||||
setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface INotebookProvider {
|
||||
|
||||
@@ -606,4 +606,25 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
editor.navigateToSection(sectionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trusts a notebook with the specified URI.
|
||||
* @param notebookUri The notebook URI to set the trusted mode for.
|
||||
* @param isTrusted True if the notebook is to be trusted, false otherwise.
|
||||
*/
|
||||
async setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean> {
|
||||
let editor = this.findNotebookEditor(notebookUri);
|
||||
|
||||
if (editor && editor.model) {
|
||||
if (isTrusted) {
|
||||
this._trustedCacheQueue.push(notebookUri);
|
||||
} else {
|
||||
this._unTrustedCacheQueue.push(notebookUri);
|
||||
}
|
||||
await this.updateTrustedCache();
|
||||
editor.model.trustedMode = isTrusted;
|
||||
}
|
||||
|
||||
return isTrusted;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user