Skip to content

Commit 107f6ca

Browse files
authored
Merge pull request microsoft#161098 from microsoft/joh/notebook-toolbar
joh/notebook toolbar
2 parents 1589496 + 7c5634e commit 107f6ca

File tree

8 files changed

+44
-72
lines changed

8 files changed

+44
-72
lines changed

src/vs/platform/actions/browser/toolbar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class WorkbenchToolBar extends ToolBar {
9191
}
9292
}
9393

94-
override setActions(_primary: readonly IAction[], _secondary: readonly IAction[]): void {
94+
override setActions(_primary: readonly IAction[], _secondary: readonly IAction[] = []): void {
9595

9696
this._sessionDisposables.clear();
9797
const primary = _primary.slice();

src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ import { ExecutionStateCellStatusBarContrib, TimerCellStatusBarContrib } from 'v
3131
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
3232
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
3333
import { ILanguageService } from 'vs/editor/common/languages/language';
34-
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
34+
import { MenuId } from 'vs/platform/actions/common/actions';
3535
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3636
import { InteractiveWindowSetting, INTERACTIVE_INPUT_CURSOR_BOUNDARY } from 'vs/workbench/contrib/interactive/browser/interactiveCommon';
3737
import { ComplexNotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookEditorModel';
3838
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3939
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
4040
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
41-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
42-
import { createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
43-
import { IAction } from 'vs/base/common/actions';
41+
import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
4442
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
4543
import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer';
4644
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
@@ -58,6 +56,7 @@ import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookCo
5856
import { ICursorPositionChangedEvent } from 'vs/editor/common/cursorEvents';
5957
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
6058
import { isEqual } from 'vs/base/common/resources';
59+
import { MenuWorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
6160

6261
const DECORATION_KEY = 'interactiveInputDecoration';
6362
const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'InteractiveEditorViewState';
@@ -94,8 +93,6 @@ export class InteractiveEditor extends EditorPane {
9493
#contextKeyService: IContextKeyService;
9594
#notebookKernelService: INotebookKernelService;
9695
#keybindingService: IKeybindingService;
97-
#menuService: IMenuService;
98-
#contextMenuService: IContextMenuService;
9996
#editorGroupService: IEditorGroupsService;
10097
#notebookExecutionStateService: INotebookExecutionStateService;
10198
#extensionService: IExtensionService;
@@ -123,8 +120,6 @@ export class InteractiveEditor extends EditorPane {
123120
@ILanguageService languageService: ILanguageService,
124121
@IKeybindingService keybindingService: IKeybindingService,
125122
@IConfigurationService private configurationService: IConfigurationService,
126-
@IMenuService menuService: IMenuService,
127-
@IContextMenuService contextMenuService: IContextMenuService,
128123
@IEditorGroupsService editorGroupService: IEditorGroupsService,
129124
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
130125
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
@@ -142,8 +137,6 @@ export class InteractiveEditor extends EditorPane {
142137
this.#notebookKernelService = notebookKernelService;
143138
this.#languageService = languageService;
144139
this.#keybindingService = keybindingService;
145-
this.#menuService = menuService;
146-
this.#contextMenuService = contextMenuService;
147140
this.#editorGroupService = editorGroupService;
148141
this.#notebookExecutionStateService = notebookExecutionStateService;
149142
this.#extensionService = extensionService;
@@ -186,21 +179,12 @@ export class InteractiveEditor extends EditorPane {
186179
}
187180

188181
#setupRunButtonToolbar(runButtonContainer: HTMLElement) {
189-
const menu = this._register(this.#menuService.createMenu(MenuId.InteractiveInputExecute, this.#contextKeyService));
190-
this.#runbuttonToolbar = this._register(new ToolBar(runButtonContainer, this.#contextMenuService, {
191-
getKeyBinding: action => this.#keybindingService.lookupKeybinding(action.id),
182+
this.#runbuttonToolbar = this._register(this.#instantiationService.createInstance(MenuWorkbenchToolBar, runButtonContainer, MenuId.InteractiveInputExecute, {
192183
actionViewItemProvider: action => {
193184
return createActionViewItem(this.#instantiationService, action);
194185
},
195186
renderDropdownAsChildElement: true
196187
}));
197-
198-
const primary: IAction[] = [];
199-
const secondary: IAction[] = [];
200-
const result = { primary, secondary };
201-
202-
createAndFillInActionBarActions(menu, { shouldForwardArgs: true }, result);
203-
this.#runbuttonToolbar.setActions([...primary, ...secondary]);
204188
}
205189

206190
#createLayoutStyles(): void {

src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService';
4040
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
4141
import { IDiffEditorConstructionOptions } from 'vs/editor/browser/editorBrowser';
4242
import { IThemeService } from 'vs/platform/theme/common/themeService';
43+
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
44+
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4345

4446
const fixedEditorPadding = {
4547
top: 12,
@@ -104,7 +106,7 @@ class PropertyHeader extends Disposable {
104106
protected _foldingIndicator!: HTMLElement;
105107
protected _statusSpan!: HTMLElement;
106108
protected _description!: HTMLElement;
107-
protected _toolbar!: ToolBar;
109+
protected _toolbar!: WorkbenchToolBar;
108110
protected _menu!: IMenu;
109111
protected _propertyExpanded?: IContextKey<boolean>;
110112

@@ -128,6 +130,7 @@ class PropertyHeader extends Disposable {
128130
@IMenuService readonly menuService: IMenuService,
129131
@IContextKeyService readonly contextKeyService: IContextKeyService,
130132
@IThemeService readonly themeService: IThemeService,
133+
@ITelemetryService readonly telemetryService: ITelemetryService,
131134
) {
132135
super();
133136
}
@@ -156,7 +159,7 @@ class PropertyHeader extends Disposable {
156159
}
157160

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

166169
return undefined;
167170
}
168-
});
171+
}, this.menuService, this.contextKeyService, this.contextMenuService, this.keybindingService, this.telemetryService);
169172
this._register(this._toolbar);
170173
this._toolbar.context = {
171174
cell: this.cell
@@ -1567,11 +1570,11 @@ export class ModifiedElement extends AbstractElementRenderer {
15671570
}
15681571
}));
15691572

1570-
this._menu = this.menuService.createMenu(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService);
1571-
this._register(this._menu);
1573+
const menu = this.menuService.createMenu(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService);
15721574
const actions: IAction[] = [];
1573-
createAndFillInActionBarActions(this._menu, { shouldForwardArgs: true }, actions);
1575+
createAndFillInActionBarActions(menu, { shouldForwardArgs: true }, actions);
15741576
this._toolbar.setActions(actions);
1577+
menu.dispose();
15751578
}
15761579

