@@ -36,7 +36,8 @@ import { MarkdownRenderer } from '@theia/core/lib/browser/markdown-rendering/mar
3636import { MarkdownString } from '@theia/monaco-editor-core/esm/vs/base/common/htmlContent' ;
3737import { NotebookCellEditorService } from '../service/notebook-cell-editor-service' ;
3838import { CellOutputWebview } from '../renderers/cell-output-webview' ;
39- import { NotebookCellStatusBarItemList , NotebookCellStatusBarService } from '../service/notebook-cell-status-bar-service' ;
39+ import { NotebookCellStatusBarItem , NotebookCellStatusBarItemList , NotebookCellStatusBarService } from '../service/notebook-cell-status-bar-service' ;
40+ import { LabelParser } from '@theia/core/lib/browser/label-parser' ;
4041
4142@injectable ( )
4243export class NotebookCodeCellRenderer implements CellRenderer {
@@ -79,6 +80,9 @@ export class NotebookCodeCellRenderer implements CellRenderer {
7980 @inject ( NotebookCellStatusBarService )
8081 protected readonly notebookCellStatusBarService : NotebookCellStatusBarService ;
8182
83+ @inject ( LabelParser )
84+ protected readonly labelParser : LabelParser ;
85+
8286 render ( notebookModel : NotebookModel , cell : NotebookCellModel , handle : number ) : React . ReactNode {
8387 return < div className = 'theia-notebook-cell-with-sidebar' ref = { ref => observeCellHeight ( ref , cell ) } >
8488 < div className = 'theia-notebook-cell-editor-container' >
@@ -92,6 +96,7 @@ export class NotebookCodeCellRenderer implements CellRenderer {
9296 commandRegistry = { this . commandRegistry }
9397 executionStateService = { this . executionStateService }
9498 cellStatusBarService = { this . notebookCellStatusBarService }
99+ labelParser = { this . labelParser }
95100 onClick = { ( ) => cell . requestFocusEditor ( ) } />
96101 </ div >
97102 </ div > ;
@@ -189,6 +194,7 @@ export interface NotebookCodeCellStatusProps {
189194 commandRegistry : CommandRegistry ;
190195 cellStatusBarService : NotebookCellStatusBarService ;
191196 executionStateService ?: NotebookExecutionStateService ;
197+ labelParser : LabelParser ;
192198 onClick : ( ) => void ;
193199}
194200
@@ -234,13 +240,14 @@ export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStat
234240 this . forceUpdate ( ) ;
235241 } ) ) ;
236242
237- this . getStatusBarItems ( ) ;
238- this . props . cellStatusBarService . onDidChangeItems ( ( ) => this . getStatusBarItems ( ) ) ;
243+ this . updateStatusBarItems ( ) ;
244+ this . props . cellStatusBarService . onDidChangeItems ( ( ) => this . updateStatusBarItems ( ) ) ;
245+ this . props . notebook . onContentChanged ( ( ) => this . updateStatusBarItems ( ) ) ;
239246 }
240247
241- async getStatusBarItems ( ) : Promise < void > {
248+ async updateStatusBarItems ( ) : Promise < void > {
242249 this . statusBarItems = await this . props . cellStatusBarService . getStatusBarItemsForCell (
243- this . props . cell . uri ,
250+ this . props . notebook . uri ,
244251 this . props . notebook . cells . indexOf ( this . props . cell ) ,
245252 this . props . notebook . viewType ,
246253 CancellationToken . None ) ;
@@ -255,7 +262,7 @@ export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStat
255262 return < div className = 'notebook-cell-status' onClick = { ( ) => this . props . onClick ( ) } >
256263 < div className = 'notebook-cell-status-left' >
257264 { this . props . executionStateService && this . renderExecutionState ( ) }
258- { this . statusBarItems ?. length > 0 && this . renderStatusBarItems ( ) }
265+ { this . statusBarItems ?. length && this . renderStatusBarItems ( ) }
259266 </ div >
260267 < div className = 'notebook-cell-status-right' >
261268 < span className = 'notebook-cell-language-label' onClick = { ( ) => {
@@ -265,7 +272,7 @@ export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStat
265272 </ div > ;
266273 }
267274
268- private renderExecutionState ( ) : React . ReactNode {
275+ protected renderExecutionState ( ) : React . ReactNode {
269276 const state = this . state . currentExecution ?. state ;
270277 const { lastRunSuccess } = this . props . cell . internalMetadata ;
271278
@@ -291,7 +298,7 @@ export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStat
291298 </ > ;
292299 }
293300
294- private getExecutionTime ( ) : number {
301+ protected getExecutionTime ( ) : number {
295302 const { runStartTime, runEndTime } = this . props . cell . internalMetadata ;
296303 const { executionTime } = this . state ;
297304 if ( runStartTime !== undefined && runEndTime !== undefined ) {
@@ -300,21 +307,42 @@ export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStat
300307 return executionTime ;
301308 }
302309
303- private renderTime ( ms : number ) : string {
310+ protected renderTime ( ms : number ) : string {
304311 return `${ ( ms / 1000 ) . toLocaleString ( undefined , { maximumFractionDigits : 1 , minimumFractionDigits : 1 } ) } s` ;
305312 }
306313
307- private renderStatusBarItems ( ) : React . ReactNode {
314+ protected renderStatusBarItems ( ) : React . ReactNode {
308315 return < >
309316 {
310- this . statusBarItems . map ( ( itemList , listIndex ) =>
311- < > { itemList . items . map ( ( item , index ) =>
312- < span key = { `${ listIndex } -${ index } ` } > { item . text } </ span >
313- ) } </ >
317+ this . statusBarItems . flatMap ( ( itemList , listIndex ) =>
318+ itemList . items . map ( ( item , index ) => this . renderStatusBarItem ( item , `${ listIndex } -${ index } ` )
319+ )
314320 )
315321 }
316322 </ > ;
317323 }
324+
325+ protected renderStatusBarItem ( item : NotebookCellStatusBarItem , key : string ) : React . ReactNode {
326+ const content = this . props . labelParser . parse ( item . text ) . map ( part => {
327+ if ( typeof part === 'string' ) {
328+ return part ;
329+ } else {
330+ return < span key = { part . name } className = { `codicon codicon-${ part . name } ` } > </ span > ;
331+ }
332+ } ) ;
333+ return < div key = { key } className = { `cell-status-bar-item ${ item . command ? 'cell-status-item-has-command' : '' } ` } onClick = { async ( ) => {
334+ if ( item . command ) {
335+ if ( typeof item . command === 'string' ) {
336+ this . props . commandRegistry . executeCommand ( item . command ) ;
337+ } else {
338+ this . props . commandRegistry . executeCommand ( item . command . id , ...( item . command . arguments ?? [ ] ) ) ;
339+ }
340+ }
341+ } } >
342+ { content }
343+ </ div > ;
344+ }
345+
318346}
319347
320348interface NotebookCellOutputProps {
0 commit comments