@@ -58,7 +58,7 @@ export interface NotebookLayoutConfiguration {
58
58
cellToolbarInteraction : string ;
59
59
compactView : boolean ;
60
60
focusIndicator : 'border' | 'gutter' ;
61
- insertToolbarBetweenCells : boolean ;
61
+ insertToolbarPosition : 'betweenCells' | 'notebookToolbar' | 'both' | 'hidden' ;
62
62
insertToolbarAlignment : 'left' | 'center' ;
63
63
globalToolbar : boolean ;
64
64
consolidatedOutputButton : boolean ;
@@ -133,7 +133,8 @@ export class NotebookOptions extends Disposable {
133
133
constructor (
134
134
private readonly configurationService : IConfigurationService ,
135
135
private readonly notebookExecutionStateService : INotebookExecutionStateService ,
136
- private readonly overrides ?: { cellToolbarInteraction : string ; globalToolbar : boolean ; dragAndDropEnabled : boolean ; insertToolbarBetweenCells ?: boolean }
136
+ private isReadonly : boolean ,
137
+ private readonly overrides ?: { cellToolbarInteraction : string ; globalToolbar : boolean ; dragAndDropEnabled : boolean }
137
138
) {
138
139
super ( ) ;
139
140
const showCellStatusBar = this . configurationService . getValue < ShowCellStatusBarType > ( NotebookSetting . showCellStatusBar ) ;
@@ -145,7 +146,7 @@ export class NotebookOptions extends Disposable {
145
146
const cellToolbarInteraction = overrides ?. cellToolbarInteraction ?? this . configurationService . getValue < string > ( NotebookSetting . cellToolbarVisibility ) ;
146
147
const compactView = this . configurationService . getValue < boolean | undefined > ( NotebookSetting . compactView ) ?? true ;
147
148
const focusIndicator = this . _computeFocusIndicatorOption ( ) ;
148
- const insertToolbarBetweenCells = overrides ?. insertToolbarBetweenCells ?? this . _computeInsertToolbarBetweenCellsOption ( ) ;
149
+ const insertToolbarPosition = this . _computeInsertToolbarPositionOption ( this . isReadonly ) ;
149
150
const insertToolbarAlignment = this . _computeInsertToolbarAlignmentOption ( ) ;
150
151
const showFoldingControls = this . _computeShowFoldingControlsOption ( ) ;
151
152
// const { bottomToolbarGap, bottomToolbarHeight } = this._computeBottomToolbarDimensions(compactView, insertToolbarPosition, insertToolbarAlignment);
@@ -219,7 +220,7 @@ export class NotebookOptions extends Disposable {
219
220
cellToolbarInteraction,
220
221
compactView,
221
222
focusIndicator,
222
- insertToolbarBetweenCells ,
223
+ insertToolbarPosition ,
223
224
insertToolbarAlignment,
224
225
showFoldingControls,
225
226
fontSize,
@@ -248,6 +249,22 @@ export class NotebookOptions extends Disposable {
248
249
} ) ) ;
249
250
}
250
251
252
+ updateOptions ( isReadonly : boolean ) {
253
+ if ( this . isReadonly !== isReadonly ) {
254
+ this . isReadonly = isReadonly ;
255
+
256
+ this . _updateConfiguration ( {
257
+ affectsConfiguration ( configuration : string ) : boolean {
258
+ return configuration === NotebookSetting . insertToolbarLocation ;
259
+ } ,
260
+ source : ConfigurationTarget . DEFAULT ,
261
+ affectedKeys : new Set ( [ NotebookSetting . insertToolbarLocation ] ) ,
262
+ change : { keys : [ NotebookSetting . insertToolbarLocation ] , overrides : [ ] } ,
263
+ sourceConfig : undefined
264
+ } ) ;
265
+ }
266
+ }
267
+
251
268
private _migrateDeprecatedSetting ( deprecatedKey : string , key : string ) : void {
252
269
const deprecatedSetting = this . configurationService . inspect ( deprecatedKey ) ;
253
270
@@ -369,7 +386,7 @@ export class NotebookOptions extends Disposable {
369
386
configuration . cellToolbarLocation = this . configurationService . getValue < string | { [ key : string ] : string } > ( NotebookSetting . cellToolbarLocation ) ?? { 'default' : 'right' } ;
370
387
}
371
388
372
- if ( cellToolbarInteraction && this . overrides ?. cellToolbarInteraction === undefined ) {
389
+ if ( cellToolbarInteraction && ! this . overrides ?. cellToolbarInteraction ) {
373
390
configuration . cellToolbarInteraction = this . configurationService . getValue < string > ( NotebookSetting . cellToolbarVisibility ) ;
374
391
}
375
392
@@ -389,8 +406,8 @@ export class NotebookOptions extends Disposable {
389
406
configuration . insertToolbarAlignment = this . _computeInsertToolbarAlignmentOption ( ) ;
390
407
}
391
408
392
- if ( insertToolbarPosition && this . overrides ?. insertToolbarBetweenCells === undefined ) {
393
- configuration . insertToolbarBetweenCells = this . _computeInsertToolbarBetweenCellsOption ( ) ;
409
+ if ( insertToolbarPosition ) {
410
+ configuration . insertToolbarPosition = this . _computeInsertToolbarPositionOption ( this . isReadonly ) ;
394
411
}
395
412
396
413
if ( globalToolbar && this . overrides ?. globalToolbar === undefined ) {
@@ -479,9 +496,8 @@ export class NotebookOptions extends Disposable {
479
496
} ) ;
480
497
}
481
498
482
- private _computeInsertToolbarBetweenCellsOption ( ) {
483
- const configValue = this . configurationService . getValue < 'betweenCells' | 'notebookToolbar' | 'both' | 'hidden' > ( NotebookSetting . insertToolbarLocation ) ?? 'both' ;
484
- return configValue === 'betweenCells' || configValue === 'both' ;
499
+ private _computeInsertToolbarPositionOption ( isReadOnly : boolean ) {
500
+ return isReadOnly ? 'hidden' : this . configurationService . getValue < 'betweenCells' | 'notebookToolbar' | 'both' | 'hidden' > ( NotebookSetting . insertToolbarLocation ) ?? 'both' ;
485
501
}
486
502
487
503
private _computeInsertToolbarAlignmentOption ( ) {
@@ -513,16 +529,16 @@ export class NotebookOptions extends Disposable {
513
529
return this . _layoutConfiguration ;
514
530
}
515
531
516
- computeCollapsedMarkdownCellHeight ( viewType : string , isReadOnly : boolean ) : number {
517
- const { bottomToolbarGap } = this . computeBottomToolbarDimensions ( viewType , isReadOnly ) ;
532
+ computeCollapsedMarkdownCellHeight ( viewType : string ) : number {
533
+ const { bottomToolbarGap } = this . computeBottomToolbarDimensions ( viewType ) ;
518
534
return this . _layoutConfiguration . markdownCellTopMargin
519
535
+ this . _layoutConfiguration . collapsedIndicatorHeight
520
536
+ bottomToolbarGap
521
537
+ this . _layoutConfiguration . markdownCellBottomMargin ;
522
538
}
523
539
524
- computeBottomToolbarOffset ( totalHeight : number , viewType : string , isReadOnly : boolean ) {
525
- const { bottomToolbarGap, bottomToolbarHeight } = this . computeBottomToolbarDimensions ( viewType , isReadOnly ) ;
540
+ computeBottomToolbarOffset ( totalHeight : number , viewType : string ) {
541
+ const { bottomToolbarGap, bottomToolbarHeight } = this . computeBottomToolbarDimensions ( viewType ) ;
526
542
527
543
return totalHeight
528
544
- bottomToolbarGap
@@ -548,37 +564,34 @@ export class NotebookOptions extends Disposable {
548
564
return this . _layoutConfiguration . cellStatusBarHeight ;
549
565
}
550
566
551
- private _computeBottomToolbarDimensions ( compactView : boolean , insertToolbarBetweenCells : boolean , insertToolbarAlignment : 'left' | 'center' , cellToolbar : 'right' | 'left' | 'hidden' ) : { bottomToolbarGap : number ; bottomToolbarHeight : number } {
552
- if ( ! insertToolbarBetweenCells ) {
553
- return compactView ? {
554
- bottomToolbarGap : 0 ,
555
- bottomToolbarHeight : 0
556
- } : {
557
- bottomToolbarGap : 12 ,
558
- bottomToolbarHeight : 12
559
- } ;
560
- }
561
-
567
+ private _computeBottomToolbarDimensions ( compactView : boolean , insertToolbarPosition : 'betweenCells' | 'notebookToolbar' | 'both' | 'hidden' , insertToolbarAlignment : 'left' | 'center' , cellToolbar : 'right' | 'left' | 'hidden' ) : { bottomToolbarGap : number ; bottomToolbarHeight : number } {
562
568
if ( insertToolbarAlignment === 'left' || cellToolbar !== 'hidden' ) {
563
569
return {
564
570
bottomToolbarGap : 18 ,
565
571
bottomToolbarHeight : 18
566
572
} ;
567
573
}
568
574
569
- return compactView ? {
570
- bottomToolbarGap : 12 ,
571
- bottomToolbarHeight : 20
572
- } : {
573
- bottomToolbarGap : 20 ,
574
- bottomToolbarHeight : 20
575
- } ;
575
+ if ( insertToolbarPosition === 'betweenCells' || insertToolbarPosition === 'both' ) {
576
+ return compactView ? {
577
+ bottomToolbarGap : 12 ,
578
+ bottomToolbarHeight : 20
579
+ } : {
580
+ bottomToolbarGap : 20 ,
581
+ bottomToolbarHeight : 20
582
+ } ;
583
+ } else {
584
+ return {
585
+ bottomToolbarGap : 0 ,
586
+ bottomToolbarHeight : 0
587
+ } ;
588
+ }
576
589
}
577
590
578
- computeBottomToolbarDimensions ( viewType ?: string , isReadOnly ?: boolean ) : { bottomToolbarGap : number ; bottomToolbarHeight : number } {
591
+ computeBottomToolbarDimensions ( viewType ?: string ) : { bottomToolbarGap : number ; bottomToolbarHeight : number } {
579
592
const configuration = this . _layoutConfiguration ;
580
593
const cellToolbarPosition = this . computeCellToolbarLocation ( viewType ) ;
581
- const { bottomToolbarGap, bottomToolbarHeight } = this . _computeBottomToolbarDimensions ( configuration . compactView , configuration . insertToolbarBetweenCells && ! isReadOnly , configuration . insertToolbarAlignment , cellToolbarPosition ) ;
594
+ const { bottomToolbarGap, bottomToolbarHeight } = this . _computeBottomToolbarDimensions ( configuration . compactView , configuration . insertToolbarPosition , configuration . insertToolbarAlignment , cellToolbarPosition ) ;
582
595
return {
583
596
bottomToolbarGap,
584
597
bottomToolbarHeight
@@ -619,8 +632,8 @@ export class NotebookOptions extends Disposable {
619
632
return 'right' ;
620
633
}
621
634
622
- computeTopInsertToolbarHeight ( viewType ?: string , isReadOnly ?: boolean ) : number {
623
- if ( this . _layoutConfiguration . insertToolbarBetweenCells && ! isReadOnly ) {
635
+ computeTopInsertToolbarHeight ( viewType ?: string ) : number {
636
+ if ( this . _layoutConfiguration . insertToolbarPosition === 'betweenCells' || this . _layoutConfiguration . insertToolbarPosition === 'both' ) {
624
637
return SCROLLABLE_ELEMENT_PADDING_TOP ;
625
638
}
626
639
@@ -700,8 +713,8 @@ export class NotebookOptions extends Disposable {
700
713
} ;
701
714
}
702
715
703
- computeIndicatorPosition ( totalHeight : number , foldHintHeight : number , viewType ?: string , isReadOnly ?: boolean ) {
704
- const { bottomToolbarGap } = this . computeBottomToolbarDimensions ( viewType , isReadOnly ) ;
716
+ computeIndicatorPosition ( totalHeight : number , foldHintHeight : number , viewType ?: string ) {
717
+ const { bottomToolbarGap } = this . computeBottomToolbarDimensions ( viewType ) ;
705
718
706
719
return {
707
720
bottomIndicatorTop : totalHeight - bottomToolbarGap - this . _layoutConfiguration . cellBottomMargin - foldHintHeight ,
0 commit comments