15771580
private async _initializeSourceDiffEditor() {

src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
1111
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
1212
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
1313
import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
14-
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
1514
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
1615
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
1716
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
1817
import { NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
18+
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
1919

2020
export enum DiffSide {
2121
Original = 0,
@@ -83,7 +83,7 @@ export interface CellDiffSideBySideRenderTemplate extends CellDiffCommonRenderTe
8383
readonly sourceEditor: DiffEditorWidget;
8484
readonly editorContainer: HTMLElement;
8585
readonly inputToolbarContainer: HTMLElement;
86-
readonly toolbar: ToolBar;
86+
readonly toolbar: WorkbenchToolBar;
8787
readonly metadataHeaderContainer: HTMLElement;
8888
readonly metadataInfoContainer: HTMLElement;
8989
readonly outputHeaderContainer: HTMLElement;

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { isMacintosh } from 'vs/base/common/platform';
2020
import { DeletedElement, fixedDiffEditorOptions, fixedEditorOptions, getOptimizedNestedCodeEditorWidgetOptions, InsertElement, ModifiedElement } from 'vs/workbench/contrib/notebook/browser/diff/diffComponents';
2121
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
2222
import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
23-
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
2423
import { IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
2524
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
2625
import { INotificationService } from 'vs/platform/notification/common/notification';
@@ -29,6 +28,7 @@ import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
2928
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
3029
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
3130
import { PixelRatio } from 'vs/base/browser/browser';
31+
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
3232

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

185185
const inputToolbarContainer = DOM.append(sourceContainer, DOM.$('.editor-input-toolbar-container'));
186186
const cellToolbarContainer = DOM.append(inputToolbarContainer, DOM.$('div.property-toolbar'));
187-
const toolbar = new ToolBar(cellToolbarContainer, this.contextMenuService, {
187+
const toolbar = this.instantiationService.createInstance(WorkbenchToolBar, cellToolbarContainer, {
188188
actionViewItemProvider: action => {
189189
if (action instanceof MenuItemAction) {
190190
const item = new CodiconActionViewItem(action, undefined, this.keybindingService, this.notificationService, this.contextKeyService, this.themeService, this.contextMenuService);

src/vs/workbench/contrib/notebook/browser/view/cellParts/cellOutput.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
import * as DOM from 'vs/base/browser/dom';
77
import { FastDomNode } from 'vs/base/browser/fastDomNode';
88
import { renderMarkdown } from 'vs/base/browser/markdownRenderer';
9-
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
109
import { Action, IAction } from 'vs/base/common/actions';
1110
import { IMarkdownString } from 'vs/base/common/htmlContent';
1211
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
1312
import { MarshalledId } from 'vs/base/common/marshallingIds';
1413
import * as nls from 'vs/nls';
1514
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
15+
import { WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
1616
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
1717
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
18-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1918
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
20-
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2119
import { IOpenerService } from 'vs/platform/opener/common/opener';
2220
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
2321
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
@@ -75,11 +73,10 @@ export class CellOutputElement extends Disposable {
7573
readonly output: ICellOutputViewModel,
7674
@INotebookService private readonly notebookService: INotebookService,
7775
@IQuickInputService private readonly quickInputService: IQuickInputService,
78-
@IContextMenuService private readonly contextMenuService: IContextMenuService,
79-
@IKeybindingService private readonly keybindingService: IKeybindingService,
8076
@IContextKeyService parentContextKeyService: IContextKeyService,
8177
@IMenuService private readonly menuService: IMenuService,
82-
@IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService
78+
@IPaneCompositePartService private readonly paneCompositeService: IPaneCompositePartService,
79+
@IInstantiationService private readonly instantiationService: IInstantiationService,
8380
) {
8481
super();
8582

@@ -268,8 +265,7 @@ export class CellOutputElement extends Disposable {
268265

269266
outputItemDiv.appendChild(mimeTypePicker);
270267

271-
const toolbar = this._renderDisposableStore.add(new ToolBar(mimeTypePicker, this.contextMenuService, {
272-
getKeyBinding: action => this.keybindingService.lookupKeybinding(action.id),
268+
const toolbar = this._renderDisposableStore.add(this.instantiationService.createInstance(WorkbenchToolBar, mimeTypePicker, {
273269
renderDropdownAsChildElement: false
274270
}));
275271
toolbar.context = <INotebookCellActionContext>{

src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,26 @@ import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
1313
import { createActionViewItem, createAndFillInActionBarActions, MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
1414
import { IMenu, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
1515
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
16-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1716
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
18-
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1917
import { INotebookCellActionContext } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
2018
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
2119
import { CodiconActionViewItem } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellActionView';
2220
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart';
2321
import { registerStickyScroll } from 'vs/workbench/contrib/notebook/browser/view/cellParts/stickyScroll';
22+
import { HiddenItemStrategy, MenuWorkbenchToolBar, WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';
2423

2524
export class BetweenCellToolbar extends CellPart {
26-
private _betweenCellToolbar!: ToolBar;
25+
private _betweenCellToolbar!: MenuWorkbenchToolBar;
2726

2827
constructor(
2928
private readonly _notebookEditor: INotebookEditorDelegate,
3029
_titleToolbarContainer: HTMLElement,
3130
private readonly _bottomCellToolbarContainer: HTMLElement,
3231
@IInstantiationService instantiationService: IInstantiationService,
33-
@IContextMenuService contextMenuService: IContextMenuService,
34-
@IContextKeyService contextKeyService: IContextKeyService,
35-
@IMenuService menuService: IMenuService
3632
) {
3733
super();
3834

39-
this._betweenCellToolbar = this._register(new ToolBar(this._bottomCellToolbarContainer, contextMenuService, {
35+
this._betweenCellToolbar = this._register(instantiationService.createInstance(MenuWorkbenchToolBar, this._bottomCellToolbarContainer, this._notebookEditor.creationOptions.menuIds.cellInsertToolbar, {
4036
actionViewItemProvider: action => {
4137
if (action instanceof MenuItemAction) {
4238
if (this._notebookEditor.notebookOptions.getLayoutConfiguration().insertToolbarAlignment === 'center') {
@@ -47,22 +43,14 @@ export class BetweenCellToolbar extends CellPart {
4743
}
4844

4945
return undefined;
46+
},
47+
toolbarOptions: {
48+
primaryGroup: g => /^inline/.test(g),
49+
},
50+
menuOptions: {
51+
shouldForwardArgs: true
5052
}
5153
}));
52-
53-
const menu = this._register(menuService.createMenu(this._notebookEditor.creationOptions.menuIds.cellInsertToolbar, contextKeyService));
54-
const updateActions = () => {
55-
const actions = getCellToolbarActions(menu);
56-
this._betweenCellToolbar.setActions(actions.primary, actions.secondary);
57-
};
58-
59-
this._register(menu.onDidChange(() => updateActions()));
60-
this._register(this._notebookEditor.notebookOptions.onDidChangeOptions((e) => {
61-
if (e.insertToolbarAlignment) {
62-
updateActions();
63-
}
64-
}));
65-
updateActions();
6654
}
6755

6856
updateContext(context: INotebookCellActionContext) {
@@ -90,9 +78,9 @@ export interface ICssClassDelegate {
9078
}
9179

9280
export class CellTitleToolbarPart extends CellPart {
93-
private _toolbar: ToolBar;
81+
private _toolbar: WorkbenchToolBar;
9482
private _titleMenu: IMenu;
95-
private _deleteToolbar: ToolBar;
83+
private _deleteToolbar: WorkbenchToolBar;
9684
private _deleteMenu: IMenu;
9785
private readonly _onDidUpdateActions: Emitter<void> = this._register(new Emitter<void>());
9886
readonly onDidUpdateActions: Event<void> = this._onDidUpdateActions.event;
@@ -116,7 +104,7 @@ export class CellTitleToolbarPart extends CellPart {
116104
this._toolbar = instantiationService.invokeFunction(accessor => createToolbar(accessor, toolbarContainer));
117105
this._titleMenu = this._register(menuService.createMenu(toolbarId, contextKeyService));
118106

119-
this._deleteToolbar = this._register(instantiationService.invokeFunction(accessor => createToolbar(accessor, toolbarContainer, 'cell-delete-toolbar')));
107+
this._deleteToolbar = this._register(instantiationService.invokeFunction(accessor => createToolbar(accessor, toolbarContainer, 'cell-delete-toolbar', HiddenItemStrategy.Ignore)));
120108
this._deleteMenu = this._register(menuService.createMenu(deleteToolbarId, contextKeyService));
121109
if (!this._notebookEditor.creationOptions.isReadOnly) {
122110
const deleteActions = getCellToolbarActions(this._deleteMenu);
@@ -202,16 +190,15 @@ function getCellToolbarActions(menu: IMenu): { primary: IAction[]; secondary: IA
202190
return result;
203191
}
204192

205-
function createToolbar(accessor: ServicesAccessor, container: HTMLElement, elementClass?: string): ToolBar {
206-
const contextMenuService = accessor.get(IContextMenuService);
207-
const keybindingService = accessor.get(IKeybindingService);
193+
function createToolbar(accessor: ServicesAccessor, container: HTMLElement, elementClass?: string, hiddenItemStrategy?: HiddenItemStrategy): WorkbenchToolBar {
208194
const instantiationService = accessor.get(IInstantiationService);
209-
const toolbar = new ToolBar(container, contextMenuService, {
210-
getKeyBinding: action => keybindingService.lookupKeybinding(action.id),
195+
196+
const toolbar = instantiationService.createInstance(WorkbenchToolBar, container, {
211197
actionViewItemProvider: action => {
212198
return createActionViewItem(instantiationService, action);
213199
},
214-
renderDropdownAsChildElement: true
200+
renderDropdownAsChildElement: true,
201+
hiddenItemStrategy
215202
});
216203

217204
if (elementClass) {

0 commit comments

Comments
 (0)