@@ -119,6 +119,8 @@ abstract class AbstractCellRenderer {
119119 return menu ;
120120 }
121121
122+ abstract getCellToolbarActions ( element : CellViewModel ) : IAction [ ] ;
123+
122124 showContextMenu ( listIndex : number | undefined , element : CellViewModel , x : number , y : number ) {
123125 const actions : IAction [ ] = [
124126 this . instantiationService . createInstance ( InsertCodeCellAboveAction ) ,
@@ -215,21 +217,16 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
215217
216218 const contextKeyService = this . contextKeyService . createScoped ( templateData . container ) ;
217219 contextKeyService . createKey ( NOTEBOOK_CELL_TYPE_CONTEXT_KEY , 'markdown' ) ;
218- const menu = this . createMenu ( ) . getCellTitleActions ( this . contextKeyService ) ;
219- const actions : IAction [ ] = [ ] ;
220- for ( let [ , actions ] of menu . getActions ( { shouldForwardArgs : true } ) ) {
221- actions . push ( ...actions ) ;
220+ const toolbarActions = this . getCellToolbarActions ( element ) ;
221+ templateData . toolbar ! . setActions ( toolbarActions ) ( ) ;
222+
223+ if ( templateData . focusIndicator ) {
224+ if ( ! toolbarActions . length ) {
225+ templateData . focusIndicator . style . top = `8px` ;
226+ } else {
227+ templateData . focusIndicator . style . top = `24px` ;
228+ }
222229 }
223-
224- templateData . toolbar ! . setActions ( [
225- ...actions ,
226- this . instantiationService . createInstance ( MoveCellUpAction ) ,
227- this . instantiationService . createInstance ( MoveCellDownAction ) ,
228- this . instantiationService . createInstance ( InsertCodeCellBelowAction ) ,
229- this . instantiationService . createInstance ( EditCellAction ) ,
230- this . instantiationService . createInstance ( SaveCellAction ) ,
231- this . instantiationService . createInstance ( DeleteCellAction )
232- ] ) ( ) ;
233230 }
234231
235232 templateData . toolbar ! . context = < INotebookCellActionContext > {
@@ -239,6 +236,44 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
239236 } ;
240237 }
241238
239+ getCellToolbarActions ( element : CellViewModel ) : IAction [ ] {
240+ const viewModel = this . notebookEditor . viewModel ;
241+
242+ if ( ! viewModel ) {
243+ return [ ] ;
244+ }
245+
246+ const menu = this . createMenu ( ) . getCellTitleActions ( this . contextKeyService ) ;
247+ const actions : IAction [ ] = [ ] ;
248+ for ( let [ , actions ] of menu . getActions ( { shouldForwardArgs : true } ) ) {
249+ actions . push ( ...actions ) ;
250+ }
251+
252+ const metadata = viewModel . metadata ;
253+
254+ if ( ! metadata || metadata . editable ) {
255+ actions . push (
256+ this . instantiationService . createInstance ( MoveCellUpAction ) ,
257+ this . instantiationService . createInstance ( MoveCellDownAction ) ,
258+ this . instantiationService . createInstance ( InsertCodeCellBelowAction )
259+ ) ;
260+ }
261+
262+ const cellMetadata = element . metadata ;
263+ if ( ! cellMetadata || cellMetadata . editable ) {
264+ actions . push (
265+ this . instantiationService . createInstance ( EditCellAction ) ,
266+ this . instantiationService . createInstance ( SaveCellAction )
267+ ) ;
268+ }
269+
270+ if ( ! metadata || metadata . editable ) {
271+ this . instantiationService . createInstance ( DeleteCellAction ) ;
272+ }
273+
274+ return actions ;
275+ }
276+
242277 getAdditionalContextMenuActions ( ) : IAction [ ] {
243278 return [
244279 this . instantiationService . createInstance ( EditCellAction ) ,
@@ -363,24 +398,49 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
363398
364399 const contextKeyService = this . contextKeyService . createScoped ( templateData . container ) ;
365400 contextKeyService . createKey ( NOTEBOOK_CELL_TYPE_CONTEXT_KEY , 'code' ) ;
366- const menu = this . createMenu ( ) . getCellTitleActions ( contextKeyService ) ;
401+ const toolbarActions = this . getCellToolbarActions ( element ) ;
402+ templateData . toolbar ! . setActions ( toolbarActions ) ( ) ;
403+ templateData . toolbar ! . context = toolbarContext ;
404+ templateData . runToolbar ! . context = toolbarContext ;
405+
406+ if ( templateData . focusIndicator ) {
407+ if ( ! toolbarActions . length ) {
408+ templateData . focusIndicator . style . top = `8px` ;
409+ } else {
410+ templateData . focusIndicator . style . top = `24px` ;
411+ }
412+ }
413+ }
414+
415+
416+ getCellToolbarActions ( element : CellViewModel ) : IAction [ ] {
417+ const viewModel = this . notebookEditor . viewModel ;
418+
419+ if ( ! viewModel ) {
420+ return [ ] ;
421+ }
422+
423+ const menu = this . createMenu ( ) . getCellTitleActions ( this . contextKeyService ) ;
367424 const actions : IAction [ ] = [ ] ;
368- for ( let [ , items ] of menu . getActions ( { shouldForwardArgs : true } ) ) {
369- actions . push ( ...items ) ;
425+ for ( let [ , actions ] of menu . getActions ( { shouldForwardArgs : true } ) ) {
426+ actions . push ( ...actions ) ;
370427 }
371428
372- templateData . toolbar ! . setActions ( [
373- ...actions ,
374- this . instantiationService . createInstance ( MoveCellUpAction ) ,
375- this . instantiationService . createInstance ( MoveCellDownAction ) ,
376- this . instantiationService . createInstance ( InsertCodeCellBelowAction ) ,
377- this . instantiationService . createInstance ( DeleteCellAction )
378- ] ) ( ) ;
429+ const metadata = viewModel . metadata ;
379430
380- templateData . toolbar ! . context = toolbarContext ;
381- templateData . runToolbar ! . context = toolbarContext ;
431+ if ( ! metadata || metadata . editable ) {
432+ actions . push (
433+ this . instantiationService . createInstance ( MoveCellUpAction ) ,
434+ this . instantiationService . createInstance ( MoveCellDownAction ) ,
435+ this . instantiationService . createInstance ( InsertCodeCellBelowAction ) ,
436+ this . instantiationService . createInstance ( DeleteCellAction )
437+ ) ;
438+ }
439+
440+ return actions ;
382441 }
383442
443+
384444 getAdditionalContextMenuActions ( ) : IAction [ ] {
385445 return [ ] ;
386446 }
0 commit comments