@@ -12,9 +12,13 @@ import { IMarkdownString, MarkdownString } from '../../../../../base/common/html
12
12
import { Disposable , DisposableStore , MutableDisposable } from '../../../../../base/common/lifecycle.js' ;
13
13
import { IMarkdownRenderResult , MarkdownRenderer , openLinkFromMarkdown } from '../../../../../editor/browser/widget/markdownRenderer/browser/markdownRenderer.js' ;
14
14
import { localize } from '../../../../../nls.js' ;
15
+ import { MenuWorkbenchToolBar } from '../../../../../platform/actions/browser/toolbar.js' ;
16
+ import { MenuId } from '../../../../../platform/actions/common/actions.js' ;
15
17
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
18
+ import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js' ;
16
19
import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.js' ;
17
20
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js' ;
21
+ import { ServiceCollection } from '../../../../../platform/instantiation/common/serviceCollection.js' ;
18
22
import { FocusMode } from '../../../../../platform/native/common/native.js' ;
19
23
import { IOpenerService } from '../../../../../platform/opener/common/opener.js' ;
20
24
import { defaultButtonStyles } from '../../../../../platform/theme/browser/defaultStyles.js' ;
@@ -33,6 +37,13 @@ export interface IChatConfirmationButton {
33
37
moreActions ?: IChatConfirmationButton [ ] ;
34
38
}
35
39
40
+ export interface IChatConfirmationWidgetOptions {
41
+ title : string | IMarkdownString ;
42
+ subtitle ?: string | IMarkdownString ;
43
+ buttons : IChatConfirmationButton [ ] ;
44
+ toolbarData ?: { arg : any ; partType : string } ;
45
+ }
46
+
36
47
export class ChatQueryTitlePart extends Disposable {
37
48
private readonly _onDidChangeHeight = this . _register ( new Emitter < void > ( ) ) ;
38
49
public readonly onDidChangeHeight = this . _onDidChangeHeight . event ;
@@ -117,25 +128,31 @@ abstract class BaseChatConfirmationWidget extends Disposable {
117
128
118
129
private readonly messageElement : HTMLElement ;
119
130
protected readonly markdownRenderer : MarkdownRenderer ;
131
+ private readonly title : string | IMarkdownString ;
120
132
121
133
private readonly notification = this . _register ( new MutableDisposable < DisposableStore > ( ) ) ;
122
134
123
135
constructor (
124
- private title : string | IMarkdownString ,
125
- subtitle : string | IMarkdownString | undefined ,
126
- buttons : IChatConfirmationButton [ ] ,
136
+ options : IChatConfirmationWidgetOptions ,
127
137
@IInstantiationService protected readonly instantiationService : IInstantiationService ,
128
138
@IContextMenuService contextMenuService : IContextMenuService ,
129
139
@IConfigurationService private readonly _configurationService : IConfigurationService ,
130
140
@IHostService private readonly _hostService : IHostService ,
131
- @IViewsService private readonly _viewsService : IViewsService
141
+ @IViewsService private readonly _viewsService : IViewsService ,
142
+ @IContextKeyService contextKeyService : IContextKeyService ,
132
143
) {
133
144
super ( ) ;
134
145
146
+ const { title, subtitle, buttons } = options ;
147
+ this . title = title ;
148
+
135
149
const elements = dom . h ( '.chat-confirmation-widget@root' , [
136
150
dom . h ( '.chat-confirmation-widget-title@title' ) ,
137
151
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
+ ] ) ,
139
156
] ) ;
140
157
this . _domNode = elements . root ;
141
158
this . markdownRenderer = this . instantiationService . createInstance ( MarkdownRenderer , { } ) ;
@@ -151,12 +168,14 @@ abstract class BaseChatConfirmationWidget extends Disposable {
151
168
this . _register ( titlePart . onDidChangeHeight ( ( ) => this . _onDidChangeHeight . fire ( ) ) ) ;
152
169
153
170
this . messageElement = elements . message ;
171
+
172
+ // Create buttons
154
173
buttons . forEach ( buttonData => {
155
174
const buttonOptions : IButtonOptions = { ...defaultButtonStyles , secondary : buttonData . isSecondary , title : buttonData . tooltip , disabled : buttonData . disabled } ;
156
175
157
176
let button : IButton ;
158
177
if ( buttonData . moreActions ) {
159
- button = new ButtonWithDropdown ( elements . buttonsContainer , {
178
+ button = new ButtonWithDropdown ( elements . buttons , {
160
179
...buttonOptions ,
161
180
contextMenuProvider : contextMenuService ,
162
181
addPrimaryActionToDropdown : false ,
@@ -172,7 +191,7 @@ abstract class BaseChatConfirmationWidget extends Disposable {
172
191
) ) ) ,
173
192
} ) ;
174
193
} else {
175
- button = new Button ( elements . buttonsContainer , buttonOptions ) ;
194
+ button = new Button ( elements . buttons , buttonOptions ) ;
176
195
}
177
196
178
197
this . _register ( button ) ;
@@ -182,6 +201,24 @@ abstract class BaseChatConfirmationWidget extends Disposable {
182
201
this . _register ( buttonData . onDidChangeDisablement ( disabled => button . enabled = ! disabled ) ) ;
183
202
}
184
203
} ) ;
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
+ }
185
222
}
186
223
187
224
protected renderMessage ( element : HTMLElement , listContainer : HTMLElement ) : void {
@@ -224,24 +261,21 @@ abstract class BaseChatConfirmationWidget extends Disposable {
224
261
}
225
262
}
226
263
}
227
-
228
264
export class ChatConfirmationWidget extends BaseChatConfirmationWidget {
229
265
private _renderedMessage : HTMLElement | undefined ;
230
266
231
267
constructor (
232
- title : string | IMarkdownString ,
233
- subtitle : string | IMarkdownString | undefined ,
234
- message : string | IMarkdownString ,
235
- buttons : IChatConfirmationButton [ ] ,
236
268
private readonly _container : HTMLElement ,
269
+ options : IChatConfirmationWidgetOptions & { message : string | IMarkdownString } ,
237
270
@IInstantiationService instantiationService : IInstantiationService ,
238
271
@IContextMenuService contextMenuService : IContextMenuService ,
239
272
@IConfigurationService configurationService : IConfigurationService ,
240
273
@IHostService hostService : IHostService ,
241
- @IViewsService viewsService : IViewsService
274
+ @IViewsService viewsService : IViewsService ,
275
+ @IContextKeyService contextKeyService : IContextKeyService ,
242
276
) {
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 ) ;
245
279
}
246
280
247
281
public updateMessage ( message : string | IMarkdownString ) : void {
@@ -257,18 +291,16 @@ export class ChatConfirmationWidget extends BaseChatConfirmationWidget {
257
291
258
292
export class ChatCustomConfirmationWidget extends BaseChatConfirmationWidget {
259
293
constructor (
260
- title : string | IMarkdownString ,
261
- subtitle : string | IMarkdownString | undefined ,
262
- messageElement : HTMLElement ,
263
- buttons : IChatConfirmationButton [ ] ,
264
294
container : HTMLElement ,
295
+ options : IChatConfirmationWidgetOptions & { message : HTMLElement } ,
265
296
@IInstantiationService instantiationService : IInstantiationService ,
266
297
@IContextMenuService contextMenuService : IContextMenuService ,
267
298
@IConfigurationService configurationService : IConfigurationService ,
268
299
@IHostService hostService : IHostService ,
269
- @IViewsService viewsService : IViewsService
300
+ @IViewsService viewsService : IViewsService ,
301
+ @IContextKeyService contextKeyService : IContextKeyService ,
270
302
) {
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 ) ;
273
305
}
274
306
}
0 commit comments