Skip to content

Commit 90c3e49

Browse files
authored
Drop-down buttons to also go to next (microsoft#226619)
1 parent eaf8451 commit 90c3e49

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

src/vs/workbench/contrib/comments/browser/commentFormActions.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Button } from 'vs/base/browser/ui/button/button';
7-
import { IAction } from 'vs/base/common/actions';
6+
import { Button, ButtonWithDropdown } from 'vs/base/browser/ui/button/button';
7+
import { ActionRunner, IAction } from 'vs/base/common/actions';
88
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
99
import { IMenu } from 'vs/platform/actions/common/actions';
1010
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
11+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1112
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1213
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles';
1314
import { CommentCommandId } from 'vs/workbench/contrib/comments/common/commentCommandIds';
@@ -20,6 +21,7 @@ export class CommentFormActions implements IDisposable {
2021
constructor(
2122
private readonly keybindingService: IKeybindingService,
2223
private readonly contextKeyService: IContextKeyService,
24+
private readonly contextMenuService: IContextMenuService,
2325
private container: HTMLElement,
2426
private actionHandler: (action: IAction) => void,
2527
private readonly maxActions?: number
@@ -34,16 +36,30 @@ export class CommentFormActions implements IDisposable {
3436
const groups = menu.getActions({ shouldForwardArgs: true });
3537
let isPrimary: boolean = !hasOnlySecondaryActions;
3638
for (const group of groups) {
37-
const [, actions] = group;
39+
const [groupId, actions] = group;
3840

3941
this._actions = actions;
40-
for (const action of actions) {
42+
for (const current of groupId === 'inline' ? actions : [actions]) {
43+
const [action, dropDownActions] = Array.isArray(current) ? [current[0], current.slice(1)] : [current, []];
4144
let keybinding = this.keybindingService.lookupKeybinding(action.id, this.contextKeyService)?.getLabel();
4245
if (!keybinding && isPrimary) {
4346
keybinding = this.keybindingService.lookupKeybinding(CommentCommandId.Submit, this.contextKeyService)?.getLabel();
4447
}
4548
const title = keybinding ? `${action.label} (${keybinding})` : action.label;
46-
const button = new Button(this.container, { secondary: !isPrimary, title, ...defaultButtonStyles });
49+
const actionHandler = this.actionHandler;
50+
const button = dropDownActions.length ? new ButtonWithDropdown(this.container, {
51+
contextMenuProvider: this.contextMenuService,
52+
actions: dropDownActions,
53+
actionRunner: new class extends ActionRunner {
54+
protected override async runAction(action: IAction, context?: unknown): Promise<void> {
55+
return actionHandler(action);
56+
}
57+
},
58+
secondary: !isPrimary,
59+
title,
60+
addPrimaryActionToDropdown: false,
61+
...defaultButtonStyles
62+
}) : new Button(this.container, { secondary: !isPrimary, title, ...defaultButtonStyles });
4763

4864
isPrimary = false;
4965
this._buttonElements.push(button.element);

src/vs/workbench/contrib/comments/browser/commentNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
633633
this._commentFormActions?.setActions(menu);
634634
}));
635635

636-
this._commentFormActions = new CommentFormActions(this.keybindingService, this._contextKeyService, container, (action: IAction): void => {
636+
this._commentFormActions = new CommentFormActions(this.keybindingService, this._contextKeyService, this.contextMenuService, container, (action: IAction): void => {
637637
const text = this._commentEditor!.getValue();
638638

639639
action.run({
@@ -659,7 +659,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
659659
this._commentEditorActions?.setActions(menu);
660660
}));
661661

662-
this._commentEditorActions = new CommentFormActions(this.keybindingService, this._contextKeyService, container, (action: IAction): void => {
662+
this._commentEditorActions = new CommentFormActions(this.keybindingService, this._contextKeyService, this.contextMenuService, container, (action: IAction): void => {
663663
const text = this._commentEditor!.getValue();
664664

665665
action.run({

src/vs/workbench/contrib/comments/browser/commentReply.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/comme
3030
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
3131
import { LayoutableEditor, MIN_EDITOR_HEIGHT, SimpleCommentEditor, calculateEditorHeight } from './simpleCommentEditor';
3232
import { IHoverService } from 'vs/platform/hover/browser/hover';
33+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
3334

3435
let INMEM_MODEL_ID = 0;
3536
export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration';
@@ -63,6 +64,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
6364
@ICommentService private commentService: ICommentService,
6465
@IConfigurationService configurationService: IConfigurationService,
6566
@IKeybindingService private keybindingService: IKeybindingService,
67+
@IContextMenuService private contextMenuService: IContextMenuService,
6668
@IHoverService private hoverService: IHoverService,
6769
@ITextModelService private readonly textModelService: ITextModelService
6870
) {
@@ -273,7 +275,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
273275
this._commentFormActions.setActions(menu);
274276
}));
275277

276-
this._commentFormActions = new CommentFormActions(this.keybindingService, this._contextKeyService, container, async (action: IAction) => {
278+
this._commentFormActions = new CommentFormActions(this.keybindingService, this._contextKeyService, this.contextMenuService, container, async (action: IAction) => {
277279
await this._actionRunDelegate?.();
278280

279281
await action.run({
@@ -296,7 +298,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
296298
this._commentEditorActions.setActions(editorMenu);
297299
}));
298300

299-
this._commentEditorActions = new CommentFormActions(this.keybindingService, this._contextKeyService, container, async (action: IAction) => {
301+
this._commentEditorActions = new CommentFormActions(this.keybindingService, this._contextKeyService, this.contextMenuService, container, async (action: IAction) => {
300302
this._actionRunDelegate?.();
301303

302304
action.run({

src/vs/workbench/contrib/comments/browser/commentThreadAdditionalActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { CommentFormActions } from 'vs/workbench/contrib/comments/browser/commen
1616
import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus';
1717
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
1818
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
19+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1920

2021
export class CommentThreadAdditionalActions<T extends IRange | ICellRange> extends Disposable {
2122
private _container: HTMLElement | null;
@@ -29,6 +30,7 @@ export class CommentThreadAdditionalActions<T extends IRange | ICellRange> exten
2930
private _commentMenus: CommentMenus,
3031
private _actionRunDelegate: (() => void) | null,
3132
@IKeybindingService private _keybindingService: IKeybindingService,
33+
@IContextMenuService private _contextMenuService: IContextMenuService,
3234
) {
3335
super();
3436

@@ -80,7 +82,7 @@ export class CommentThreadAdditionalActions<T extends IRange | ICellRange> exten
8082
this._enableDisableMenu(menu);
8183
}));
8284

83-
this._commentFormActions = new CommentFormActions(this._keybindingService, this._contextKeyService, container, async (action: IAction) => {
85+
this._commentFormActions = new CommentFormActions(this._keybindingService, this._contextKeyService, this._contextMenuService, container, async (action: IAction) => {
8486
this._actionRunDelegate?.();
8587

8688
action.run({

0 commit comments

Comments
 (0)