@@ -16,7 +16,7 @@ import { Color } from 'vs/base/common/color';
16
16
import { Event as BaseEvent , Emitter } from 'vs/base/common/event' ;
17
17
import { IMarkdownString , isMarkdownString , markdownStringEqual } from 'vs/base/common/htmlContent' ;
18
18
import { KeyCode } from 'vs/base/common/keyCodes' ;
19
- import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
19
+ import { Disposable , DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
20
20
import { ThemeIcon } from 'vs/base/common/themables' ;
21
21
import 'vs/css!./button' ;
22
22
import { localize } from 'vs/nls' ;
@@ -89,6 +89,7 @@ export class Button extends Disposable implements IButton {
89
89
this . _element . tabIndex = 0 ;
90
90
this . _element . setAttribute ( 'role' , 'button' ) ;
91
91
92
+ this . _element . classList . toggle ( 'secondary' , ! ! options . secondary ) ;
92
93
const background = options . secondary ? options . buttonSecondaryBackground : options . buttonBackground ;
93
94
const foreground = options . secondary ? options . buttonSecondaryForeground : options . buttonForeground ;
94
95
@@ -154,6 +155,11 @@ export class Button extends Disposable implements IButton {
154
155
this . _register ( this . focusTracker . onDidBlur ( ( ) => { if ( this . enabled ) { this . updateBackground ( false ) ; } } ) ) ;
155
156
}
156
157
158
+ public override dispose ( ) : void {
159
+ super . dispose ( ) ;
160
+ this . _element . remove ( ) ;
161
+ }
162
+
157
163
private getContentElements ( content : string ) : HTMLElement [ ] {
158
164
const elements : HTMLSpanElement [ ] = [ ] ;
159
165
for ( let segment of renderLabelWithIcons ( content ) ) {
@@ -281,7 +287,7 @@ export class Button extends Disposable implements IButton {
281
287
282
288
export interface IButtonWithDropdownOptions extends IButtonOptions {
283
289
readonly contextMenuProvider : IContextMenuProvider ;
284
- readonly actions : IAction [ ] ;
290
+ readonly actions : readonly IAction [ ] ;
285
291
readonly actionRunner ?: IActionRunner ;
286
292
readonly addPrimaryActionToDropdown ?: boolean ;
287
293
}
@@ -344,6 +350,11 @@ export class ButtonWithDropdown extends Disposable implements IButton {
344
350
} ) ) ;
345
351
}
346
352
353
+ override dispose ( ) {
354
+ super . dispose ( ) ;
355
+ this . element . remove ( ) ;
356
+ }
357
+
347
358
set label ( value : string ) {
348
359
this . button . label = value ;
349
360
this . action . label = value ;
@@ -433,32 +444,42 @@ export class ButtonWithDescription implements IButtonWithDescription {
433
444
}
434
445
}
435
446
436
- export class ButtonBar extends Disposable {
447
+ export class ButtonBar {
437
448
438
- private _buttons : IButton [ ] = [ ] ;
449
+ private readonly _buttons : IButton [ ] = [ ] ;
450
+ private readonly _buttonStore = new DisposableStore ( ) ;
439
451
440
452
constructor ( private readonly container : HTMLElement ) {
441
- super ( ) ;
453
+
454
+ }
455
+
456
+ dispose ( ) : void {
457
+ this . _buttonStore . dispose ( ) ;
442
458
}
443
459
444
460
get buttons ( ) : IButton [ ] {
445
461
return this . _buttons ;
446
462
}
447
463
464
+ clear ( ) : void {
465
+ this . _buttonStore . clear ( ) ;
466
+ this . _buttons . length = 0 ;
467
+ }
468
+
448
469
addButton ( options : IButtonOptions ) : IButton {
449
- const button = this . _register ( new Button ( this . container , options ) ) ;
470
+ const button = this . _buttonStore . add ( new Button ( this . container , options ) ) ;
450
471
this . pushButton ( button ) ;
451
472
return button ;
452
473
}
453
474
454
475
addButtonWithDescription ( options : IButtonOptions ) : IButtonWithDescription {
455
- const button = this . _register ( new ButtonWithDescription ( this . container , options ) ) ;
476
+ const button = this . _buttonStore . add ( new ButtonWithDescription ( this . container , options ) ) ;
456
477
this . pushButton ( button ) ;
457
478
return button ;
458
479
}
459
480
460
481
addButtonWithDropdown ( options : IButtonWithDropdownOptions ) : IButton {
461
- const button = this . _register ( new ButtonWithDropdown ( this . container , options ) ) ;
482
+ const button = this . _buttonStore . add ( new ButtonWithDropdown ( this . container , options ) ) ;
462
483
this . pushButton ( button ) ;
463
484
return button ;
464
485
}
@@ -467,7 +488,7 @@ export class ButtonBar extends Disposable {
467
488
this . _buttons . push ( button ) ;
468
489
469
490
const index = this . _buttons . length - 1 ;
470
- this . _register ( addDisposableListener ( button . element , EventType . KEY_DOWN , e => {
491
+ this . _buttonStore . add ( addDisposableListener ( button . element , EventType . KEY_DOWN , e => {
471
492
const event = new StandardKeyboardEvent ( e ) ;
472
493
let eventHandled = true ;
473
494
0 commit comments