@@ -12,8 +12,7 @@ import 'vs/css!./actionWidget';
12
12
import { localize } from 'vs/nls' ;
13
13
import { Action2 , registerAction2 } from 'vs/platform/actions/common/actions' ;
14
14
import { acceptSelectedActionCommand , ActionList , IListMenuItem , previewSelectedActionCommand } from 'vs/platform/actionWidget/browser/actionList' ;
15
- import { ActionSet , IActionItem , IActionKeybindingResolver } from 'vs/platform/actionWidget/common/actionWidget' ;
16
- import { ICommandService } from 'vs/platform/commands/common/commands' ;
15
+ import { IActionItem , IActionKeybindingResolver } from 'vs/platform/actionWidget/common/actionWidget' ;
17
16
import { IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
18
17
import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
19
18
import { InstantiationType , registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
@@ -30,18 +29,13 @@ export interface IRenderDelegate<T extends IActionItem> {
30
29
onSelect ( action : IActionItem , preview ?: boolean ) : Promise < any > ;
31
30
}
32
31
33
- export interface IActionShowOptions {
34
- readonly includeDisabledActions : boolean ;
35
- readonly fromLightbulb ?: boolean ;
36
- readonly showHeaders ?: boolean ;
37
- }
38
-
39
32
export const IActionWidgetService = createDecorator < IActionWidgetService > ( 'actionWidgetService' ) ;
40
33
41
34
export interface IActionWidgetService {
42
35
readonly _serviceBrand : undefined ;
43
36
44
- show ( user : string , toMenuItems : ( inputQuickFixes : readonly any [ ] , showHeaders : boolean ) => IListMenuItem < IActionItem > [ ] , delegate : IRenderDelegate < any > , actions : ActionSet < any > , anchor : IAnchor , container : HTMLElement | undefined , options : IActionShowOptions ) : Promise < void > ;
37
+ show ( user : string , items : IListMenuItem < IActionItem > [ ] , delegate : IRenderDelegate < any > , anchor : IAnchor , container : HTMLElement | undefined , actionBarActions ?: readonly IAction [ ] ) : Promise < void > ;
38
+
45
39
hide ( ) : void ;
46
40
47
41
readonly isVisible : boolean ;
@@ -54,47 +48,25 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
54
48
return ActionWidgetContextKeys . Visible . getValue ( this . _contextKeyService ) || false ;
55
49
}
56
50
57
- private _showDisabled = false ;
58
- private _currentShowingContext ?: {
59
- readonly user : string ;
60
- readonly toMenuItems : ( inputItems : readonly any [ ] , showHeaders : boolean ) => IListMenuItem < any > [ ] ;
61
- readonly options : IActionShowOptions ;
62
- readonly anchor : IAnchor ;
63
- readonly container : HTMLElement | undefined ;
64
- readonly actions : ActionSet < unknown > ;
65
- readonly delegate : IRenderDelegate < any > ;
66
- readonly resolver ?: IActionKeybindingResolver ;
67
- } ;
68
-
69
51
private readonly _list = this . _register ( new MutableDisposable < ActionList < any > > ( ) ) ;
70
52
71
53
constructor (
72
- @ICommandService private readonly _commandService : ICommandService ,
73
54
@IContextViewService private readonly contextViewService : IContextViewService ,
74
55
@IContextKeyService private readonly _contextKeyService : IContextKeyService ,
75
56
@IInstantiationService private readonly _instantiationService : IInstantiationService
76
57
) {
77
58
super ( ) ;
78
59
}
79
60
80
- async show ( user : string , toMenuItems : ( inputQuickFixes : readonly IActionItem [ ] , showHeaders : boolean ) => IListMenuItem < IActionItem > [ ] , delegate : IRenderDelegate < any > , actions : ActionSet < any > , anchor : IAnchor , container : HTMLElement | undefined , options : IActionShowOptions , resolver ?: IActionKeybindingResolver ) : Promise < void > {
81
- this . _currentShowingContext = undefined ;
61
+ async show ( user : string , items : IListMenuItem < IActionItem > [ ] , delegate : IRenderDelegate < any > , anchor : IAnchor , container : HTMLElement | undefined , actionBarActions ?: readonly IAction [ ] , resolver ?: IActionKeybindingResolver ) : Promise < void > {
82
62
const visibleContext = ActionWidgetContextKeys . Visible . bindTo ( this . _contextKeyService ) ;
83
63
84
- const actionsToShow = options . includeDisabledActions && ( this . _showDisabled || actions . validActions . length === 0 ) ? actions . allActions : actions . validActions ;
85
- if ( ! actionsToShow . length ) {
86
- visibleContext . reset ( ) ;
87
- return ;
88
- }
89
-
90
- this . _currentShowingContext = { user, toMenuItems, delegate, actions, anchor, container, options, resolver } ;
91
-
92
- const list = this . _instantiationService . createInstance ( ActionList , user , toMenuItems ( actionsToShow , true ) , delegate , resolver ) ;
64
+ const list = this . _instantiationService . createInstance ( ActionList , user , items , delegate , resolver ) ;
93
65
this . contextViewService . showContextView ( {
94
66
getAnchor : ( ) => anchor ,
95
67
render : ( container : HTMLElement ) => {
96
68
visibleContext . set ( true ) ;
97
- return this . _renderWidget ( container , list , actions , options ) ;
69
+ return this . _renderWidget ( container , list , actionBarActions ?? [ ] ) ;
98
70
} ,
99
71
onHide : ( didCancel ) => {
100
72
visibleContext . reset ( ) ;
@@ -124,7 +96,7 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
124
96
this . _list . clear ( ) ;
125
97
}
126
98
127
- private _renderWidget ( element : HTMLElement , list : ActionList < any > , actions : ActionSet < any > , options : IActionShowOptions ) : IDisposable {
99
+ private _renderWidget ( element : HTMLElement , list : ActionList < any > , actionBarActions : readonly IAction [ ] ) : IDisposable {
128
100
const widget = document . createElement ( 'div' ) ;
129
101
widget . classList . add ( 'action-widget' ) ;
130
102
element . appendChild ( widget ) ;
@@ -154,8 +126,8 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
154
126
155
127
// Action bar
156
128
let actionBarWidth = 0 ;
157
- if ( ! options . fromLightbulb ) {
158
- const actionBar = this . _createActionBar ( '.action-widget-action-bar' , actions , options ) ;
129
+ if ( actionBarActions . length ) {
130
+ const actionBar = this . _createActionBar ( '.action-widget-action-bar' , actionBarActions ) ;
159
131
if ( actionBar ) {
160
132
widget . appendChild ( actionBar . getContainer ( ) . parentElement ! ) ;
161
133
renderDisposables . add ( actionBar ) ;
@@ -172,8 +144,7 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
172
144
return renderDisposables ;
173
145
}
174
146
175
- private _createActionBar ( className : string , inputActions : ActionSet < any > , options : IActionShowOptions ) : ActionBar | undefined {
176
- const actions = this . _getActionBarActions ( inputActions , options ) ;
147
+ private _createActionBar ( className : string , actions : readonly IAction [ ] ) : ActionBar | undefined {
177
148
if ( ! actions . length ) {
178
149
return undefined ;
179
150
}
@@ -184,54 +155,7 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
184
155
return actionBar ;
185
156
}
186
157
187
- private _getActionBarActions ( actions : ActionSet < any > , options : IActionShowOptions ) : IAction [ ] {
188
- const resultActions = actions . documentation . map ( ( command ) : IAction => ( {
189
- id : command . id ,
190
- label : command . title ,
191
- tooltip : command . tooltip ?? '' ,
192
- class : undefined ,
193
- enabled : true ,
194
- run : ( ) => this . _commandService . executeCommand ( command . id , ...( command . commandArguments ?? [ ] ) ) ,
195
- } ) ) ;
196
-
197
- if ( options . includeDisabledActions && actions . validActions . length > 0 && actions . allActions . length !== actions . validActions . length ) {
198
- resultActions . push ( this . _showDisabled ? {
199
- id : 'hideMoreActions' ,
200
- label : localize ( 'hideMoreActions' , 'Hide Disabled' ) ,
201
- enabled : true ,
202
- tooltip : '' ,
203
- class : undefined ,
204
- run : ( ) => this . _toggleShowDisabled ( false )
205
- } : {
206
- id : 'showMoreActions' ,
207
- label : localize ( 'showMoreActions' , 'Show Disabled' ) ,
208
- enabled : true ,
209
- tooltip : '' ,
210
- class : undefined ,
211
- run : ( ) => this . _toggleShowDisabled ( true )
212
- } ) ;
213
- }
214
-
215
- return resultActions ;
216
- }
217
-
218
- /**
219
- * Toggles whether the disabled actions in the action widget are visible or not.
220
- */
221
- private _toggleShowDisabled ( newShowDisabled : boolean ) : void {
222
- const previousCtx = this . _currentShowingContext ;
223
-
224
- this . hide ( ) ;
225
-
226
- this . _showDisabled = newShowDisabled ;
227
-
228
- if ( previousCtx ) {
229
- this . show ( previousCtx . user , previousCtx . toMenuItems , previousCtx . delegate , previousCtx . actions , previousCtx . anchor , previousCtx . container , previousCtx . options , previousCtx . resolver ) ;
230
- }
231
- }
232
-
233
158
private _onWidgetClosed ( didCancel ?: boolean ) : void {
234
- this . _currentShowingContext = undefined ;
235
159
this . _list . value ?. hide ( didCancel ) ;
236
160
}
237
161
}
0 commit comments