diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts index 4832413c701edfd027433e94df962b5539208b68..69d0a1ad357ef0268e935e1b74217fe309bfd01c 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts @@ -18,8 +18,8 @@ import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/context 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 { BaseCellRenderTemplate, CellEditState, CellRunState, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_RUNNABLE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; -import { CellKind, NOTEBOOK_EDITOR_CURSOR_BOUNDARY } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { BaseCellRenderTemplate, CellEditState, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_RUNNABLE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { CellKind, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, NotebookCellRunState } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -429,7 +429,7 @@ export function getActiveNotebookEditor(editorService: IEditorService): INoteboo } async function runCell(context: INotebookCellActionContext): Promise { - if (context.cell.runState === CellRunState.Running) { + if (context.cell.metadata?.runState === NotebookCellRunState.Running) { return; } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 0bf3e0694af6f74e57b7f3b474da1a0176d51f50..0ced34f4a947d7552485d8d5db7d2024cc45d2f0 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -107,7 +107,6 @@ export interface ICellViewModel { language: string; cellKind: CellKind; editState: CellEditState; - readonly runState: CellRunState; currentTokenSource: CancellationTokenSource | undefined; focusMode: CellFocusMode; getText(): string; @@ -475,11 +474,6 @@ export enum CellRevealPosition { Center } -export enum CellRunState { - Idle, - Running -} - export enum CellEditState { /** * Default state. @@ -511,7 +505,6 @@ export interface CellViewModelStateChangeEvent { metadataChanged?: boolean; selectionChanged?: boolean; focusModeChanged?: boolean; - runStateChanged?: boolean; editStateChanged?: boolean; languageChanged?: boolean; foldingStateChanged?: boolean; diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts index e192f6c863fd8c3ab90837cd8844eb3d9a988b32..16836b0cd629cb4f773b342ad63f43cbd795ffbe 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts @@ -35,7 +35,7 @@ import { IModeService } from 'vs/editor/common/services/modeService'; import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IMenu, MenuItemAction } from 'vs/platform/actions/common/actions'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; @@ -43,7 +43,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { BOTTOM_CELL_TOOLBAR_HEIGHT, EDITOR_BOTTOM_PADDING, EDITOR_TOOLBAR_HEIGHT, EDITOR_TOP_MARGIN, EDITOR_TOP_PADDING } from 'vs/workbench/contrib/notebook/browser/constants'; import { CancelCellAction, ChangeCellLanguageAction, ExecuteCellAction, INotebookCellActionContext, InsertCodeCellAction, InsertMarkdownCellAction } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions'; -import { BaseCellRenderTemplate, CellEditState, CellRunState, CodeCellRenderTemplate, ICellViewModel, INotebookCellList, INotebookEditor, MarkdownCellRenderTemplate, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_RUNNABLE, NOTEBOOK_CELL_RUN_STATE, NOTEBOOK_CELL_TYPE, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { BaseCellRenderTemplate, CellEditState, CodeCellRenderTemplate, ICellViewModel, INotebookCellList, INotebookEditor, MarkdownCellRenderTemplate, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_RUNNABLE, NOTEBOOK_CELL_RUN_STATE, NOTEBOOK_CELL_TYPE, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { CellMenus } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellMenus'; import { CodeCell } from 'vs/workbench/contrib/notebook/browser/view/renderers/codeCell'; import { StatefullMarkdownCell } from 'vs/workbench/contrib/notebook/browser/view/renderers/markdownCell'; @@ -978,9 +978,14 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende return templateData; } - private updateForRunState(element: CodeCellViewModel, templateData: CodeCellRenderTemplate, runStateKey: IContextKey): void { - runStateKey.set(CellRunState[element.runState]); - if (element.runState === CellRunState.Running) { + private updateForRunState(runState: NotebookCellRunState | undefined, templateData: CodeCellRenderTemplate): void { + if (typeof runState === 'undefined') { + runState = NotebookCellRunState.Idle; + } + + const runStateKey = NOTEBOOK_CELL_RUN_STATE.bindTo(templateData.contextKeyService); + runStateKey.set(NotebookCellRunState[runState]); + if (runState === NotebookCellRunState.Running) { templateData.progressBar.infinite().show(500); templateData.runToolbar.setActions([ @@ -995,7 +1000,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende } } - private updateForMetadata(element: CodeCellViewModel, templateData: CodeCellRenderTemplate, cellEditableKey: IContextKey, cellRunnableKey: IContextKey): void { + private updateForMetadata(element: CodeCellViewModel, templateData: CodeCellRenderTemplate): void { + const cellEditableKey = NOTEBOOK_CELL_EDITABLE.bindTo(templateData.contextKeyService); + const cellRunnableKey = NOTEBOOK_CELL_RUNNABLE.bindTo(templateData.contextKeyService); + const metadata = element.getEvaluatedMetadata(this.notebookEditor.viewModel!.notebookDocument.metadata); DOM.toggleClass(templateData.cellContainer, 'runnable', !!metadata.runnable); this.renderExecutionOrder(element, templateData); @@ -1028,6 +1036,8 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende if (typeof metadata.breakpointMargin === 'boolean') { this.editorOptions.setGlyphMargin(metadata.breakpointMargin); } + + this.updateForRunState(metadata.runState, templateData); } private renderExecutionOrder(element: CodeCellViewModel, templateData: CodeCellRenderTemplate): void { @@ -1066,34 +1076,18 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende templateData.focusIndicator.style.height = `${element.layoutInfo.indicatorHeight}px`; })); - const contextKeyService = this.contextKeyServiceProvider(templateData.container); - - const runStateKey = NOTEBOOK_CELL_RUN_STATE.bindTo(contextKeyService); - runStateKey.set(CellRunState[element.runState]); - this.updateForRunState(element, templateData, runStateKey); - elementDisposables.add(element.onDidChangeState((e) => { - if (e.runStateChanged) { - this.updateForRunState(element, templateData, runStateKey); - } - })); - - const cellHasOutputsContext = NOTEBOOK_CELL_HAS_OUTPUTS.bindTo(contextKeyService); + const cellHasOutputsContext = NOTEBOOK_CELL_HAS_OUTPUTS.bindTo(templateData.contextKeyService); cellHasOutputsContext.set(element.outputs.length > 0); elementDisposables.add(element.onDidChangeOutputs(() => { cellHasOutputsContext.set(element.outputs.length > 0); })); - NOTEBOOK_CELL_TYPE.bindTo(contextKeyService).set('code'); - NOTEBOOK_VIEW_TYPE.bindTo(contextKeyService).set(element.viewType); - const metadata = element.getEvaluatedMetadata(this.notebookEditor.viewModel!.notebookDocument.metadata); - const cellEditableKey = NOTEBOOK_CELL_EDITABLE.bindTo(contextKeyService); - cellEditableKey.set(!!metadata.editable); - const cellRunnableKey = NOTEBOOK_CELL_RUNNABLE.bindTo(contextKeyService); - cellRunnableKey.set(!!metadata.runnable); - this.updateForMetadata(element, templateData, cellEditableKey, cellRunnableKey); + NOTEBOOK_CELL_TYPE.bindTo(templateData.contextKeyService).set('code'); + NOTEBOOK_VIEW_TYPE.bindTo(templateData.contextKeyService).set(element.viewType); + this.updateForMetadata(element, templateData); elementDisposables.add(element.onDidChangeState((e) => { if (e.metadataChanged) { - this.updateForMetadata(element, templateData, cellEditableKey, cellRunnableKey); + this.updateForMetadata(element, templateData); } if (e.outputIsHoveredChanged) { @@ -1101,7 +1095,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende } })); - this.setupCellToolbarActions(contextKeyService, templateData, elementDisposables); + this.setupCellToolbarActions(templateData.contextKeyService, templateData, elementDisposables); const toolbarContext = { cell: element, diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts index dd48fc5d3eb28784e6a582de6ad68cc6aec41929..106839fafc88ddf453114492db7692c706318b84 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts @@ -13,7 +13,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon'; import * as model from 'vs/editor/common/model'; import { SearchParams } from 'vs/editor/common/model/textModelSearch'; import { EDITOR_TOOLBAR_HEIGHT, EDITOR_TOP_MARGIN } from 'vs/workbench/contrib/notebook/browser/constants'; -import { CellEditState, CellFocusMode, CellRunState, CursorAtBoundary, CellViewModelStateChangeEvent, IEditableCellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { CellEditState, CellFocusMode, CursorAtBoundary, CellViewModelStateChangeEvent, IEditableCellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { CellKind, NotebookCellMetadata, NotebookDocumentMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel'; @@ -65,21 +65,15 @@ export abstract class BaseCellViewModel extends Disposable { } } - // TODO@roblourens - move any "run"/"status" concept to Code-specific places private _currentTokenSource: CancellationTokenSource | undefined; public set currentTokenSource(v: CancellationTokenSource | undefined) { this._currentTokenSource = v; - this._onDidChangeState.fire({ runStateChanged: true }); } public get currentTokenSource(): CancellationTokenSource | undefined { return this._currentTokenSource; } - get runState(): CellRunState { - return this._currentTokenSource ? CellRunState.Running : CellRunState.Idle; - } - private _focusMode: CellFocusMode = CellFocusMode.Container; get focusMode() { return this._focusMode;