Enable contributing to cell execute dropdown

Towards #130524
This commit is contained in:
Rob Lourens 2021-08-10 15:45:02 -07:00
parent 7a034baa92
commit 1c445fe4c7
7 changed files with 31 additions and 15 deletions

View file

@ -10,13 +10,17 @@ import { ActionViewItem, BaseActionViewItem } from 'vs/base/browser/ui/actionbar
import { DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem';
import { IAction } from 'vs/base/common/actions';
import { Event } from 'vs/base/common/event';
import { KeyCode } from 'vs/base/common/keyCodes';
import { KeyCode, ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
export interface IDropdownWithPrimaryActionViewItemOptions {
getKeyBinding?: (action: IAction) => ResolvedKeybinding | undefined;
}
export class DropdownWithPrimaryActionViewItem extends BaseActionViewItem {
private _primaryAction: ActionViewItem;
private _dropdown: DropdownMenuActionViewItem;
@ -33,6 +37,7 @@ export class DropdownWithPrimaryActionViewItem extends BaseActionViewItem {
dropdownMenuActions: IAction[],
className: string,
private readonly _contextMenuProvider: IContextMenuProvider,
private readonly _options: IDropdownWithPrimaryActionViewItemOptions | undefined,
@IKeybindingService _keybindingService: IKeybindingService,
@INotificationService _notificationService: INotificationService,
@IContextKeyService _contextKeyService: IContextKeyService
@ -41,7 +46,8 @@ export class DropdownWithPrimaryActionViewItem extends BaseActionViewItem {
this._primaryAction = new MenuEntryActionViewItem(primaryAction, undefined, _keybindingService, _notificationService, _contextKeyService);
this._dropdown = new DropdownMenuActionViewItem(dropdownAction, dropdownMenuActions, this._contextMenuProvider, {
menuAsChild: true,
classNames: ['codicon', 'codicon-chevron-down']
classNames: ['codicon', 'codicon-chevron-down'],
keybindingProvider: this._options?.getKeyBinding
});
}

View file

@ -188,6 +188,11 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.NotebookCellTitle,
description: localize('notebook.cell.title', "The contributed notebook cell title menu")
},
{
key: 'notebook/cell/execute',
id: MenuId.NotebookCellExecute,
description: localize('notebook.cell.execute', "The contributed notebook cell execution menu")
},
{
key: 'interactive/toolbar',
id: MenuId.InteractiveToolbar,

View file

@ -19,7 +19,7 @@ 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, CellFocusMode, EXECUTE_CELL_COMMAND_ID, EXPAND_CELL_INPUT_COMMAND_ID, getNotebookEditorFromEditorPane, IActiveNotebookEditor, ICellViewModel, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_HAS_RUNNING_CELL, CHANGE_CELL_LANGUAGE, QUIT_EDIT_CELL_COMMAND_ID, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_CELL_EXECUTING, NOTEBOOK_MISSING_KERNEL_EXTENSION, EXPAND_CELL_OUTPUT_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellEditType, CellKind, ICellEditOperation, isDocumentExcludePattern, NotebookCellMetadata, NotebookCellExecutionState, TransientCellMetadata, TransientDocumentMetadata, SelectionStateType, ICellReplaceEdit, OpenGettingStarted, GlobalToolbarShowLabel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellEditType, CellKind, ICellEditOperation, isDocumentExcludePattern, NotebookCellMetadata, NotebookCellExecutionState, TransientCellMetadata, TransientDocumentMetadata, SelectionStateType, ICellReplaceEdit, OpenGettingStarted, GlobalToolbarShowLabel, ConsolidatedRunButton } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange, isICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
@ -417,7 +417,9 @@ registerAction2(class ExecuteAboveCells extends NotebookMultiCellAction<INoteboo
menu: [
{
id: MenuId.NotebookCellExecute,
when: executeCellCondition
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, true))
},
{
id: MenuId.NotebookCellTitle,
@ -425,7 +427,7 @@ registerAction2(class ExecuteAboveCells extends NotebookMultiCellAction<INoteboo
group: CELL_TITLE_CELL_GROUP_ID,
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals('config.notebook.consolidatedRunButton', false))
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, false))
}
],
icon: icons.executeAboveIcon
@ -461,7 +463,9 @@ registerAction2(class ExecuteCellAndBelow extends NotebookMultiCellAction<INoteb
menu: [
{
id: MenuId.NotebookCellExecute,
when: executeCellCondition,
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, true))
},
{
id: MenuId.NotebookCellTitle,
@ -469,7 +473,7 @@ registerAction2(class ExecuteCellAndBelow extends NotebookMultiCellAction<INoteb
group: CELL_TITLE_CELL_GROUP_ID,
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals('config.notebook.consolidatedRunButton', false))
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, false))
}
],
icon: icons.executeBelowIcon

View file

@ -819,9 +819,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
const actionViewItemDisposables = disposables.add(new DisposableStore());
const dropdownAction = disposables.add(new Action('notebook.moreRunActions', localize('notebook.moreRunActionsLabel', "More..."), 'codicon-chevron-down', true));
const keybindingProvider = (action: IAction) => this.keybindingService.lookupKeybinding(action.id, executionContextKeyService);
const executionContextKeyService = disposables.add(getCodeCellExecutionContextKeyService(contextKeyService));
const toolbar = disposables.add(new ToolBar(container, this.contextMenuService, {
getKeyBinding: action => this.keybindingService.lookupKeybinding(action.id, executionContextKeyService),
getKeyBinding: keybindingProvider,
actionViewItemProvider: _action => {
actionViewItemDisposables.clear();
@ -836,16 +837,15 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
return undefined;
}
if (!this.notebookEditor.notebookOptions.getLayoutConfiguration().consolidatedRunButton) {
return undefined;
}
const item = this.instantiationService.createInstance(DropdownWithPrimaryActionViewItem,
primary,
dropdownAction,
actions.secondary,
'notebook-cell-run-toolbar',
this.contextMenuService);
this.contextMenuService,
{
getKeyBinding: keybindingProvider
});
actionViewItemDisposables.add(item.onDidChangeDropdownVisibility(visible => {
cellContainer.classList.toggle('cell-run-toolbar-dropdown-active', visible);
}));

View file

@ -202,7 +202,7 @@ export class TerminalEditor extends EditorPane {
switch (action.id) {
case TerminalCommandId.CreateWithProfileButton: {
const actions = getTerminalActionBarArgs(TerminalLocation.Editor, this._terminalService.availableProfiles, this._getDefaultProfileName(), this._terminalContributionService.terminalProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
const button = this._instantiationService.createInstance(DropdownWithPrimaryActionViewItem, actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService);
const button = this._instantiationService.createInstance(DropdownWithPrimaryActionViewItem, actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, {});
return button;
}
}

View file

@ -206,7 +206,7 @@ export class TerminalViewPane extends ViewPane {
const actions = getTerminalActionBarArgs(TerminalLocation.TerminalView, this._terminalService.availableProfiles, this._getDefaultProfileName(), this._terminalContributionService.terminalProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
this._tabButtons = new DropdownWithPrimaryActionViewItem(actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, this._keybindingService, this._notificationService, this._contextKeyService);
this._tabButtons = new DropdownWithPrimaryActionViewItem(actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, {}, this._keybindingService, this._notificationService, this._contextKeyService);
this._updateTabActionBar(this._terminalService.availableProfiles);
return this._tabButtons;
}

View file

@ -363,6 +363,7 @@ export class TestingExplorerView extends ViewPane {
primaryAction, dropdownAction, dropdownActions,
'',
this.contextMenuService,
{}
);
}