Skip to content

Commit 6ce31d9

Browse files
authored
Remove split button from comments additional actions (microsoft#166568)
and add a max number of 4 actions Part of microsoft#163281
1 parent aaac6f9 commit 6ce31d9

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

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

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

6-
import { Button, ButtonWithDropdown, IButton } from 'vs/base/browser/ui/button/button';
6+
import { Button } from 'vs/base/browser/ui/button/button';
77
import { IAction } from 'vs/base/common/actions';
88
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
9-
import { IMenu, SubmenuItemAction } from 'vs/platform/actions/common/actions';
9+
import { IMenu } from 'vs/platform/actions/common/actions';
1010
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles';
11-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1211

1312
export class CommentFormActions implements IDisposable {
1413
private _buttonElements: HTMLElement[] = [];
@@ -18,7 +17,7 @@ export class CommentFormActions implements IDisposable {
1817
constructor(
1918
private container: HTMLElement,
2019
private actionHandler: (action: IAction) => void,
21-
private contextMenuService?: IContextMenuService
20+
private readonly maxActions?: number
2221
) { }
2322

2423
setActions(menu: IMenu, hasOnlySecondaryActions: boolean = false) {
@@ -33,34 +32,20 @@ export class CommentFormActions implements IDisposable {
3332

3433
this._actions = actions;
3534
for (const action of actions) {
36-
const submenuAction = action as SubmenuItemAction;
37-
38-
// Use the first action from the submenu as the primary button.
39-
const appliedAction: IAction = submenuAction.actions?.length > 0 ? submenuAction.actions[0] : action;
40-
let button: IButton | undefined;
41-
42-
// Use dropdown only if submenu contains more than 1 action.
43-
if (submenuAction.actions?.length > 1 && this.contextMenuService) {
44-
button = new ButtonWithDropdown(this.container,
45-
{
46-
contextMenuProvider: this.contextMenuService,
47-
actions: submenuAction.actions.slice(1),
48-
addPrimaryActionToDropdown: false,
49-
secondary: !isPrimary,
50-
...defaultButtonStyles
51-
});
52-
} else {
53-
button = new Button(this.container, { secondary: !isPrimary, ...defaultButtonStyles });
54-
}
35+
const button = new Button(this.container, { secondary: !isPrimary, ...defaultButtonStyles });
5536

5637
isPrimary = false;
5738
this._buttonElements.push(button.element);
5839

5940
this._toDispose.add(button);
60-
this._toDispose.add(button.onDidClick(() => this.actionHandler(appliedAction)));
41+
this._toDispose.add(button.onDidClick(() => this.actionHandler(action)));
6142

62-
button.enabled = appliedAction.enabled;
63-
button.label = appliedAction.label;
43+
button.enabled = action.enabled;
44+
button.label = action.label;
45+
if ((this.maxActions !== undefined) && (this._buttonElements.length >= this.maxActions)) {
46+
console.warn(`An extension has contributed more than the allowable number of actions to a comments menu.`);
47+
return;
48+
}
6449
}
6550
}
6651
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1515
import { CommentFormActions } from 'vs/workbench/contrib/comments/browser/commentFormActions';
1616
import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus';
1717
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
18-
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1918

2019
export class CommentThreadAdditionalActions<T extends IRange | ICellRange> extends Disposable {
2120
private _container: HTMLElement | null;
@@ -28,7 +27,6 @@ export class CommentThreadAdditionalActions<T extends IRange | ICellRange> exten
2827
private _contextKeyService: IContextKeyService,
2928
private _commentMenus: CommentMenus,
3029
private _actionRunDelegate: (() => void) | null,
31-
@IContextMenuService private contextMenuService: IContextMenuService,
3230
) {
3331
super();
3432

@@ -76,7 +74,7 @@ export class CommentThreadAdditionalActions<T extends IRange | ICellRange> exten
7674
const menu = this._commentMenus.getCommentThreadAdditionalActions(this._contextKeyService);
7775
this._register(menu);
7876
this._register(menu.onDidChange(() => {
79-
this._commentFormActions.setActions(menu);
77+
this._commentFormActions.setActions(menu, /*hasOnlySecondaryActions*/ true);
8078
this._enableDisableMenu(menu);
8179
}));
8280

@@ -87,8 +85,7 @@ export class CommentThreadAdditionalActions<T extends IRange | ICellRange> exten
8785
thread: this._commentThread,
8886
$mid: MarshalledId.CommentThreadInstance
8987
});
90-
91-
}, this.contextMenuService);
88+
}, 4);
9289

9390
this._register(this._commentFormActions);
9491
this._commentFormActions.setActions(menu, /*hasOnlySecondaryActions*/ true);

src/vs/workbench/services/actions/common/menusExtensionPoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const apiMenus: IAPIMenu[] = [
163163
key: 'comments/commentThread/additionalActions',
164164
id: MenuId.CommentThreadAdditionalActions,
165165
description: localize('commentThread.actions', "The contributed comment thread context menu, rendered as buttons below the comment editor"),
166-
supportsSubmenus: true,
166+
supportsSubmenus: false,
167167
proposed: 'contribCommentThreadAdditionalMenu'
168168
},
169169
{

0 commit comments

Comments
 (0)