@@ -44,7 +44,7 @@ import { invertLineRange, lineRangeAsRange } from 'vs/workbench/contrib/inlineCh
44
44
import { ICodeEditorViewState , ScrollType } from 'vs/editor/common/editorCommon' ;
45
45
import { LineRange } from 'vs/editor/common/core/lineRange' ;
46
46
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
47
- import { MenuItemAction , SubmenuItemAction } from 'vs/platform/actions/common/actions' ;
47
+ import { IMenuService , MenuItemAction , SubmenuItemAction } from 'vs/platform/actions/common/actions' ;
48
48
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
49
49
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
50
50
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution' ;
@@ -53,6 +53,9 @@ import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
53
53
import { ExpansionState } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession' ;
54
54
import { IdleValue } from 'vs/base/common/async' ;
55
55
import * as aria from 'vs/base/browser/ui/aria/aria' ;
56
+ import { ButtonBar , IButton } from 'vs/base/browser/ui/button/button' ;
57
+ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
58
+ import { onUnexpectedError } from 'vs/base/common/errors' ;
56
59
57
60
const defaultAriaLabel = localize ( 'aria-label' , "Inline Chat Input" ) ;
58
61
@@ -193,7 +196,9 @@ export class InlineChatWidget {
193
196
@IKeybindingService private readonly _keybindingService : IKeybindingService ,
194
197
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
195
198
@IAccessibilityService private readonly _accessibilityService : IAccessibilityService ,
196
- @IConfigurationService private readonly _configurationService : IConfigurationService
199
+ @IConfigurationService private readonly _configurationService : IConfigurationService ,
200
+ @IMenuService private readonly _menuService : IMenuService ,
201
+ @IContextMenuService private readonly _contextMenuService : IContextMenuService ,
197
202
) {
198
203
199
204
// input editor logic
@@ -333,9 +338,63 @@ export class InlineChatWidget {
333
338
return createActionViewItem ( this . _instantiationService , action , options ) ;
334
339
}
335
340
} ;
336
- const statusToolbar = this . _instantiationService . createInstance ( MenuWorkbenchToolBar , this . _elements . statusToolbar , MENU_INLINE_CHAT_WIDGET_STATUS , { ...workbenchToolbarOptions , hiddenItemStrategy : HiddenItemStrategy . Ignore } ) ;
337
- this . _store . add ( statusToolbar . onDidChangeMenuItems ( ( ) => this . _onDidChangeHeight . fire ( ) ) ) ;
338
- this . _store . add ( statusToolbar ) ;
341
+ // const statusToolbar = this._instantiationService.createInstance(MenuWorkbenchToolBar, this._elements.statusToolbar, MENU_INLINE_CHAT_WIDGET_STATUS, { ...workbenchToolbarOptions, hiddenItemStrategy: HiddenItemStrategy.Ignore });
342
+ // this._store.add(statusToolbar.onDidChangeMenuItems(() => this._onDidChangeHeight.fire()));
343
+ // this._store.add(statusToolbar);
344
+
345
+ // TODO@jrieken extract this as re-usable MenuButtonBar similar to MenuWorkbenchToolBar
346
+ // add telemetry for workbench actions....
347
+ //
348
+ const menu = this . _menuService . createMenu ( MENU_INLINE_CHAT_WIDGET_STATUS , this . _contextKeyService ) ;
349
+ const buttonBar = new ButtonBar ( this . _elements . statusToolbar ) ;
350
+ this . _store . add ( menu ) ;
351
+ this . _store . add ( buttonBar ) ;
352
+
353
+ const populateButtonBarFromMenu = ( ) => {
354
+
355
+ buttonBar . clear ( ) ;
356
+
357
+ const actions = menu
358
+ . getActions ( { renderShortTitle : true } )
359
+ . flatMap ( entry => entry [ 1 ] ) ;
360
+
361
+ for ( let i = 0 ; i < actions . length ; i ++ ) {
362
+ const action = actions [ i ] ;
363
+ let btnAction : IAction ;
364
+ let btn : IButton ;
365
+
366
+ if ( action instanceof SubmenuItemAction && action . actions . length > 0 ) {
367
+ const [ first , ...rest ] = action . actions ;
368
+ btnAction = first ;
369
+ btn = buttonBar . addButtonWithDropdown ( {
370
+ secondary : i > 0 ,
371
+ actions : rest ,
372
+ contextMenuProvider : this . _contextMenuService
373
+ } ) ;
374
+ } else {
375
+ btnAction = action ;
376
+ btn = buttonBar . addButton ( { secondary : i > 0 } ) ;
377
+ }
378
+
379
+ btn . label = btnAction . label ;
380
+ btn . enabled = btnAction . enabled ;
381
+ const kb = _keybindingService . lookupKeybinding ( btnAction . id ) ;
382
+ if ( kb ) {
383
+ btn . element . title = localize ( 'labelWithKeybinding' , "{0} ({1})" , btnAction . label , kb . getLabel ( ) ) ;
384
+ }
385
+ btn . onDidClick ( async ( ) => {
386
+ try {
387
+ await btnAction . run ( ) ;
388
+ } catch ( error ) {
389
+ onUnexpectedError ( error ) ;
390
+ }
391
+ } ) ;
392
+ }
393
+ } ;
394
+
395
+ populateButtonBarFromMenu ( ) ;
396
+ this . _store . add ( menu . onDidChange ( populateButtonBarFromMenu ) ) ;
397
+
339
398
340
399
const feedbackToolbar = this . _instantiationService . createInstance ( MenuWorkbenchToolBar , this . _elements . feedbackToolbar , MENU_INLINE_CHAT_WIDGET_FEEDBACK , { ...workbenchToolbarOptions , hiddenItemStrategy : HiddenItemStrategy . Ignore } ) ;
341
400
this . _store . add ( feedbackToolbar . onDidChangeMenuItems ( ( ) => this . _onDidChangeHeight . fire ( ) ) ) ;
0 commit comments