4
4
5
5
import vscode = require( "vscode" ) ;
6
6
7
- var confirmItemLabel : string = "$(checklist) Confirm" ;
8
- var checkedPrefix : string = "[ $(check) ]" ;
9
- var uncheckedPrefix : string = "[ ]" ;
10
- var defaultPlaceHolder : string = "Select 'Confirm' to confirm or press 'Esc' key to cancel" ;
7
+ const confirmItemLabel : string = "$(checklist) Confirm" ;
8
+ const checkedPrefix : string = "[ $(check) ]" ;
9
+ const uncheckedPrefix : string = "[ ]" ;
10
+ const defaultPlaceHolder : string = "Select 'Confirm' to confirm or press 'Esc' key to cancel" ;
11
11
12
- export interface CheckboxQuickPickItem {
12
+ export interface ICheckboxQuickPickItem {
13
13
label : string ;
14
14
description ?: string ;
15
15
isSelected : boolean ;
16
16
}
17
17
18
- export interface CheckboxQuickPickOptions {
18
+ export interface ICheckboxQuickPickOptions {
19
19
confirmPlaceHolder : string ;
20
20
}
21
21
22
- var defaultOptions :CheckboxQuickPickOptions = { confirmPlaceHolder : defaultPlaceHolder } ;
22
+ const defaultOptions : ICheckboxQuickPickOptions = { confirmPlaceHolder : defaultPlaceHolder } ;
23
23
24
24
export function showCheckboxQuickPick (
25
- items : CheckboxQuickPickItem [ ] ,
26
- options : CheckboxQuickPickOptions = defaultOptions ) : Thenable < CheckboxQuickPickItem [ ] > {
25
+ items : ICheckboxQuickPickItem [ ] ,
26
+ options : ICheckboxQuickPickOptions = defaultOptions ) : Thenable < ICheckboxQuickPickItem [ ] > {
27
27
28
28
return showInner ( items , options ) . then (
29
29
( selectedItem ) => {
30
30
// We're mutating the original item list so just return it for now.
31
31
// If 'selectedItem' is undefined it means the user cancelled the
32
32
// inner showQuickPick UI so pass the undefined along.
33
- return selectedItem != undefined ? items : undefined ;
34
- } )
33
+ return selectedItem !== undefined ? items : undefined ;
34
+ } ) ;
35
35
}
36
36
37
- function getQuickPickItems ( items : CheckboxQuickPickItem [ ] ) : vscode . QuickPickItem [ ] {
37
+ function getQuickPickItems ( items : ICheckboxQuickPickItem [ ] ) : vscode . QuickPickItem [ ] {
38
38
39
- let quickPickItems : vscode . QuickPickItem [ ] = [ ] ;
39
+ const quickPickItems : vscode . QuickPickItem [ ] = [ ] ;
40
40
quickPickItems . push ( { label : confirmItemLabel , description : "" } ) ;
41
41
42
- items . forEach ( item =>
42
+ items . forEach ( ( item ) =>
43
43
quickPickItems . push ( {
44
44
label : convertToCheckBox ( item ) ,
45
- description : item . description
45
+ description : item . description ,
46
46
} ) ) ;
47
47
48
48
return quickPickItems ;
49
49
}
50
50
51
51
function showInner (
52
- items : CheckboxQuickPickItem [ ] ,
53
- options : CheckboxQuickPickOptions ) : Thenable < vscode . QuickPickItem > {
52
+ items : ICheckboxQuickPickItem [ ] ,
53
+ options : ICheckboxQuickPickOptions ) : Thenable < vscode . QuickPickItem > {
54
54
55
- var quickPickThenable : Thenable < vscode . QuickPickItem > =
55
+ const quickPickThenable : Thenable < vscode . QuickPickItem > =
56
56
vscode . window . showQuickPick (
57
57
getQuickPickItems ( items ) ,
58
58
{
59
59
ignoreFocusOut : true ,
60
60
matchOnDescription : true ,
61
- placeHolder : options . confirmPlaceHolder
61
+ placeHolder : options . confirmPlaceHolder ,
62
62
} ) ;
63
63
64
64
return quickPickThenable . then (
65
65
( selection ) => {
66
66
if ( ! selection ) {
67
- //return Promise.reject<vscode.QuickPickItem>("showCheckBoxQuickPick cancelled")
68
67
return Promise . resolve < vscode . QuickPickItem > ( undefined ) ;
69
68
}
70
69
71
70
if ( selection . label === confirmItemLabel ) {
72
71
return selection ;
73
72
}
74
73
75
- let index : number = getItemIndex ( items , selection . label ) ;
74
+ const index : number = getItemIndex ( items , selection . label ) ;
76
75
77
76
if ( index >= 0 ) {
78
77
toggleSelection ( items [ index ] ) ;
79
- }
80
- else {
78
+ } else {
79
+ // tslint:disable-next-line:no-console
81
80
console . log ( `Couldn't find CheckboxQuickPickItem for label '${ selection . label } '` ) ;
82
81
}
83
82
84
83
return showInner ( items , options ) ;
85
84
} ) ;
86
85
}
87
86
88
- function getItemIndex ( items : CheckboxQuickPickItem [ ] , itemLabel : string ) : number {
89
- var trimmedLabel = itemLabel . substr ( itemLabel . indexOf ( "]" ) + 2 ) ;
90
- return items . findIndex ( item => item . label === trimmedLabel ) ;
87
+ function getItemIndex ( items : ICheckboxQuickPickItem [ ] , itemLabel : string ) : number {
88
+ const trimmedLabel = itemLabel . substr ( itemLabel . indexOf ( "]" ) + 2 ) ;
89
+ return items . findIndex ( ( item ) => item . label === trimmedLabel ) ;
91
90
}
92
91
93
- function toggleSelection ( item : CheckboxQuickPickItem ) : void {
92
+ function toggleSelection ( item : ICheckboxQuickPickItem ) : void {
94
93
item . isSelected = ! item . isSelected ;
95
94
}
96
95
97
- function convertToCheckBox ( item : CheckboxQuickPickItem ) : string {
96
+ function convertToCheckBox ( item : ICheckboxQuickPickItem ) : string {
98
97
return `${ item . isSelected ? checkedPrefix : uncheckedPrefix } ${ item . label } ` ;
99
- }
98
+ }
0 commit comments