@@ -44,6 +44,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
44
44
this . _contextMenuStaged = new Menu ( { commands } ) ;
45
45
this . _contextMenuUnstaged = new Menu ( { commands } ) ;
46
46
this . _contextMenuUntracked = new Menu ( { commands } ) ;
47
+ this . _contextMenuSimpleUntracked = new Menu ( { commands } ) ;
48
+ this . _contextMenuSimpleTracked = new Menu ( { commands } ) ;
47
49
48
50
this . state = {
49
51
selectedFile : null
@@ -134,7 +136,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
134
136
label : 'Discard' ,
135
137
caption : 'Discard recent changes of selected file' ,
136
138
execute : ( ) => {
137
- this . discardChanges ( this . state . selectedFile . to ) ;
139
+ this . discardChanges ( this . state . selectedFile ) ;
138
140
}
139
141
} ) ;
140
142
}
@@ -159,6 +161,18 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
159
161
[ CommandIDs . gitFileOpen , CommandIDs . gitFileTrack ] . forEach ( command => {
160
162
this . _contextMenuUntracked . addItem ( { command } ) ;
161
163
} ) ;
164
+
165
+ [
166
+ CommandIDs . gitFileOpen ,
167
+ CommandIDs . gitFileDiscard ,
168
+ CommandIDs . gitFileDiffWorking
169
+ ] . forEach ( command => {
170
+ this . _contextMenuSimpleTracked . addItem ( { command } ) ;
171
+ } ) ;
172
+
173
+ [ CommandIDs . gitFileOpen ] . forEach ( command => {
174
+ this . _contextMenuSimpleUntracked . addItem ( { command } ) ;
175
+ } ) ;
162
176
}
163
177
164
178
/** Handle right-click on a staged file */
@@ -179,6 +193,18 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
179
193
this . _contextMenuUntracked . open ( event . clientX , event . clientY ) ;
180
194
} ;
181
195
196
+ /** Handle right-click on an untracked file in Simple mode*/
197
+ contextMenuSimpleUntracked = ( event : React . MouseEvent ) => {
198
+ event . preventDefault ( ) ;
199
+ this . _contextMenuSimpleUntracked . open ( event . clientX , event . clientY ) ;
200
+ } ;
201
+
202
+ /** Handle right-click on an tracked file in Simple mode*/
203
+ contextMenuSimpleTracked = ( event : React . MouseEvent ) => {
204
+ event . preventDefault ( ) ;
205
+ this . _contextMenuSimpleTracked . open ( event . clientX , event . clientY ) ;
206
+ } ;
207
+
182
208
/** Reset all staged files */
183
209
resetAllStagedFiles = async ( ) => {
184
210
await this . props . model . reset ( ) ;
@@ -234,23 +260,31 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
234
260
} ;
235
261
236
262
/** Discard changes in a specific unstaged or staged file */
237
- discardChanges = async ( file : string ) => {
263
+ discardChanges = async ( file : Git . IStatusFile ) => {
238
264
const result = await showDialog ( {
239
265
title : 'Discard changes' ,
240
266
body : (
241
267
< span >
242
- Are you sure you want to permanently discard changes to < b > { file } </ b > ?
243
- This action cannot be undone.
268
+ Are you sure you want to permanently discard changes to{ ' ' }
269
+ < b > { file . to } </ b > ? This action cannot be undone.
244
270
</ span >
245
271
) ,
246
272
buttons : [ Dialog . cancelButton ( ) , Dialog . warnButton ( { label : 'Discard' } ) ]
247
273
} ) ;
248
274
if ( result . button . accept ) {
249
275
try {
250
- await this . props . model . reset ( file ) ;
251
- await this . props . model . checkout ( { filename : file } ) ;
276
+ if ( file . status === 'staged' || file . status === 'partially-staged' ) {
277
+ await this . props . model . reset ( file . to ) ;
278
+ }
279
+ if (
280
+ file . status === 'unstaged' ||
281
+ ( file . status === 'partially-staged' && file . x !== 'A' )
282
+ ) {
283
+ // resetting an added file moves it to untracked category => checkout will fail
284
+ await this . props . model . checkout ( { filename : file . to } ) ;
285
+ }
252
286
} catch ( reason ) {
253
- showErrorMessage ( `Discard changes for ${ file } failed.` , reason , [
287
+ showErrorMessage ( `Discard changes for ${ file . to } failed.` , reason , [
254
288
Dialog . warnButton ( { label : 'DISMISS' } )
255
289
] ) ;
256
290
}
@@ -297,6 +331,16 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
297
331
case 'untracked' :
298
332
untrackedFiles . push ( file ) ;
299
333
break ;
334
+ case 'partially-staged' :
335
+ stagedFiles . push ( {
336
+ ...file ,
337
+ status : 'staged'
338
+ } ) ;
339
+ unstagedFiles . push ( {
340
+ ...file ,
341
+ status : 'unstaged'
342
+ } ) ;
343
+ break ;
300
344
301
345
default :
302
346
break ;
@@ -325,7 +369,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
325
369
this . state . selectedFile . x === candidate . x &&
326
370
this . state . selectedFile . y === candidate . y &&
327
371
this . state . selectedFile . from === candidate . from &&
328
- this . state . selectedFile . to === candidate . to
372
+ this . state . selectedFile . to === candidate . to &&
373
+ this . state . selectedFile . status === candidate . status
329
374
) ;
330
375
}
331
376
@@ -443,7 +488,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
443
488
iconName = { 'git-discard' }
444
489
title = { 'Discard changes' }
445
490
onClick = { ( ) => {
446
- this . discardChanges ( file . to ) ;
491
+ this . discardChanges ( file ) ;
447
492
} }
448
493
/>
449
494
< ActionButton
@@ -569,9 +614,13 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
569
614
? ( ) : void => undefined
570
615
: openFile ;
571
616
572
- let diffButton : JSX . Element ;
573
- if ( file . status === 'unstaged' ) {
574
- diffButton = this . _createDiffButton ( file , 'WORKING' ) ;
617
+ let contextMenu = this . contextMenuSimpleUntracked ;
618
+
619
+ if (
620
+ file . status === 'unstaged' ||
621
+ file . status === 'partially-staged'
622
+ ) {
623
+ const diffButton = this . _createDiffButton ( file , 'WORKING' ) ;
575
624
actions = (
576
625
< React . Fragment >
577
626
< ActionButton
@@ -586,7 +635,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
586
635
iconName = { 'git-discard' }
587
636
title = { 'Discard changes' }
588
637
onClick = { ( ) => {
589
- this . discardChanges ( file . to ) ;
638
+ this . discardChanges ( file ) ;
590
639
} }
591
640
/>
592
641
</ React . Fragment >
@@ -596,8 +645,9 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
596
645
? ( ) => this . _openDiffView ( file , 'WORKING' )
597
646
: ( ) => undefined
598
647
: openFile ;
648
+ contextMenu = this . contextMenuSimpleTracked ;
599
649
} else if ( file . status === 'staged' ) {
600
- diffButton = this . _createDiffButton ( file , 'INDEX' ) ;
650
+ const diffButton = this . _createDiffButton ( file , 'INDEX' ) ;
601
651
actions = (
602
652
< React . Fragment >
603
653
< ActionButton
@@ -607,13 +657,22 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
607
657
onClick = { openFile }
608
658
/>
609
659
{ diffButton }
660
+ < ActionButton
661
+ className = { hiddenButtonStyle }
662
+ iconName = { 'git-discard' }
663
+ title = { 'Discard changes' }
664
+ onClick = { ( ) => {
665
+ this . discardChanges ( file ) ;
666
+ } }
667
+ />
610
668
</ React . Fragment >
611
669
) ;
612
670
onDoubleClick = doubleClickDiff
613
671
? diffButton
614
672
? ( ) => this . _openDiffView ( file , 'INDEX' )
615
673
: ( ) => undefined
616
674
: openFile ;
675
+ contextMenu = this . contextMenuSimpleTracked ;
617
676
}
618
677
619
678
return (
@@ -624,6 +683,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
624
683
markBox = { true }
625
684
model = { this . props . model }
626
685
onDoubleClick = { onDoubleClick }
686
+ contextMenu = { contextMenu }
687
+ selectFile = { this . updateSelectedFile }
627
688
/>
628
689
) ;
629
690
} ) }
@@ -683,4 +744,6 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
683
744
private _contextMenuStaged : Menu ;
684
745
private _contextMenuUnstaged : Menu ;
685
746
private _contextMenuUntracked : Menu ;
747
+ private _contextMenuSimpleTracked : Menu ;
748
+ private _contextMenuSimpleUntracked : Menu ;
686
749
}
0 commit comments