提交 674b5496 编写于 作者: R Rob Lourens

Eliminate duplicate runstate, simplify context keys in cellRenderer

上级 99ff35b0
......@@ -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<void> {
if (context.cell.runState === CellRunState.Running) {
if (context.cell.metadata?.runState === NotebookCellRunState.Running) {
return;
}
......
......@@ -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;
......
......@@ -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<string>): 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<boolean>, cellRunnableKey: IContextKey<boolean>): 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 = <INotebookCellActionContext>{
cell: element,
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册