6
6
fileChangedLabelInfoStyle ,
7
7
fileChangedLabelStyle ,
8
8
fileStyle ,
9
+ gitMarkBoxStyle ,
9
10
selectedFileChangedLabelStyle ,
10
11
selectedFileStyle
11
12
} from '../style/FileItemStyle' ;
@@ -27,11 +28,18 @@ export const STATUS_CODES = {
27
28
28
29
export interface IFileItemProps {
29
30
actions ?: React . ReactElement ;
30
- contextMenu : ( event : React . MouseEvent ) => void ;
31
+ contextMenu ? : ( event : React . MouseEvent ) => void ;
31
32
file : Git . IStatusFile ;
33
+ markBox ?: boolean ;
32
34
model : GitExtension ;
33
- selected : boolean ;
34
- selectFile : ( file : Git . IStatusFile | null ) => void ;
35
+ selected ?: boolean ;
36
+ selectFile ?: ( file : Git . IStatusFile | null ) => void ;
37
+ }
38
+
39
+ export interface IGitMarkBoxProps {
40
+ fname : string ;
41
+ model : GitExtension ;
42
+ stage : string ;
35
43
}
36
44
37
45
export class FileItem extends React . Component < IFileItemProps > {
@@ -73,16 +81,31 @@ export class FileItem extends React.Component<IFileItemProps> {
73
81
return (
74
82
< li
75
83
className = { this . getFileClass ( ) }
76
- onClick = { ( ) => this . props . selectFile ( this . props . file ) }
77
- onContextMenu = { event => {
78
- this . props . selectFile ( this . props . file ) ;
79
- this . props . contextMenu ( event ) ;
80
- } }
84
+ onClick = {
85
+ this . props . selectFile &&
86
+ ( ( ) => this . props . selectFile ( this . props . file ) )
87
+ }
88
+ onContextMenu = {
89
+ this . props . contextMenu &&
90
+ ( event => {
91
+ if ( this . props . selectFile ) {
92
+ this . props . selectFile ( this . props . file ) ;
93
+ }
94
+ this . props . contextMenu ( event ) ;
95
+ } )
96
+ }
81
97
onDoubleClick = { ( ) => {
82
98
openListedFile ( this . props . file , this . props . model ) ;
83
99
} }
84
100
title = { `${ this . props . file . to } ● ${ status } ` }
85
101
>
102
+ { this . props . markBox && (
103
+ < GitMarkBox
104
+ fname = { this . props . file . to }
105
+ stage = { this . props . file . status }
106
+ model = { this . props . model }
107
+ />
108
+ ) }
86
109
< FilePath
87
110
filepath = { this . props . file . to }
88
111
selected = { this . props . selected }
@@ -97,3 +120,35 @@ export class FileItem extends React.Component<IFileItemProps> {
97
120
) ;
98
121
}
99
122
}
123
+
124
+ export class GitMarkBox extends React . Component < IGitMarkBoxProps > {
125
+ constructor ( props : IGitMarkBoxProps ) {
126
+ super ( props ) ;
127
+ }
128
+
129
+ protected _onClick = ( event : React . ChangeEvent < HTMLInputElement > ) => {
130
+ // toggle will emit a markChanged signal
131
+ this . props . model . toggleMark ( this . props . fname ) ;
132
+
133
+ // needed if markChanged doesn't force an update of a parent
134
+ this . forceUpdate ( ) ;
135
+ } ;
136
+
137
+ render ( ) {
138
+ // idempotent, will only run once per file
139
+ this . props . model . addMark (
140
+ this . props . fname ,
141
+ this . props . stage !== 'untracked'
142
+ ) ;
143
+
144
+ return (
145
+ < input
146
+ name = "gitMark"
147
+ className = { gitMarkBoxStyle }
148
+ type = "checkbox"
149
+ checked = { this . props . model . getMark ( this . props . fname ) }
150
+ onChange = { this . _onClick }
151
+ />
152
+ ) ;
153
+ }
154
+ }
0 commit comments