@@ -11,83 +11,76 @@ export class CheckboxQuickPickItem {
11
11
}
12
12
13
13
export class CheckboxQuickPick {
14
- private options : CheckboxQuickPickItem [ ] ;
15
- private readonly confirm : string ;
16
- private readonly checkboxOn : string ;
17
- private readonly checkboxOff : string ;
18
- private readonly confirmPlaceHolder : string ;
14
+ private static readonly confirm : string = "$(check)" ;
15
+ private static readonly checkboxOn : string = "[ x ]" ;
16
+ private static readonly checkboxOff : string = "[ ]" ;
17
+ private static readonly confirmPlaceHolder : string = "Select 'Confirm' to confirm change; Press 'esc' key to cancel changes" ;
19
18
20
- constructor ( options : CheckboxQuickPickItem [ ] ) {
21
- this . options = options ;
22
- this . confirm = "$(check)" ;
23
- this . checkboxOn = "[ x ]" ;
24
- this . checkboxOff = "[ ]" ;
25
- this . confirmPlaceHolder = "Select 'Confirm' to confirm change; Press 'esc' key to cancel changes" ;
19
+ public static show (
20
+ checkboxQuickPickItems : CheckboxQuickPickItem [ ] ,
21
+ callback : ( items : CheckboxQuickPickItem [ ] ) => void ) : void {
22
+ CheckboxQuickPick . showInner ( checkboxQuickPickItems . slice ( ) , callback ) ;
26
23
}
27
24
28
- public show ( callback : ( options : CheckboxQuickPickItem [ ] ) => void ) : void {
29
- let tempOptions : CheckboxQuickPickItem [ ] = this . options . slice ( ) ;
30
- this . showInner ( tempOptions , callback ) ;
31
- }
32
-
33
- private showInner (
25
+ private static showInner (
34
26
tempOptions : CheckboxQuickPickItem [ ] ,
35
27
callback : ( options : CheckboxQuickPickItem [ ] ) => void ) : void {
36
28
vscode . window . showQuickPick (
37
- this . getQuickPickItems ( tempOptions ) ,
38
- { ignoreFocusOut : true , placeHolder : this . confirmPlaceHolder } ) . then ( ( selection ) => {
29
+ CheckboxQuickPick . getQuickPickItems ( tempOptions ) ,
30
+ { ignoreFocusOut : true , placeHolder : CheckboxQuickPick . confirmPlaceHolder } ) . then ( ( selection ) => {
39
31
if ( ! selection ) {
40
32
return ;
41
33
}
42
34
43
- if ( selection . label == this . confirm ) {
35
+ if ( selection . label === CheckboxQuickPick . confirm ) {
44
36
callback ( tempOptions ) ;
45
- this . options = tempOptions ;
46
37
return ;
47
38
}
48
39
49
- let index : number = this . getRuleIndex ( tempOptions , selection . description ) ;
50
- this . toggleOption ( tempOptions [ index ] ) ;
51
- this . showInner ( tempOptions , callback ) ;
40
+ let index : number = CheckboxQuickPick . getRuleIndex ( tempOptions , selection . description ) ;
41
+ CheckboxQuickPick . toggleOption ( tempOptions [ index ] ) ;
42
+ CheckboxQuickPick . showInner ( tempOptions , callback ) ;
52
43
} ) ;
53
44
}
54
45
55
- private getRuleIndex ( options : CheckboxQuickPickItem [ ] , optionLabel : string ) : number {
46
+ private static getRuleIndex ( options : CheckboxQuickPickItem [ ] , optionLabel : string ) : number {
56
47
return options . findIndex ( opt => opt . name == optionLabel ) ;
57
48
}
58
49
59
- private getQuickPickItems ( tempOptions : CheckboxQuickPickItem [ ] ) : QuickPickItem [ ] {
50
+ private static getQuickPickItems ( tempOptions : CheckboxQuickPickItem [ ] ) : QuickPickItem [ ] {
60
51
let quickPickItems : QuickPickItem [ ] = [ ] ;
61
- quickPickItems . push ( { label : this . confirm , description : "Confirm" } ) ;
52
+ quickPickItems . push ( { label : CheckboxQuickPick . confirm , description : "Confirm" } ) ;
62
53
tempOptions . forEach ( option =>
63
54
quickPickItems . push ( {
64
- label : this . convertToCheckBox ( option . isSelected ) , description : option . name
55
+ label : CheckboxQuickPick . convertToCheckBox ( option . isSelected ) , description : option . name
65
56
} ) ) ;
66
57
return quickPickItems ;
67
58
}
68
59
69
- private convertToState ( checkBox : string ) : boolean {
70
- return checkBox == this . checkboxOn ;
60
+ private static convertToState ( checkBox : string ) : boolean {
61
+ return checkBox === CheckboxQuickPick . checkboxOn ;
71
62
}
72
63
73
- private toggleState ( state : boolean ) : boolean {
64
+ private static toggleState ( state : boolean ) : boolean {
74
65
return ! state ;
75
66
}
76
67
77
- private toggleOption ( option : CheckboxQuickPickItem ) : void {
78
- option . isSelected = this . toggleState ( option . isSelected ) ;
68
+ private static toggleOption ( option : CheckboxQuickPickItem ) : void {
69
+ option . isSelected = CheckboxQuickPick . toggleState ( option . isSelected ) ;
79
70
}
80
71
81
- private toggleCheckBox ( checkBox : string ) : string {
82
- return this . convertToCheckBox ( this . toggleState ( this . convertToState ( checkBox ) ) ) ;
72
+ private static toggleCheckBox ( checkBox : string ) : string {
73
+ return CheckboxQuickPick . convertToCheckBox (
74
+ CheckboxQuickPick . toggleState (
75
+ CheckboxQuickPick . convertToState ( checkBox ) ) ) ;
83
76
}
84
77
85
- private convertToCheckBox ( state : boolean ) : string {
78
+ private static convertToCheckBox ( state : boolean ) : string {
86
79
if ( state ) {
87
- return this . checkboxOn ;
80
+ return CheckboxQuickPick . checkboxOn ;
88
81
}
89
82
else {
90
- return this . checkboxOff ;
83
+ return CheckboxQuickPick . checkboxOff ;
91
84
}
92
85
}
93
86
}
0 commit comments