mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-25 17:27:26 +01:00
give the option completely to notebook extension for now.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import * as glob from 'vs/base/common/glob';
|
||||
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
@@ -21,9 +21,9 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { CATEGORIES } from 'vs/workbench/common/actions';
|
||||
import { BaseCellRenderTemplate, CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID, EXPAND_CELL_CONTENT_COMMAND_ID, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED, TRUST_NOTEBOOK_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { BaseCellRenderTemplate, CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID, EXPAND_CELL_CONTENT_COMMAND_ID, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_EDITOR_FOCUSED, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
|
||||
import { CellEditType, CellKind, ICellEditOperation, ICellRange, isDocumentExcludePattern, NotebookCellMetadata, NotebookCellRunState, NotebookDocumentMetadata, NOTEBOOK_EDITOR_CURSOR_BEGIN_END, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { CellEditType, CellKind, ICellEditOperation, ICellRange, isDocumentExcludePattern, NotebookCellMetadata, NotebookCellRunState, NOTEBOOK_EDITOR_CURSOR_BEGIN_END, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
@@ -1823,34 +1823,6 @@ registerAction2(class extends ChangeNotebookCellMetadataAction {
|
||||
}
|
||||
});
|
||||
|
||||
abstract class ChangeNotebookMetadataAction extends NotebookCellAction {
|
||||
async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
|
||||
const textModel = context.notebookEditor.viewModel?.notebookDocument;
|
||||
if (!textModel) {
|
||||
return;
|
||||
}
|
||||
|
||||
textModel.applyEdits(textModel.versionId, [{ editType: CellEditType.DocumentMetadata, metadata: { ...textModel.metadata, ...this.getMetadataDelta() } }], true, undefined, () => undefined, undefined);
|
||||
}
|
||||
|
||||
abstract getMetadataDelta(): Partial<NotebookDocumentMetadata>;
|
||||
}
|
||||
|
||||
registerAction2(class extends ChangeNotebookMetadataAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: TRUST_NOTEBOOK_COMMAND_ID,
|
||||
title: localize('notebook.trust', "Trust Current Notebook Document"),
|
||||
});
|
||||
}
|
||||
|
||||
getMetadataDelta(): Partial<NotebookDocumentMetadata> {
|
||||
return { trusted: true };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
registerAction2(class extends Action2 {
|
||||
constructor() {
|
||||
super({
|
||||
@@ -1894,6 +1866,19 @@ registerAction2(class extends Action2 {
|
||||
}
|
||||
});
|
||||
|
||||
// Revisit once we have a story for trusted workspace
|
||||
CommandsRegistry.registerCommand('notebook.trust', (accessor, args) => {
|
||||
const uri = URI.revive(args as UriComponents);
|
||||
const notebookService = accessor.get<INotebookService>(INotebookService);
|
||||
|
||||
|
||||
const document = notebookService.listNotebookDocuments().find(document => document.uri.toString() === uri.toString());
|
||||
|
||||
if (document) {
|
||||
document.applyEdits(document.versionId, [{ editType: CellEditType.DocumentMetadata, metadata: { ...document.metadata, ...{ trusted: true } } }], true, undefined, () => undefined, undefined, false);
|
||||
}
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand('_resolveNotebookContentProvider', (accessor, args): {
|
||||
viewType: string;
|
||||
displayName: string;
|
||||
|
||||
@@ -61,7 +61,6 @@ export const NOTEBOOK_CELL_OUTPUT_COLLAPSED = new RawContextKey<boolean>('notebo
|
||||
// Shared commands
|
||||
export const EXPAND_CELL_CONTENT_COMMAND_ID = 'notebook.cell.expandCellContent';
|
||||
export const EXECUTE_CELL_COMMAND_ID = 'notebook.cell.execute';
|
||||
export const TRUST_NOTEBOOK_COMMAND_ID = 'notebook.trust';
|
||||
|
||||
// Kernels
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { EDITOR_BOTTOM_PADDING, EDITOR_TOP_PADDING } from 'vs/workbench/contrib/notebook/browser/constants';
|
||||
import { CellFocusMode, CodeCellRenderTemplate, INotebookEditor, TRUST_NOTEBOOK_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CellFocusMode, CodeCellRenderTemplate, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
|
||||
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { ClickTargetType, getExecuteCellPlaceholder } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellWidgets';
|
||||
import { OutputContainer } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellOutput';
|
||||
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
|
||||
import { CellStatusbarAlignment, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
|
||||
export class CodeCell extends Disposable {
|
||||
@@ -248,35 +248,35 @@ export class CodeCell extends Disposable {
|
||||
updatePlaceholder();
|
||||
}));
|
||||
|
||||
const updateUntrustedStatus = () => {
|
||||
if (this.notebookEditor.viewModel
|
||||
&& this.notebookEditor.viewModel.metadata.trusted) {
|
||||
this._untrustedStatusItem?.dispose();
|
||||
this._untrustedStatusItem = null;
|
||||
} else {
|
||||
if (this._untrustedStatusItem === null) {
|
||||
this._untrustedStatusItem = this.notebookCellStatusBarService.addEntry({
|
||||
alignment: CellStatusbarAlignment.LEFT,
|
||||
priority: -1,
|
||||
cellResource: viewCell.uri,
|
||||
command: TRUST_NOTEBOOK_COMMAND_ID,
|
||||
text: 'Untrusted',
|
||||
tooltip: 'Untrusted notebook',
|
||||
visible: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
// const updateUntrustedStatus = () => {
|
||||
// if (this.notebookEditor.viewModel
|
||||
// && this.notebookEditor.viewModel.metadata.trusted) {
|
||||
// this._untrustedStatusItem?.dispose();
|
||||
// this._untrustedStatusItem = null;
|
||||
// } else {
|
||||
// if (this._untrustedStatusItem === null) {
|
||||
// this._untrustedStatusItem = this.notebookCellStatusBarService.addEntry({
|
||||
// alignment: CellStatusbarAlignment.LEFT,
|
||||
// priority: -1,
|
||||
// cellResource: viewCell.uri,
|
||||
// command: TRUST_NOTEBOOK_COMMAND_ID,
|
||||
// text: 'Untrusted',
|
||||
// tooltip: 'Untrusted notebook',
|
||||
// visible: true,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
this._register(this.notebookEditor.viewModel!.notebookDocument.onDidChangeContent(e => {
|
||||
if (e.rawEvents.find(event => event.kind === NotebookCellsChangeType.ChangeDocumentMetadata)) {
|
||||
updatePlaceholder();
|
||||
updateUntrustedStatus();
|
||||
// updateUntrustedStatus();
|
||||
}
|
||||
}));
|
||||
|
||||
updatePlaceholder();
|
||||
updateUntrustedStatus();
|
||||
// updateUntrustedStatus();
|
||||
}
|
||||
|
||||
private viewUpdate(): void {
|
||||
|
||||
@@ -483,6 +483,17 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
|
||||
}
|
||||
}
|
||||
|
||||
private _isDocumentMetadataChangeTransient(a: NotebookDocumentMetadata, b: NotebookDocumentMetadata) {
|
||||
const keys = new Set([...Object.keys(a || {}), ...Object.keys(b || {})]);
|
||||
for (let key of keys) {
|
||||
if (key !== 'trusted') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private _updateNotebookMetadata(metadata: NotebookDocumentMetadata, computeUndoRedo: boolean) {
|
||||
const oldMetadata = this.metadata;
|
||||
this.metadata = metadata;
|
||||
@@ -504,7 +515,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
|
||||
}(), undefined, undefined);
|
||||
}
|
||||
|
||||
this._eventEmitter.emit({ kind: NotebookCellsChangeType.ChangeDocumentMetadata, metadata: this.metadata, transient: false }, true);
|
||||
this._eventEmitter.emit({ kind: NotebookCellsChangeType.ChangeDocumentMetadata, metadata: this.metadata, transient: this._isDocumentMetadataChangeTransient(oldMetadata, metadata) }, true);
|
||||
}
|
||||
|
||||
private _insertNewCell(index: number, cells: NotebookCellTextModel[], synchronous: boolean, endSelections?: number[]): void {
|
||||
|
||||
Reference in New Issue
Block a user