@@ -12,7 +12,7 @@ import { localize } from 'vs/nls';
12
12
import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
13
13
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
14
14
import { ZoneWidget } from 'vs/editor/contrib/zoneWidget/browser/zoneWidget' ;
15
- import { CTX_INLINE_CHAT_FOCUSED , CTX_INLINE_CHAT_INNER_CURSOR_FIRST , CTX_INLINE_CHAT_INNER_CURSOR_LAST , CTX_INLINE_CHAT_EMPTY , CTX_INLINE_CHAT_OUTER_CURSOR_POSITION , CTX_INLINE_CHAT_VISIBLE , MENU_INLINE_CHAT_WIDGET , MENU_INLINE_CHAT_WIDGET_STATUS , MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE , CTX_INLINE_CHAT_MESSAGE_CROP_STATE , IInlineChatSlashCommand , MENU_INLINE_CHAT_WIDGET_FEEDBACK , ACTION_ACCEPT_CHANGES } from 'vs/workbench/contrib/inlineChat/common/inlineChat' ;
15
+ import { CTX_INLINE_CHAT_FOCUSED , CTX_INLINE_CHAT_INNER_CURSOR_FIRST , CTX_INLINE_CHAT_INNER_CURSOR_LAST , CTX_INLINE_CHAT_EMPTY , CTX_INLINE_CHAT_OUTER_CURSOR_POSITION , CTX_INLINE_CHAT_VISIBLE , MENU_INLINE_CHAT_WIDGET , MENU_INLINE_CHAT_WIDGET_STATUS , MENU_INLINE_CHAT_WIDGET_MARKDOWN_MESSAGE , CTX_INLINE_CHAT_MESSAGE_CROP_STATE , IInlineChatSlashCommand , MENU_INLINE_CHAT_WIDGET_FEEDBACK , ACTION_REGENERATE_RESPONSE } from 'vs/workbench/contrib/inlineChat/common/inlineChat' ;
16
16
import { IModelDeltaDecoration , ITextModel } from 'vs/editor/common/model' ;
17
17
import { Dimension , addDisposableListener , getActiveElement , getTotalHeight , getTotalWidth , h , reset } from 'vs/base/browser/dom' ;
18
18
import { Emitter , Event , MicrotaskEmitter } from 'vs/base/common/event' ;
@@ -28,14 +28,11 @@ import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
28
28
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestController' ;
29
29
import { Position } from 'vs/editor/common/core/position' ;
30
30
import { DEFAULT_FONT_FAMILY } from 'vs/workbench/browser/style' ;
31
- import { DropdownWithDefaultActionViewItem , IMenuEntryActionViewItemOptions , MenuEntryActionViewItem , createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
32
31
import { CompletionItem , CompletionItemInsertTextRule , CompletionItemKind , CompletionItemProvider , CompletionList , ProviderResult , TextEdit } from 'vs/editor/common/languages' ;
33
32
import { EditOperation , ISingleEditOperation } from 'vs/editor/common/core/editOperation' ;
34
33
import { ILanguageSelection , ILanguageService } from 'vs/editor/common/languages/language' ;
35
34
import { ResourceLabel } from 'vs/workbench/browser/labels' ;
36
35
import { FileKind } from 'vs/platform/files/common/files' ;
37
- import { IAction } from 'vs/base/common/actions' ;
38
- import { IActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionViewItems' ;
39
36
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures' ;
40
37
import { LanguageSelector } from 'vs/editor/common/languageSelector' ;
41
38
import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel' ;
@@ -44,18 +41,14 @@ import { invertLineRange, lineRangeAsRange } from 'vs/workbench/contrib/inlineCh
44
41
import { ICodeEditorViewState , ScrollType } from 'vs/editor/common/editorCommon' ;
45
42
import { LineRange } from 'vs/editor/common/core/lineRange' ;
46
43
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
47
- import { IMenuService , MenuItemAction , SubmenuItemAction } from 'vs/platform/actions/common/actions' ;
48
44
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
49
45
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
50
46
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution' ;
51
- import { assertType } from 'vs/base/common/types' ;
52
47
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels' ;
53
48
import { ExpansionState } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession' ;
54
49
import { IdleValue } from 'vs/base/common/async' ;
55
50
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' ;
51
+ import { IMenuWorkbenchButtonBarOptions , MenuWorkbenchButtonBar } from 'vs/platform/actions/browser/buttonbar' ;
59
52
60
53
const defaultAriaLabel = localize ( 'aria-label' , "Inline Chat Input" ) ;
61
54
@@ -196,9 +189,7 @@ export class InlineChatWidget {
196
189
@IKeybindingService private readonly _keybindingService : IKeybindingService ,
197
190
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
198
191
@IAccessibilityService private readonly _accessibilityService : IAccessibilityService ,
199
- @IConfigurationService private readonly _configurationService : IConfigurationService ,
200
- @IMenuService private readonly _menuService : IMenuService ,
201
- @IContextMenuService private readonly _contextMenuService : IContextMenuService ,
192
+ @IConfigurationService private readonly _configurationService : IConfigurationService
202
193
) {
203
194
204
195
// input editor logic
@@ -298,104 +289,28 @@ export class InlineChatWidget {
298
289
this . _progressBar = new ProgressBar ( this . _elements . progress ) ;
299
290
this . _store . add ( this . _progressBar ) ;
300
291
292
+ const workbenchMenubarOptions : IMenuWorkbenchButtonBarOptions = {
293
+ telemetrySource : 'interactiveEditorWidget-toolbar' ,
294
+ buttonConfigProvider : action => {
295
+ if ( action . id === ACTION_REGENERATE_RESPONSE ) {
296
+ return { showIcon : true , showLabel : false } ;
297
+ }
298
+ return undefined ;
299
+ }
300
+ } ;
301
+ const statusButtonBar = this . _instantiationService . createInstance ( MenuWorkbenchButtonBar , this . _elements . statusToolbar , MENU_INLINE_CHAT_WIDGET_STATUS , workbenchMenubarOptions ) ;
302
+ this . _store . add ( statusButtonBar . onDidChangeMenuItems ( ( ) => this . _onDidChangeHeight . fire ( ) ) ) ;
303
+ this . _store . add ( statusButtonBar ) ;
304
+
305
+
301
306
const workbenchToolbarOptions = {
302
307
hiddenItemStrategy : HiddenItemStrategy . NoHide ,
303
308
toolbarOptions : {
304
309
primaryGroup : ( ) => true ,
305
310
useSeparatorsInPrimaryActions : true
306
- } ,
307
- actionViewItemProvider : ( action : IAction , options : IActionViewItemOptions ) => {
308
-
309
- if ( action instanceof SubmenuItemAction ) {
310
- return this . _instantiationService . createInstance ( DropdownWithDefaultActionViewItem , action , { ...options , renderKeybindingWithDefaultActionLabel : true , persistLastActionId : false } ) ;
311
- }
312
-
313
- if ( action . id === ACTION_ACCEPT_CHANGES ) {
314
- const ButtonLikeActionViewItem = class extends MenuEntryActionViewItem {
315
-
316
- override render ( container : HTMLElement ) : void {
317
- this . options . icon = false ;
318
- super . render ( container ) ;
319
- assertType ( this . element ) ;
320
- this . element . classList . add ( 'button-item' ) ;
321
- }
322
-
323
- protected override updateLabel ( ) : void {
324
- assertType ( this . label ) ;
325
- assertType ( this . action instanceof MenuItemAction ) ;
326
- const label = MenuItemAction . label ( this . action . item , { renderShortTitle : true } ) ;
327
- const labelElements = renderLabelWithIcons ( `$(check)${ label } ` ) ;
328
- reset ( this . label , ...labelElements ) ;
329
- }
330
-
331
- protected override updateClass ( ) : void {
332
- // noop
333
- }
334
- } ;
335
- return this . _instantiationService . createInstance ( ButtonLikeActionViewItem , < MenuItemAction > action , < IMenuEntryActionViewItemOptions > options ) ;
336
- }
337
-
338
- return createActionViewItem ( this . _instantiationService , action , options ) ;
339
- }
340
- } ;
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
311
}
393
312
} ;
394
313
395
- populateButtonBarFromMenu ( ) ;
396
- this . _store . add ( menu . onDidChange ( populateButtonBarFromMenu ) ) ;
397
-
398
-
399
314
const feedbackToolbar = this . _instantiationService . createInstance ( MenuWorkbenchToolBar , this . _elements . feedbackToolbar , MENU_INLINE_CHAT_WIDGET_FEEDBACK , { ...workbenchToolbarOptions , hiddenItemStrategy : HiddenItemStrategy . Ignore } ) ;
400
315
this . _store . add ( feedbackToolbar . onDidChangeMenuItems ( ( ) => this . _onDidChangeHeight . fire ( ) ) ) ;
401
316
this . _store . add ( feedbackToolbar ) ;
0 commit comments