4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as DOM from 'vs/base/browser/dom' ;
7
+ import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate' ;
8
+ import { ICustomHover , setupCustomHover } from 'vs/base/browser/ui/iconLabel/iconLabelHover' ;
7
9
import { Toggle } from 'vs/base/browser/ui/toggle/toggle' ;
8
10
import { Codicon } from 'vs/base/common/codicons' ;
9
11
import { Emitter , Event } from 'vs/base/common/event' ;
@@ -25,13 +27,14 @@ export class TreeItemCheckbox extends Disposable {
25
27
public toggle : Toggle | undefined ;
26
28
private checkboxContainer : HTMLDivElement ;
27
29
public isDisposed = false ;
30
+ private hover : ICustomHover | undefined ;
28
31
29
32
public static readonly checkboxClass = 'custom-view-tree-node-item-checkbox' ;
30
33
31
34
private readonly _onDidChangeState = new Emitter < boolean > ( ) ;
32
35
readonly onDidChangeState : Event < boolean > = this . _onDidChangeState . event ;
33
36
34
- constructor ( container : HTMLElement , private checkboxStateHandler : CheckboxStateHandler ) {
37
+ constructor ( container : HTMLElement , private checkboxStateHandler : CheckboxStateHandler , private readonly hoverDelegate : IHoverDelegate ) {
35
38
super ( ) ;
36
39
this . checkboxContainer = < HTMLDivElement > container ;
37
40
}
@@ -52,10 +55,11 @@ export class TreeItemCheckbox extends Disposable {
52
55
if ( node . checkbox ) {
53
56
this . toggle = new Toggle ( {
54
57
isChecked : node . checkbox . isChecked ,
55
- title : this . createCheckboxTitle ( node . checkbox ) ,
58
+ title : '' ,
56
59
icon : node . checkbox . isChecked ? Codicon . check : undefined ,
57
60
...defaultToggleStyles
58
61
} ) ;
62
+ this . setHover ( node . checkbox ) ;
59
63
this . setAccessibilityInformation ( node . checkbox ) ;
60
64
this . toggle . domNode . classList . add ( TreeItemCheckbox . checkboxClass ) ;
61
65
DOM . append ( this . checkboxContainer , this . toggle . domNode ) ;
@@ -73,17 +77,29 @@ export class TreeItemCheckbox extends Disposable {
73
77
}
74
78
}
75
79
80
+ private setHover ( checkbox : ITreeItemCheckboxState ) {
81
+ if ( this . toggle ) {
82
+ if ( ! this . hover ) {
83
+ this . hover = setupCustomHover ( this . hoverDelegate , this . toggle . domNode , this . checkboxHoverContent ( checkbox ) ) ;
84
+ this . _register ( this . hover ) ;
85
+ } else {
86
+ this . hover . update ( checkbox . tooltip ) ;
87
+ }
88
+ }
89
+ }
90
+
76
91
private setCheckbox ( node : ITreeItem ) {
77
92
if ( this . toggle && node . checkbox ) {
78
93
node . checkbox . isChecked = this . toggle . checked ;
79
94
this . toggle . setIcon ( this . toggle . checked ? Codicon . check : undefined ) ;
80
- this . toggle . setTitle ( this . createCheckboxTitle ( node . checkbox ) ) ;
95
+ this . setHover ( node . checkbox ) ;
96
+
81
97
this . setAccessibilityInformation ( node . checkbox ) ;
82
98
this . checkboxStateHandler . setCheckboxState ( node ) ;
83
99
}
84
100
}
85
101
86
- private createCheckboxTitle ( checkbox : ITreeItemCheckboxState ) {
102
+ private checkboxHoverContent ( checkbox : ITreeItemCheckboxState ) : string {
87
103
return checkbox . tooltip ? checkbox . tooltip :
88
104
checkbox . isChecked ? localize ( 'checked' , 'Checked' ) : localize ( 'unchecked' , 'Unchecked' ) ;
89
105
}
0 commit comments