Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert hiding some notebook toolbars #161136

Merged
merged 6 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts
Expand Up @@ -31,14 +31,16 @@ import { ExecutionStateCellStatusBarContrib, TimerCellStatusBarContrib } from 'v
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { MenuId } from 'vs/platform/actions/common/actions';
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { InteractiveWindowSetting, INTERACTIVE_INPUT_CURSOR_BOUNDARY } from 'vs/workbench/contrib/interactive/browser/interactiveCommon';
import { ComplexNotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookEditorModel';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IAction } from 'vs/base/common/actions';
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer';
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
Expand All @@ -56,7 +58,6 @@ import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookCo
import { ICursorPositionChangedEvent } from 'vs/editor/common/cursorEvents';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { isEqual } from 'vs/base/common/resources';
import { MenuWorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';

const DECORATION_KEY = 'interactiveInputDecoration';
const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'InteractiveEditorViewState';
Expand Down Expand Up @@ -93,6 +94,8 @@ export class InteractiveEditor extends EditorPane {
#contextKeyService: IContextKeyService;
#notebookKernelService: INotebookKernelService;
#keybindingService: IKeybindingService;
#menuService: IMenuService;
#contextMenuService: IContextMenuService;
#editorGroupService: IEditorGroupsService;
#notebookExecutionStateService: INotebookExecutionStateService;
#extensionService: IExtensionService;
Expand Down Expand Up @@ -120,6 +123,8 @@ export class InteractiveEditor extends EditorPane {
@ILanguageService languageService: ILanguageService,
@IKeybindingService keybindingService: IKeybindingService,
@IConfigurationService private configurationService: IConfigurationService,
@IMenuService menuService: IMenuService,
@IContextMenuService contextMenuService: IContextMenuService,
@IEditorGroupsService editorGroupService: IEditorGroupsService,
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
Expand All @@ -137,6 +142,8 @@ export class InteractiveEditor extends EditorPane {
this.#notebookKernelService = notebookKernelService;
this.#languageService = languageService;
this.#keybindingService = keybindingService;
this.#menuService = menuService;
this.#contextMenuService = contextMenuService;
this.#editorGroupService = editorGroupService;
this.#notebookExecutionStateService = notebookExecutionStateService;
this.#extensionService = extensionService;
Expand Down Expand Up @@ -179,12 +186,21 @@ export class InteractiveEditor extends EditorPane {
}

#setupRunButtonToolbar(runButtonContainer: HTMLElement) {
this.#runbuttonToolbar = this._register(this.#instantiationService.createInstance(MenuWorkbenchToolBar, runButtonContainer, MenuId.InteractiveInputExecute, {
const menu = this._register(this.#menuService.createMenu(MenuId.InteractiveInputExecute, this.#contextKeyService));
this.#runbuttonToolbar = this._register(new ToolBar(runButtonContainer, this.#contextMenuService, {
getKeyBinding: action => this.#keybindingService.lookupKeybinding(action.id),
actionViewItemProvider: action => {
return createActionViewItem(this.#instantiationService, action);
},
renderDropdownAsChildElement: true
}));

const primary: IAction[] = [];
const secondary: IAction[] = [];
const result = { primary, secondary };

createAndFillInActionBarActions(menu, { shouldForwardArgs: true }, result);
this.#runbuttonToolbar.setActions([...primary, ...secondary]);
}

#createLayoutStyles(): void {
Expand Down
Expand Up @@ -13,25 +13,31 @@ import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { createActionViewItem, createAndFillInActionBarActions, MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenu, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
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 { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotebookCellActionContext } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CodiconActionViewItem } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellActionView';
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
import { registerStickyScroll } from 'vs/workbench/contrib/notebook/browser/view/cellParts/stickyScroll';
import { HiddenItemStrategy, MenuWorkbenchToolBar, WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';

export class BetweenCellToolbar extends CellPart {
private _betweenCellToolbar!: MenuWorkbenchToolBar;
private _betweenCellToolbar!: ToolBar;

constructor(
private readonly _notebookEditor: INotebookEditorDelegate,
_titleToolbarContainer: HTMLElement,
private readonly _bottomCellToolbarContainer: HTMLElement,
@IInstantiationService instantiationService: IInstantiationService,
@IContextMenuService contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService,
@IMenuService menuService: IMenuService
) {
super();
this._betweenCellToolbar = this._register(instantiationService.createInstance(MenuWorkbenchToolBar, this._bottomCellToolbarContainer, this._notebookEditor.creationOptions.menuIds.cellInsertToolbar, {

this._betweenCellToolbar = this._register(new ToolBar(this._bottomCellToolbarContainer, contextMenuService, {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
if (this._notebookEditor.notebookOptions.getLayoutConfiguration().insertToolbarAlignment === 'center') {
Expand All @@ -42,14 +48,22 @@ export class BetweenCellToolbar extends CellPart {
}

return undefined;
},
toolbarOptions: {
primaryGroup: g => /^inline/.test(g),
},
menuOptions: {
shouldForwardArgs: true
}
}));

const menu = this._register(menuService.createMenu(this._notebookEditor.creationOptions.menuIds.cellInsertToolbar, contextKeyService));
const updateActions = () => {
const actions = getCellToolbarActions(menu);
this._betweenCellToolbar.setActions(actions.primary, actions.secondary);
};

this._register(menu.onDidChange(() => updateActions()));
this._register(this._notebookEditor.notebookOptions.onDidChangeOptions((e) => {
if (e.insertToolbarAlignment) {
updateActions();
}
}));
updateActions();
}

updateContext(context: INotebookCellActionContext) {
Expand Down Expand Up @@ -77,9 +91,9 @@ export interface ICssClassDelegate {
}

export class CellTitleToolbarPart extends CellPart {
private _toolbar: WorkbenchToolBar;
private _toolbar: ToolBar;
private _titleMenu: IMenu;
private _deleteToolbar: WorkbenchToolBar;
private _deleteToolbar: ToolBar;
private _deleteMenu: IMenu;
private readonly _onDidUpdateActions: Emitter<void> = this._register(new Emitter<void>());
readonly onDidUpdateActions: Event<void> = this._onDidUpdateActions.event;
Expand All @@ -100,10 +114,15 @@ export class CellTitleToolbarPart extends CellPart {
) {
super();

this._toolbar = instantiationService.invokeFunction(accessor => createToolbar(accessor, toolbarContainer));
this._toolbar = instantiationService.createInstance(WorkbenchToolBar, toolbarContainer, {
actionViewItemProvider: action => {
return createActionViewItem(instantiationService, action);
},
renderDropdownAsChildElement: true
});
this._titleMenu = this._register(menuService.createMenu(toolbarId, contextKeyService));

this._deleteToolbar = this._register(instantiationService.invokeFunction(accessor => createToolbar(accessor, toolbarContainer, 'cell-delete-toolbar', HiddenItemStrategy.Ignore)));
this._deleteToolbar = this._register(instantiationService.invokeFunction(accessor => createDeleteToolbar(accessor, toolbarContainer, 'cell-delete-toolbar')));
this._deleteMenu = this._register(menuService.createMenu(deleteToolbarId, contextKeyService));
if (!this._notebookEditor.creationOptions.isReadOnly) {
const deleteActions = getCellToolbarActions(this._deleteMenu);
Expand Down Expand Up @@ -189,15 +208,16 @@ function getCellToolbarActions(menu: IMenu): { primary: IAction[]; secondary: IA
return result;
}

function createToolbar(accessor: ServicesAccessor, container: HTMLElement, elementClass?: string, hiddenItemStrategy?: HiddenItemStrategy): WorkbenchToolBar {
function createDeleteToolbar(accessor: ServicesAccessor, container: HTMLElement, elementClass?: string): ToolBar {
const contextMenuService = accessor.get(IContextMenuService);
const keybindingService = accessor.get(IKeybindingService);
const instantiationService = accessor.get(IInstantiationService);

const toolbar = instantiationService.createInstance(WorkbenchToolBar, container, {
const toolbar = new ToolBar(container, contextMenuService, {
getKeyBinding: action => keybindingService.lookupKeybinding(action.id),
actionViewItemProvider: action => {
return createActionViewItem(instantiationService, action);
},
renderDropdownAsChildElement: true,
hiddenItemStrategy
renderDropdownAsChildElement: true
});

if (elementClass) {
Expand Down
Expand Up @@ -3,14 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { Action, IAction } from 'vs/base/common/actions';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { MarshalledId } from 'vs/base/common/marshallingIds';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { localize } from 'vs/nls';
import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem';
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { HiddenItemStrategy, WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
import { IMenu, IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
Expand All @@ -24,7 +24,7 @@ import { registerStickyScroll } from 'vs/workbench/contrib/notebook/browser/view
import { NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';

export class RunToolbar extends CellPart {
private toolbar!: WorkbenchToolBar;
private toolbar!: ToolBar;

private primaryMenu: IMenu;
private secondaryMenu: IMenu;
Expand Down Expand Up @@ -82,8 +82,7 @@ export class RunToolbar extends CellPart {

const keybindingProvider = (action: IAction) => this.keybindingService.lookupKeybinding(action.id, executionContextKeyService);
const executionContextKeyService = this._register(getCodeCellExecutionContextKeyService(contextKeyService));
this.toolbar = this._register(this.instantiationService.createInstance(WorkbenchToolBar, container, {
hiddenItemStrategy: HiddenItemStrategy.Ignore,
this.toolbar = this._register(new ToolBar(container, this.contextMenuService, {
getKeyBinding: keybindingProvider,
actionViewItemProvider: _action => {
actionViewItemDisposables.clear();
Expand Down