diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 445f6c6a1a9..4e554b1bc2f 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -148,7 +148,7 @@ export class InteractiveEditor extends EditorPane { this.#notebookExecutionStateService = notebookExecutionStateService; this.#extensionService = extensionService; - this.#notebookOptions = new NotebookOptions(configurationService, notebookExecutionStateService, { cellToolbarInteraction: 'hover', globalToolbar: true, dragAndDropEnabled: false }); + this.#notebookOptions = new NotebookOptions(configurationService, notebookExecutionStateService, true, { cellToolbarInteraction: 'hover', globalToolbar: true, dragAndDropEnabled: false }); this.#editorMemento = this.getEditorMemento(editorGroupService, textResourceConfigurationService, INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY); codeEditorService.registerDecorationType('interactive-decoration', DECORATION_KEY, {}); diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts index 4b5054fcfbb..d951f7928ff 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts @@ -151,7 +151,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD @INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService, ) { super(NotebookTextDiffEditor.ID, telemetryService, themeService, storageService); - this._notebookOptions = new NotebookOptions(this.configurationService, notebookExecutionStateService); + this._notebookOptions = new NotebookOptions(this.configurationService, notebookExecutionStateService, false); this._register(this._notebookOptions); const editorOptions = this.configurationService.getValue('editor'); this._fontInfo = FontMeasurements.readFontInfo(BareFontInfo.createFromRawSettings(editorOptions, PixelRatio.value)); diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index cd9e8eef631..482c5c5e516 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -292,7 +292,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD this.isEmbedded = creationOptions.isEmbedded ?? false; this._readOnly = creationOptions.isReadOnly ?? false; - this._notebookOptions = creationOptions.options ?? new NotebookOptions(this.configurationService, notebookExecutionStateService); + this._notebookOptions = creationOptions.options ?? new NotebookOptions(this.configurationService, notebookExecutionStateService, this._readOnly); this._register(this._notebookOptions); this._viewContext = new ViewContext( this._notebookOptions, @@ -1176,6 +1176,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD } this.viewModel.updateOptions({ isReadOnly: this._readOnly }); + this.notebookOptions.updateOptions(this._readOnly); // reveal cell if editor options tell to do so const cellOptions = options?.cellOptions ?? this._parseIndexedCellOptions(options); @@ -1364,6 +1365,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD this.viewModel = this.instantiationService.createInstance(NotebookViewModel, textModel.viewType, textModel, this._viewContext, this.getLayoutInfo(), { isReadOnly: this._readOnly }); this._viewContext.eventDispatcher.emit([new NotebookLayoutChangedEvent({ width: true, fontInfo: true }, this.getLayoutInfo())]); + this.notebookOptions.updateOptions(this._readOnly); this._updateForOptions(); this._updateForNotebookConfiguration(); diff --git a/src/vs/workbench/contrib/notebook/browser/notebookOptions.ts b/src/vs/workbench/contrib/notebook/browser/notebookOptions.ts index 3546e299079..2140b0286ae 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookOptions.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookOptions.ts @@ -133,6 +133,7 @@ export class NotebookOptions extends Disposable { constructor( private readonly configurationService: IConfigurationService, private readonly notebookExecutionStateService: INotebookExecutionStateService, + private isReadonly: boolean, private readonly overrides?: { cellToolbarInteraction: string; globalToolbar: boolean; dragAndDropEnabled: boolean } ) { super(); @@ -145,7 +146,7 @@ export class NotebookOptions extends Disposable { const cellToolbarInteraction = overrides?.cellToolbarInteraction ?? this.configurationService.getValue(NotebookSetting.cellToolbarVisibility); const compactView = this.configurationService.getValue(NotebookSetting.compactView) ?? true; const focusIndicator = this._computeFocusIndicatorOption(); - const insertToolbarPosition = this._computeInsertToolbarPositionOption(); + const insertToolbarPosition = this._computeInsertToolbarPositionOption(this.isReadonly); const insertToolbarAlignment = this._computeInsertToolbarAlignmentOption(); const showFoldingControls = this._computeShowFoldingControlsOption(); // const { bottomToolbarGap, bottomToolbarHeight } = this._computeBottomToolbarDimensions(compactView, insertToolbarPosition, insertToolbarAlignment); @@ -248,6 +249,22 @@ export class NotebookOptions extends Disposable { })); } + updateOptions(isReadonly: boolean) { + if (this.isReadonly !== isReadonly) { + this.isReadonly = isReadonly; + + this._updateConfiguration({ + affectsConfiguration(configuration: string): boolean { + return configuration === NotebookSetting.insertToolbarLocation; + }, + source: ConfigurationTarget.DEFAULT, + affectedKeys: new Set([NotebookSetting.insertToolbarLocation]), + change: { keys: [NotebookSetting.insertToolbarLocation], overrides: [] }, + sourceConfig: undefined + }); + } + } + private _migrateDeprecatedSetting(deprecatedKey: string, key: string): void { const deprecatedSetting = this.configurationService.inspect(deprecatedKey); @@ -390,7 +407,7 @@ export class NotebookOptions extends Disposable { } if (insertToolbarPosition) { - configuration.insertToolbarPosition = this._computeInsertToolbarPositionOption(); + configuration.insertToolbarPosition = this._computeInsertToolbarPositionOption(this.isReadonly); } if (globalToolbar && this.overrides?.globalToolbar === undefined) { @@ -479,8 +496,8 @@ export class NotebookOptions extends Disposable { }); } - private _computeInsertToolbarPositionOption() { - return this.configurationService.getValue<'betweenCells' | 'notebookToolbar' | 'both' | 'hidden'>(NotebookSetting.insertToolbarLocation) ?? 'both'; + private _computeInsertToolbarPositionOption(isReadOnly: boolean) { + return isReadOnly ? 'hidden' : this.configurationService.getValue<'betweenCells' | 'notebookToolbar' | 'both' | 'hidden'>(NotebookSetting.insertToolbarLocation) ?? 'both'; } private _computeInsertToolbarAlignmentOption() { diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts index 3858986efe8..4d9d8efd3de 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts @@ -202,7 +202,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod // recompute this._ensureOutputsTop(); const notebookLayoutConfiguration = this.viewContext.notebookOptions.getLayoutConfiguration(); - const bottomToolbarDimensions = this.viewContext.notebookOptions.computeBottomToolbarDimensions(); + const bottomToolbarDimensions = this.viewContext.notebookOptions.computeBottomToolbarDimensions(this.viewType); const outputShowMoreContainerHeight = state.outputShowMoreContainerHeight ? state.outputShowMoreContainerHeight : this._layoutInfo.outputShowMoreContainerHeight; const outputTotalHeight = Math.max(this._outputMinHeight, this.isOutputCollapsed ? notebookLayoutConfiguration.collapsedIndicatorHeight : this._outputsTop!.getTotalSum()); const commentHeight = state.commentHeight ? this._commentHeight : this._layoutInfo.commentHeight; diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts index b1240e9adaf..047e8baa9aa 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookCellList.test.ts @@ -21,7 +21,7 @@ suite('NotebookCellList', () => { suiteSetup(() => { disposables = new DisposableStore(); instantiationService = setupInstantiationService(disposables); - notebookDefaultOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService)); + notebookDefaultOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false); topInsertToolbarHeight = notebookDefaultOptions.computeTopInsertToolbarHeight(); }); diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts index b6f13158a18..b5134c88bdf 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts @@ -58,7 +58,7 @@ suite('NotebookViewModel', () => { test('ctor', function () { const notebook = new NotebookTextModel('notebook', URI.parse('test'), [], {}, { transientCellMetadata: {}, transientDocumentMetadata: {}, transientOutputs: false, cellContentMetadata: {} }, undoRedoService, modelService, languageService); const model = new NotebookEditorTestModel(notebook); - const viewContext = new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService)), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)); + const viewContext = new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)); const viewModel = new NotebookViewModel('notebook', model.notebook, viewContext, null, { isReadOnly: false }, instantiationService, bulkEditService, undoRedoService, textModelService, notebookExecutionStateService); assert.strictEqual(viewModel.viewType, 'notebook'); }); diff --git a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts index 25506f54286..c9f0a3114c7 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts @@ -201,7 +201,7 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic }), {}, { transientCellMetadata: {}, transientDocumentMetadata: {}, cellContentMetadata: {}, transientOutputs: false }); const model = new NotebookEditorTestModel(notebook); - const notebookOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService)); + const notebookOptions = new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false); const viewContext = new ViewContext(notebookOptions, new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)); const viewModel: NotebookViewModel = instantiationService.createInstance(NotebookViewModel, viewType, model.notebook, viewContext, null, { isReadOnly: false }); @@ -374,7 +374,7 @@ export function createNotebookCellList(instantiationService: TestInstantiationSe NotebookCellList, 'NotebookCellList', DOM.$('container'), - viewContext ?? new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService)), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)), + viewContext ?? new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService), instantiationService.get(INotebookExecutionStateService), false), new NotebookEventDispatcher(), () => ({} as IBaseCellEditorOptions)), delegate, [renderer], instantiationService.get(IContextKeyService),