Skip to content

Commit

Permalink
Enable contributing to cell execute dropdown
Browse files Browse the repository at this point in the history
Towards #130524
  • Loading branch information
roblourens committed Aug 10, 2021
1 parent 7a034ba commit 1c445fe
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/api/common/menusExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -417,15 +417,17 @@ registerAction2(class ExecuteAboveCells extends NotebookMultiCellAction<INoteboo
menu: [
{
id: MenuId.NotebookCellExecute,
when: executeCellCondition
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, true))
},
{
id: MenuId.NotebookCellTitle,
order: CellToolbarOrder.ExecuteAboveCells,
group: CELL_TITLE_CELL_GROUP_ID,
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals('config.notebook.consolidatedRunButton', false))
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, false))
}
],
icon: icons.executeAboveIcon
Expand Down Expand Up @@ -461,15 +463,17 @@ registerAction2(class ExecuteCellAndBelow extends NotebookMultiCellAction<INoteb
menu: [
{
id: MenuId.NotebookCellExecute,
when: executeCellCondition,
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, true))
},
{
id: MenuId.NotebookCellTitle,
order: CellToolbarOrder.ExecuteCellAndBelow,
group: CELL_TITLE_CELL_GROUP_ID,
when: ContextKeyExpr.and(
executeCellCondition,
ContextKeyExpr.equals('config.notebook.consolidatedRunButton', false))
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, false))
}
],
icon: icons.executeBelowIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export class TestingExplorerView extends ViewPane {
primaryAction, dropdownAction, dropdownActions,
'',
this.contextMenuService,
{}
);
}

Expand Down

0 comments on commit 1c445fe

Please sign in to comment.