3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Button , ButtonWithDropdown , IButton } from 'vs/base/browser/ui/button/button' ;
6
+ import { Button } from 'vs/base/browser/ui/button/button' ;
7
7
import { IAction } from 'vs/base/common/actions' ;
8
8
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' ;
10
10
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles' ;
11
- import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
12
11
13
12
export class CommentFormActions implements IDisposable {
14
13
private _buttonElements : HTMLElement [ ] = [ ] ;
@@ -18,7 +17,7 @@ export class CommentFormActions implements IDisposable {
18
17
constructor (
19
18
private container : HTMLElement ,
20
19
private actionHandler : ( action : IAction ) => void ,
21
- private contextMenuService ?: IContextMenuService
20
+ private readonly maxActions ?: number
22
21
) { }
23
22
24
23
setActions ( menu : IMenu , hasOnlySecondaryActions : boolean = false ) {
@@ -33,34 +32,20 @@ export class CommentFormActions implements IDisposable {
33
32
34
33
this . _actions = actions ;
35
34
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 } ) ;
55
36
56
37
isPrimary = false ;
57
38
this . _buttonElements . push ( button . element ) ;
58
39
59
40
this . _toDispose . add ( button ) ;
60
- this . _toDispose . add ( button . onDidClick ( ( ) => this . actionHandler ( appliedAction ) ) ) ;
41
+ this . _toDispose . add ( button . onDidClick ( ( ) => this . actionHandler ( action ) ) ) ;
61
42
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
+ }
64
49
}
65
50
}
66
51
}
0 commit comments