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

joh/notebook toolbar #161098

Merged
merged 10 commits into from
Sep 16, 2022
16 changes: 13 additions & 3 deletions src/vs/platform/actions/browser/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import { addDisposableListener } from 'vs/base/browser/dom';
import { IToolBarOptions, ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { IAction, Separator, SubmenuAction, WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
import { IAction, Separator, SubmenuAction, toAction, WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
import { coalesceInPlace } from 'vs/base/common/arrays';
import { BugIndicatingError } from 'vs/base/common/errors';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { createAndFillInActionBarActions, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenuActionOptions, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
Expand Down Expand Up @@ -90,7 +91,7 @@ export class WorkbenchToolBar extends ToolBar {
}
}

override setActions(_primary: readonly IAction[], _secondary: readonly IAction[]): void {
override setActions(_primary: readonly IAction[], _secondary: readonly IAction[] = []): void {

this._sessionDisposables.clear();
const primary = _primary.slice();
Expand Down Expand Up @@ -141,9 +142,18 @@ export class WorkbenchToolBar extends ToolBar {
let actions = toggleActions;

// add "hide foo" actions
let hideAction: IAction;
if (action instanceof MenuItemAction && action.hideActions) {
actions = [action.hideActions.hide, new Separator(), ...toggleActions];
hideAction = action.hideActions.hide;
} else {
hideAction = toAction({
id: 'label',
label: localize('hide', "Hide"),
enabled: false,
run() { }
});
}
actions = [hideAction, new Separator(), ...toggleActions];

// add context menu actions (iff appicable)
if (this._options?.contextMenu) {
Expand Down
24 changes: 4 additions & 20 deletions src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ 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 { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { 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 { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IAction } from 'vs/base/common/actions';
import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
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 @@ -58,6 +56,7 @@ 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 @@ -94,8 +93,6 @@ 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 @@ -123,8 +120,6 @@ 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 @@ -142,8 +137,6 @@ 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 @@ -186,21 +179,12 @@ export class InteractiveEditor extends EditorPane {
}

#setupRunButtonToolbar(runButtonContainer: HTMLElement) {
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),
this.#runbuttonToolbar = this._register(this.#instantiationService.createInstance(MenuWorkbenchToolBar, runButtonContainer, MenuId.InteractiveInputExecute, {
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
15 changes: 9 additions & 6 deletions src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';

const fixedEditorPadding = {
top: 12,
Expand Down Expand Up @@ -104,7 +106,7 @@ class PropertyHeader extends Disposable {
protected _foldingIndicator!: HTMLElement;
protected _statusSpan!: HTMLElement;
protected _description!: HTMLElement;
protected _toolbar!: ToolBar;
protected _toolbar!: WorkbenchToolBar;
protected _menu!: IMenu;
protected _propertyExpanded?: IContextKey<boolean>;

Expand All @@ -128,6 +130,7 @@ class PropertyHeader extends Disposable {
@IMenuService readonly menuService: IMenuService,
@IContextKeyService readonly contextKeyService: IContextKeyService,
@IThemeService readonly themeService: IThemeService,
@ITelemetryService readonly telemetryService: ITelemetryService,
) {
super();
}
Expand Down Expand Up @@ -156,7 +159,7 @@ class PropertyHeader extends Disposable {
}

const cellToolbarContainer = DOM.append(this.propertyHeaderContainer, DOM.$('div.property-toolbar'));
this._toolbar = new ToolBar(cellToolbarContainer, this.contextMenuService, {
this._toolbar = new WorkbenchToolBar(cellToolbarContainer, {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
const item = new CodiconActionViewItem(action, undefined, this.keybindingService, this.notificationService, this.contextKeyService, this.themeService, this.contextMenuService);
Expand All @@ -165,7 +168,7 @@ class PropertyHeader extends Disposable {

return undefined;
}
});
}, this.menuService, this.contextKeyService, this.contextMenuService, this.keybindingService, this.telemetryService);
this._register(this._toolbar);
this._toolbar.context = {
cell: this.cell
Expand Down Expand Up @@ -1567,11 +1570,11 @@ export class ModifiedElement extends AbstractElementRenderer {
}
}));

this._menu = this.menuService.createMenu(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService);
this._register(this._menu);
const menu = this.menuService.createMenu(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService);
const actions: IAction[] = [];
createAndFillInActionBarActions(this._menu, { shouldForwardArgs: true }, actions);
createAndFillInActionBarActions(menu, { shouldForwardArgs: true }, actions);
this._toolbar.setActions(actions);
menu.dispose();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to be a local because I don't see any other references and disposing a menu quickly is better - since it stops listening on CKS events

}

private async _initializeSourceDiffEditor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
import { NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';

export enum DiffSide {
Original = 0,
Expand Down Expand Up @@ -83,7 +83,7 @@ export interface CellDiffSideBySideRenderTemplate extends CellDiffCommonRenderTe
readonly sourceEditor: DiffEditorWidget;
readonly editorContainer: HTMLElement;
readonly inputToolbarContainer: HTMLElement;
readonly toolbar: ToolBar;
readonly toolbar: WorkbenchToolBar;
readonly metadataHeaderContainer: HTMLElement;
readonly metadataInfoContainer: HTMLElement;
readonly outputHeaderContainer: HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { isMacintosh } from 'vs/base/common/platform';
import { DeletedElement, fixedDiffEditorOptions, fixedEditorOptions, getOptimizedNestedCodeEditorWidgetOptions, InsertElement, ModifiedElement } from 'vs/workbench/contrib/notebook/browser/diff/diffComponents';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand All @@ -29,6 +28,7 @@ import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { PixelRatio } from 'vs/base/browser/browser';
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';

export class NotebookCellTextDiffListDelegate implements IListVirtualDelegate<DiffElementViewModelBase> {
private readonly lineHeight: number;
Expand Down Expand Up @@ -184,7 +184,7 @@ export class CellDiffSideBySideRenderer implements IListRenderer<SideBySideDiffE

const inputToolbarContainer = DOM.append(sourceContainer, DOM.$('.editor-input-toolbar-container'));
const cellToolbarContainer = DOM.append(inputToolbarContainer, DOM.$('div.property-toolbar'));
const toolbar = new ToolBar(cellToolbarContainer, this.contextMenuService, {
const toolbar = this.instantiationService.createInstance(WorkbenchToolBar, cellToolbarContainer, {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
const item = new CodiconActionViewItem(action, undefined, this.keybindingService, this.notificationService, this.contextKeyService, this.themeService, this.contextMenuService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
import * as DOM from 'vs/base/browser/dom';
import { FastDomNode } from 'vs/base/browser/fastDomNode';
import { renderMarkdown } from 'vs/base/browser/markdownRenderer';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { Action, IAction } from 'vs/base/common/actions';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { MarshalledId } from 'vs/base/common/marshallingIds';
import * as nls from 'vs/nls';
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
import { IMenuService, MenuId } 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 { IOpenerService } from 'vs/platform/opener/common/opener';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
Expand Down Expand Up @@ -75,11 +73,10 @@ export class CellOutputElement extends Disposable {
readonly output: ICellOutputViewModel,
@INotebookService private readonly notebookService: INotebookService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IContextKeyService parentContextKeyService: IContextKeyService,
@IMenuService private readonly menuService: IMenuService,
@IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService
@IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
) {
super();

Expand Down Expand Up @@ -268,8 +265,7 @@ export class CellOutputElement extends Disposable {

outputItemDiv.appendChild(mimeTypePicker);

const toolbar = this._renderDisposableStore.add(new ToolBar(mimeTypePicker, this.contextMenuService, {
getKeyBinding: action => this.keybindingService.lookupKeybinding(action.id),
const toolbar = this._renderDisposableStore.add(this.instantiationService.createInstance(WorkbenchToolBar, mimeTypePicker, {
renderDropdownAsChildElement: false
}));
toolbar.context = <INotebookCellActionContext>{
Expand Down