2
2
* Copyright (C) Microsoft Corporation. All rights reserved.
3
3
*--------------------------------------------------------*/
4
4
5
- import vscode = require( ' vscode' ) ;
5
+ import vscode = require( " vscode" ) ;
6
6
import QuickPickItem = vscode . QuickPickItem ;
7
- const figures = require ( ' figures' ) ;
7
+ const figures : any = require ( " figures" ) ;
8
8
9
- export interface Option {
9
+ export interface ICheckboxOption {
10
10
name : string ;
11
11
isSelected : boolean ;
12
12
}
13
13
14
14
export class CheckboxQuickPick {
15
- private options : Option [ ] ;
15
+ private options : ICheckboxOption [ ] ;
16
16
private readonly confirm : string ;
17
17
private readonly checkboxOn : string ;
18
18
private readonly checkboxOff : string ;
19
19
private readonly confirmPlaceHolder : string ;
20
20
21
- constructor ( options : Option [ ] ) {
21
+ constructor ( options : ICheckboxOption [ ] ) {
22
22
this . options = options ;
23
23
this . confirm = figures . tick ;
24
24
this . checkboxOn = "[ x ]" ;
25
25
this . checkboxOff = "[ ]" ;
26
26
this . confirmPlaceHolder = "Select " + this . confirm + " to confirm" ;
27
27
}
28
28
29
- public show ( callback : ( options : Option [ ] ) => void ) {
30
- let tempOptions = this . options . slice ( ) ;
29
+ public show ( callback : ( options : ICheckboxOption [ ] ) => void ) : void {
30
+ let tempOptions : ICheckboxOption [ ] = this . options . slice ( ) ;
31
31
this . showInner ( tempOptions , callback ) ;
32
32
}
33
33
34
- private showInner ( tempOptions : Option [ ] , callback : ( options : Option [ ] ) => void ) {
34
+ private showInner ( tempOptions : ICheckboxOption [ ] , callback : ( options : ICheckboxOption [ ] ) => void ) : void {
35
35
vscode . window . showQuickPick (
36
36
this . getQuickPickItems ( tempOptions ) ,
37
37
{ ignoreFocusOut : true , placeHolder : this . confirmPlaceHolder } ) . then ( ( selection ) => {
@@ -45,18 +45,17 @@ export class CheckboxQuickPick {
45
45
return ;
46
46
}
47
47
48
- let index = this . getRuleIndex ( tempOptions , selection . description ) ;
49
- // this.toggleOption(tempOptions[index]);
50
- tempOptions [ index ] . isSelected = this . toggleState ( tempOptions [ index ] . isSelected ) ;
48
+ let index : number = this . getRuleIndex ( tempOptions , selection . description ) ;
49
+ this . toggleOption ( tempOptions [ index ] ) ;
51
50
this . showInner ( tempOptions , callback ) ;
52
51
} ) ;
53
52
}
54
53
55
- private getRuleIndex ( options : Option [ ] , optionLabel : string ) {
54
+ private getRuleIndex ( options : ICheckboxOption [ ] , optionLabel : string ) : number {
56
55
return options . findIndex ( opt => opt . name == optionLabel ) ;
57
56
}
58
57
59
- private getQuickPickItems ( tempOptions : Option [ ] ) : QuickPickItem [ ] {
58
+ private getQuickPickItems ( tempOptions : ICheckboxOption [ ] ) : QuickPickItem [ ] {
60
59
let quickPickItems : QuickPickItem [ ] = [ ] ;
61
60
tempOptions . forEach ( option =>
62
61
quickPickItems . push ( {
@@ -70,14 +69,14 @@ export class CheckboxQuickPick {
70
69
return checkBox == this . checkboxOn ;
71
70
}
72
71
73
- private toggleOption ( option : Option ) {
74
- option . isSelected = this . toggleState ( option . isSelected ) ;
75
- }
76
-
77
72
private toggleState ( state : boolean ) : boolean {
78
73
return ! state ;
79
74
}
80
75
76
+ private toggleOption ( option : ICheckboxOption ) : void {
77
+ option . isSelected = this . toggleState ( option . isSelected ) ;
78
+ }
79
+
81
80
private toggleCheckBox ( checkBox : string ) : string {
82
81
return this . convertToCheckBox ( this . toggleState ( this . convertToState ( checkBox ) ) ) ;
83
82
}
0 commit comments