@@ -12,8 +12,7 @@ import 'vs/css!./actionWidget';
1212import { localize } from 'vs/nls' ;
1313import { Action2 , registerAction2 } from 'vs/platform/actions/common/actions' ;
1414import { 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' ;
1716import { IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
1817import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
1918import { InstantiationType , registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
@@ -30,18 +29,13 @@ export interface IRenderDelegate<T extends IActionItem> {
3029 onSelect ( action : IActionItem , preview ?: boolean ) : Promise < any > ;
3130}
3231
33- export interface IActionShowOptions {
34- readonly includeDisabledActions : boolean ;
35- readonly fromLightbulb ?: boolean ;
36- readonly showHeaders ?: boolean ;
37- }
38-
3932export const IActionWidgetService = createDecorator < IActionWidgetService > ( 'actionWidgetService' ) ;
4033
4134export interface IActionWidgetService {
4235 readonly _serviceBrand : undefined ;
4336
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+
4539 hide ( ) : void ;
4640
4741 readonly isVisible : boolean ;
@@ -54,47 +48,25 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
5448 return ActionWidgetContextKeys . Visible . getValue ( this . _contextKeyService ) || false ;
5549 }
5650
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-
6951 private readonly _list = this . _register ( new MutableDisposable < ActionList < any > > ( ) ) ;
7052
7153 constructor (
72- @ICommandService private readonly _commandService : ICommandService ,
7354 @IContextViewService private readonly contextViewService : IContextViewService ,
7455 @IContextKeyService private readonly _contextKeyService : IContextKeyService ,
7556 @IInstantiationService private readonly _instantiationService : IInstantiationService
7657 ) {
7758 super ( ) ;
7859 }
7960
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 > {
8262 const visibleContext = ActionWidgetContextKeys . Visible . bindTo ( this . _contextKeyService ) ;
8363
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 ) ;
9365 this . contextViewService . showContextView ( {
9466 getAnchor : ( ) => anchor ,
9567 render : ( container : HTMLElement ) => {
9668 visibleContext . set ( true ) ;
97- return this . _renderWidget ( container , list , actions , options ) ;
69+ return this . _renderWidget ( container , list , actionBarActions ?? [ ] ) ;
9870 } ,
9971 onHide : ( didCancel ) => {
10072 visibleContext . reset ( ) ;
@@ -124,7 +96,7 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
12496 this . _list . clear ( ) ;
12597 }
12698
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 {
128100 const widget = document . createElement ( 'div' ) ;
129101 widget . classList . add ( 'action-widget' ) ;
130102 element . appendChild ( widget ) ;
@@ -154,8 +126,8 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
154126
155127 // Action bar
156128 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 ) ;
159131 if ( actionBar ) {
160132 widget . appendChild ( actionBar . getContainer ( ) . parentElement ! ) ;
161133 renderDisposables . add ( actionBar ) ;
@@ -172,8 +144,7 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
172144 return renderDisposables ;
173145 }
174146
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 {
177148 if ( ! actions . length ) {
178149 return undefined ;
179150 }
@@ -184,54 +155,7 @@ class ActionWidgetService extends Disposable implements IActionWidgetService {
184155 return actionBar ;
185156 }
186157
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-
233158 private _onWidgetClosed ( didCancel ?: boolean ) : void {
234- this . _currentShowingContext = undefined ;
235159 this . _list . value ?. hide ( didCancel ) ;
236160 }
237161}
0 commit comments