@@ -12,9 +12,13 @@ import { IMarkdownString, MarkdownString } from '../../../../../base/common/html
1212import { Disposable , DisposableStore , MutableDisposable } from '../../../../../base/common/lifecycle.js' ;
1313import { IMarkdownRenderResult , MarkdownRenderer , openLinkFromMarkdown } from '../../../../../editor/browser/widget/markdownRenderer/browser/markdownRenderer.js' ;
1414import { localize } from '../../../../../nls.js' ;
15+ import { MenuWorkbenchToolBar } from '../../../../../platform/actions/browser/toolbar.js' ;
16+ import { MenuId } from '../../../../../platform/actions/common/actions.js' ;
1517import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
18+ import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js' ;
1619import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.js' ;
1720import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js' ;
21+ import { ServiceCollection } from '../../../../../platform/instantiation/common/serviceCollection.js' ;
1822import { FocusMode } from '../../../../../platform/native/common/native.js' ;
1923import { IOpenerService } from '../../../../../platform/opener/common/opener.js' ;
2024import { defaultButtonStyles } from '../../../../../platform/theme/browser/defaultStyles.js' ;
@@ -33,6 +37,13 @@ export interface IChatConfirmationButton {
3337 moreActions ?: IChatConfirmationButton [ ] ;
3438}
3539
40+ export interface IChatConfirmationWidgetOptions {
41+ title : string | IMarkdownString ;
42+ subtitle ?: string | IMarkdownString ;
43+ buttons : IChatConfirmationButton [ ] ;
44+ toolbarData ?: { arg : any ; partType : string } ;
45+ }
46+
3647export class ChatQueryTitlePart extends Disposable {
3748 private readonly _onDidChangeHeight = this . _register ( new Emitter < void > ( ) ) ;
3849 public readonly onDidChangeHeight = this . _onDidChangeHeight . event ;
@@ -117,25 +128,31 @@ abstract class BaseChatConfirmationWidget extends Disposable {
117128
118129 private readonly messageElement : HTMLElement ;
119130 protected readonly markdownRenderer : MarkdownRenderer ;
131+ private readonly title : string | IMarkdownString ;
120132
121133 private readonly notification = this . _register ( new MutableDisposable < DisposableStore > ( ) ) ;
122134
123135 constructor (
124- private title : string | IMarkdownString ,
125- subtitle : string | IMarkdownString | undefined ,
126- buttons : IChatConfirmationButton [ ] ,
136+ options : IChatConfirmationWidgetOptions ,
127137 @IInstantiationService protected readonly instantiationService : IInstantiationService ,
128138 @IContextMenuService contextMenuService : IContextMenuService ,
129139 @IConfigurationService private readonly _configurationService : IConfigurationService ,
130140 @IHostService private readonly _hostService : IHostService ,
131- @IViewsService private readonly _viewsService : IViewsService
141+ @IViewsService private readonly _viewsService : IViewsService ,
142+ @IContextKeyService contextKeyService : IContextKeyService ,
132143 ) {
133144 super ( ) ;
134145
146+ const { title, subtitle, buttons } = options ;
147+ this . title = title ;
148+
135149 const elements = dom . h ( '.chat-confirmation-widget@root' , [
136150 dom . h ( '.chat-confirmation-widget-title@title' ) ,
137151 dom . h ( '.chat-confirmation-widget-message@message' ) ,
138- dom . h ( '.chat-buttons-container@buttonsContainer' ) ,
152+ dom . h ( '.chat-buttons-container@buttonsContainer' , [
153+ dom . h ( '.chat-buttons@buttons' ) ,
154+ dom . h ( '.chat-toolbar@toolbar' ) ,
155+ ] ) ,
139156 ] ) ;
140157 this . _domNode = elements . root ;
141158 this . markdownRenderer = this . instantiationService . createInstance ( MarkdownRenderer , { } ) ;
@@ -151,12 +168,14 @@ abstract class BaseChatConfirmationWidget extends Disposable {
151168 this . _register ( titlePart . onDidChangeHeight ( ( ) => this . _onDidChangeHeight . fire ( ) ) ) ;
152169
153170 this . messageElement = elements . message ;
171+
172+ // Create buttons
154173 buttons . forEach ( buttonData => {
155174 const buttonOptions : IButtonOptions = { ...defaultButtonStyles , secondary : buttonData . isSecondary , title : buttonData . tooltip , disabled : buttonData . disabled } ;
156175
157176 let button : IButton ;
158177 if ( buttonData . moreActions ) {
159- button = new ButtonWithDropdown ( elements . buttonsContainer , {
178+ button = new ButtonWithDropdown ( elements . buttons , {
160179 ...buttonOptions ,
161180 contextMenuProvider : contextMenuService ,
162181 addPrimaryActionToDropdown : false ,
@@ -172,7 +191,7 @@ abstract class BaseChatConfirmationWidget extends Disposable {
172191 ) ) ) ,
173192 } ) ;
174193 } else {
175- button = new Button ( elements . buttonsContainer , buttonOptions ) ;
194+ button = new Button ( elements . buttons , buttonOptions ) ;
176195 }
177196
178197 this . _register ( button ) ;
@@ -182,6 +201,24 @@ abstract class BaseChatConfirmationWidget extends Disposable {
182201 this . _register ( buttonData . onDidChangeDisablement ( disabled => button . enabled = ! disabled ) ) ;
183202 }
184203 } ) ;
204+
205+ // Create toolbar if actions are provided
206+ if ( options ?. toolbarData ) {
207+ const overlay = contextKeyService . createOverlay ( [ [ 'chatConfirmationPartType' , options . toolbarData . partType ] ] ) ;
208+ const nestedInsta = this . _register ( instantiationService . createChild ( new ServiceCollection ( [ IContextKeyService , overlay ] ) ) ) ;
209+ this . _register ( nestedInsta . createInstance (
210+ MenuWorkbenchToolBar ,
211+ elements . toolbar ,
212+ MenuId . ChatConfirmationMenu ,
213+ {
214+ // buttonConfigProvider: () => ({ showLabel: false, showIcon: true }),
215+ menuOptions : {
216+ arg : options . toolbarData . arg ,
217+ shouldForwardArgs : true ,
218+ }
219+ }
220+ ) ) ;
221+ }
185222 }
186223
187224 protected renderMessage ( element : HTMLElement , listContainer : HTMLElement ) : void {
@@ -224,24 +261,21 @@ abstract class BaseChatConfirmationWidget extends Disposable {
224261 }
225262 }
226263}
227-
228264export class ChatConfirmationWidget extends BaseChatConfirmationWidget {
229265 private _renderedMessage : HTMLElement | undefined ;
230266
231267 constructor (
232- title : string | IMarkdownString ,
233- subtitle : string | IMarkdownString | undefined ,
234- message : string | IMarkdownString ,
235- buttons : IChatConfirmationButton [ ] ,
236268 private readonly _container : HTMLElement ,
269+ options : IChatConfirmationWidgetOptions & { message : string | IMarkdownString } ,
237270 @IInstantiationService instantiationService : IInstantiationService ,
238271 @IContextMenuService contextMenuService : IContextMenuService ,
239272 @IConfigurationService configurationService : IConfigurationService ,
240273 @IHostService hostService : IHostService ,
241- @IViewsService viewsService : IViewsService
274+ @IViewsService viewsService : IViewsService ,
275+ @IContextKeyService contextKeyService : IContextKeyService ,
242276 ) {
243- super ( title , subtitle , buttons , instantiationService , contextMenuService , configurationService , hostService , viewsService ) ;
244- this . updateMessage ( message ) ;
277+ super ( options , instantiationService , contextMenuService , configurationService , hostService , viewsService , contextKeyService ) ;
278+ this . updateMessage ( options . message ) ;
245279 }
246280
247281 public updateMessage ( message : string | IMarkdownString ) : void {
@@ -257,18 +291,16 @@ export class ChatConfirmationWidget extends BaseChatConfirmationWidget {
257291
258292export class ChatCustomConfirmationWidget extends BaseChatConfirmationWidget {
259293 constructor (
260- title : string | IMarkdownString ,
261- subtitle : string | IMarkdownString | undefined ,
262- messageElement : HTMLElement ,
263- buttons : IChatConfirmationButton [ ] ,
264294 container : HTMLElement ,
295+ options : IChatConfirmationWidgetOptions & { message : HTMLElement } ,
265296 @IInstantiationService instantiationService : IInstantiationService ,
266297 @IContextMenuService contextMenuService : IContextMenuService ,
267298 @IConfigurationService configurationService : IConfigurationService ,
268299 @IHostService hostService : IHostService ,
269- @IViewsService viewsService : IViewsService
300+ @IViewsService viewsService : IViewsService ,
301+ @IContextKeyService contextKeyService : IContextKeyService ,
270302 ) {
271- super ( title , subtitle , buttons , instantiationService , contextMenuService , configurationService , hostService , viewsService ) ;
272- this . renderMessage ( messageElement , container ) ;
303+ super ( options , instantiationService , contextMenuService , configurationService , hostService , viewsService , contextKeyService ) ;
304+ this . renderMessage ( options . message , container ) ;
273305 }
274306}
0 commit comments