3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
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' ;
8
8
import { DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
9
9
import { IMenu } from 'vs/platform/actions/common/actions' ;
10
10
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
11
+ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
11
12
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
12
13
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles' ;
13
14
import { CommentCommandId } from 'vs/workbench/contrib/comments/common/commentCommandIds' ;
@@ -20,6 +21,7 @@ export class CommentFormActions implements IDisposable {
20
21
constructor (
21
22
private readonly keybindingService : IKeybindingService ,
22
23
private readonly contextKeyService : IContextKeyService ,
24
+ private readonly contextMenuService : IContextMenuService ,
23
25
private container : HTMLElement ,
24
26
private actionHandler : ( action : IAction ) => void ,
25
27
private readonly maxActions ?: number
@@ -34,16 +36,30 @@ export class CommentFormActions implements IDisposable {
34
36
const groups = menu . getActions ( { shouldForwardArgs : true } ) ;
35
37
let isPrimary : boolean = ! hasOnlySecondaryActions ;
36
38
for ( const group of groups ) {
37
- const [ , actions ] = group ;
39
+ const [ groupId , actions ] = group ;
38
40
39
41
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 , [ ] ] ;
41
44
let keybinding = this . keybindingService . lookupKeybinding ( action . id , this . contextKeyService ) ?. getLabel ( ) ;
42
45
if ( ! keybinding && isPrimary ) {
43
46
keybinding = this . keybindingService . lookupKeybinding ( CommentCommandId . Submit , this . contextKeyService ) ?. getLabel ( ) ;
44
47
}
45
48
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 } ) ;
47
63
48
64
isPrimary = false ;
49
65
this . _buttonElements . push ( button . element ) ;
0 commit comments