@@ -325,6 +325,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
325
325
}
326
326
327
327
private _renderStaged ( files : Git . IStatusFile [ ] ) {
328
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
329
+ . composite as boolean ;
328
330
return (
329
331
< GitStage
330
332
actions = {
@@ -341,12 +343,22 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
341
343
nFiles = { files . length }
342
344
>
343
345
{ files . map ( ( file : Git . IStatusFile ) => {
346
+ const openFile = ( ) => {
347
+ openListedFile ( file , this . props . model ) ;
348
+ } ;
349
+ const diffButton = this . _createDiffButton ( file , 'INDEX' ) ;
344
350
return (
345
351
< FileItem
346
352
key = { file . to }
347
353
actions = {
348
354
< React . Fragment >
349
- { this . _maybeCreateDiffButton ( file , 'INDEX' ) }
355
+ < ActionButton
356
+ className = { hiddenButtonStyle }
357
+ iconName = { 'open-file' }
358
+ title = { 'Open this file' }
359
+ onClick = { openFile }
360
+ />
361
+ { diffButton }
350
362
< ActionButton
351
363
className = { hiddenButtonStyle }
352
364
iconName = { 'git-remove' }
@@ -362,7 +374,13 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
362
374
model = { this . props . model }
363
375
selected = { this . _isSelectedFile ( file ) }
364
376
selectFile = { this . updateSelectedFile }
365
- onDoubleClick = { this . _onDoubleClickFactory ( file , 'WORKING' ) }
377
+ onDoubleClick = {
378
+ doubleClickDiff
379
+ ? diffButton
380
+ ? ( ) => this . _openDiffView ( file , 'INDEX' )
381
+ : ( ) => undefined
382
+ : openFile
383
+ }
366
384
/>
367
385
) ;
368
386
} ) }
@@ -371,6 +389,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
371
389
}
372
390
373
391
private _renderChanged ( files : Git . IStatusFile [ ] ) {
392
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
393
+ . composite as boolean ;
374
394
const disabled = files . length === 0 ;
375
395
return (
376
396
< GitStage
@@ -397,11 +417,22 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
397
417
nFiles = { files . length }
398
418
>
399
419
{ files . map ( ( file : Git . IStatusFile ) => {
420
+ const openFile = ( ) => {
421
+ openListedFile ( file , this . props . model ) ;
422
+ } ;
423
+ const diffButton = this . _createDiffButton ( file , 'WORKING' ) ;
400
424
return (
401
425
< FileItem
402
426
key = { file . to }
403
427
actions = {
404
428
< React . Fragment >
429
+ < ActionButton
430
+ className = { hiddenButtonStyle }
431
+ iconName = { 'open-file' }
432
+ title = { 'Open this file' }
433
+ onClick = { openFile }
434
+ />
435
+ { diffButton }
405
436
< ActionButton
406
437
className = { hiddenButtonStyle }
407
438
iconName = { 'git-discard' }
@@ -410,7 +441,6 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
410
441
this . discardChanges ( file . to ) ;
411
442
} }
412
443
/>
413
- { this . _maybeCreateDiffButton ( file , 'WORKING' ) }
414
444
< ActionButton
415
445
className = { hiddenButtonStyle }
416
446
iconName = { 'git-add' }
@@ -426,7 +456,13 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
426
456
model = { this . props . model }
427
457
selected = { this . _isSelectedFile ( file ) }
428
458
selectFile = { this . updateSelectedFile }
429
- onDoubleClick = { this . _onDoubleClickFactory ( file , 'WORKING' ) }
459
+ onDoubleClick = {
460
+ doubleClickDiff
461
+ ? diffButton
462
+ ? ( ) => this . _openDiffView ( file , 'WORKING' )
463
+ : ( ) => undefined
464
+ : openFile
465
+ }
430
466
/>
431
467
) ;
432
468
} ) }
@@ -435,6 +471,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
435
471
}
436
472
437
473
private _renderUntracked ( files : Git . IStatusFile [ ] ) {
474
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
475
+ . composite as boolean ;
438
476
return (
439
477
< GitStage
440
478
actions = {
@@ -455,18 +493,33 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
455
493
< FileItem
456
494
key = { file . to }
457
495
actions = {
458
- < ActionButton
459
- className = { hiddenButtonStyle }
460
- iconName = { 'git-add' }
461
- title = { 'Track this file' }
462
- onClick = { ( ) => {
463
- this . addFile ( file . to ) ;
464
- } }
465
- />
496
+ < React . Fragment >
497
+ < ActionButton
498
+ className = { hiddenButtonStyle }
499
+ iconName = { 'open-file' }
500
+ title = { 'Open this file' }
501
+ onClick = { async ( ) => {
502
+ openListedFile ( file , this . props . model ) ;
503
+ } }
504
+ />
505
+ < ActionButton
506
+ className = { hiddenButtonStyle }
507
+ iconName = { 'git-add' }
508
+ title = { 'Track this file' }
509
+ onClick = { ( ) => {
510
+ this . addFile ( file . to ) ;
511
+ } }
512
+ />
513
+ </ React . Fragment >
466
514
}
467
515
file = { file }
468
516
contextMenu = { this . contextMenuUntracked }
469
517
model = { this . props . model }
518
+ onDoubleClick = { ( ) => {
519
+ if ( ! doubleClickDiff ) {
520
+ openListedFile ( file , this . props . model ) ;
521
+ }
522
+ } }
470
523
selected = { this . _isSelectedFile ( file ) }
471
524
selectFile = { this . updateSelectedFile }
472
525
/>
@@ -477,6 +530,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
477
530
}
478
531
479
532
private _renderSimpleStage ( files : Git . IStatusFile [ ] ) {
533
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
534
+ . composite as boolean ;
480
535
return (
481
536
< GitStage
482
537
actions = {
@@ -492,11 +547,35 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
492
547
nFiles = { files . length }
493
548
>
494
549
{ files . map ( ( file : Git . IStatusFile ) => {
495
- let actions = null ;
496
- let onDoubleClick = null ;
550
+ const openFile = ( ) => {
551
+ openListedFile ( file , this . props . model ) ;
552
+ } ;
553
+
554
+ // Default value for actions and double click
555
+ let actions : JSX . Element = (
556
+ < ActionButton
557
+ className = { hiddenButtonStyle }
558
+ iconName = { 'open-file' }
559
+ title = { 'Open this file' }
560
+ onClick = { openFile }
561
+ />
562
+ ) ;
563
+ let onDoubleClick = doubleClickDiff
564
+ ? ( ) : void => undefined
565
+ : openFile ;
566
+
567
+ let diffButton : JSX . Element ;
497
568
if ( file . status === 'unstaged' ) {
569
+ diffButton = this . _createDiffButton ( file , 'WORKING' ) ;
498
570
actions = (
499
571
< React . Fragment >
572
+ < ActionButton
573
+ className = { hiddenButtonStyle }
574
+ iconName = { 'open-file' }
575
+ title = { 'Open this file' }
576
+ onClick = { openFile }
577
+ />
578
+ { diffButton }
500
579
< ActionButton
501
580
className = { hiddenButtonStyle }
502
581
iconName = { 'git-discard' }
@@ -505,13 +584,31 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
505
584
this . discardChanges ( file . to ) ;
506
585
} }
507
586
/>
508
- { this . _maybeCreateDiffButton ( file , 'WORKING' ) }
509
587
</ React . Fragment >
510
588
) ;
511
- onDoubleClick = this . _onDoubleClickFactory ( file , 'WORKING' ) ;
589
+ onDoubleClick = doubleClickDiff
590
+ ? diffButton
591
+ ? ( ) => this . _openDiffView ( file , 'WORKING' )
592
+ : ( ) => undefined
593
+ : openFile ;
512
594
} else if ( file . status === 'staged' ) {
513
- actions = this . _maybeCreateDiffButton ( file , 'INDEX' ) ;
514
- onDoubleClick = this . _onDoubleClickFactory ( file , 'INDEX' ) ;
595
+ diffButton = this . _createDiffButton ( file , 'INDEX' ) ;
596
+ actions = (
597
+ < React . Fragment >
598
+ < ActionButton
599
+ className = { hiddenButtonStyle }
600
+ iconName = { 'open-file' }
601
+ title = { 'Open this file' }
602
+ onClick = { openFile }
603
+ />
604
+ { diffButton }
605
+ </ React . Fragment >
606
+ ) ;
607
+ onDoubleClick = doubleClickDiff
608
+ ? diffButton
609
+ ? ( ) => this . _openDiffView ( file , 'INDEX' )
610
+ : ( ) => undefined
611
+ : openFile ;
515
612
}
516
613
517
614
return (
@@ -536,81 +633,45 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
536
633
* @param path File path of interest
537
634
* @param currentRef the ref to diff against the git 'HEAD' ref
538
635
*/
539
- private _maybeCreateDiffButton (
636
+ private _createDiffButton (
540
637
file : Git . IStatusFile ,
541
638
currentRef : ISpecialRef [ 'specialRef' ]
542
639
) : JSX . Element {
543
- if ( this . props . settings . composite [ 'doubleClickDiff' ] ) {
544
- return (
640
+ return (
641
+ ( isDiffSupported ( file . to ) || ! file . is_binary ) && (
545
642
< ActionButton
546
643
className = { hiddenButtonStyle }
547
- iconName = { 'open-file' }
548
- title = { 'Open this file' }
549
- onClick = { async ( ) => {
550
- openListedFile ( file , this . props . model ) ;
551
- } }
644
+ iconName = { 'git-diff' }
645
+ title = { 'Diff this file' }
646
+ onClick = { ( ) => this . _openDiffView ( file , currentRef ) }
552
647
/>
553
- ) ;
554
- } else {
555
- return (
556
- ( isDiffSupported ( file . to ) || ! file . is_binary ) && (
557
- < ActionButton
558
- className = { hiddenButtonStyle }
559
- iconName = { 'git-diff' }
560
- title = { 'Diff this file' }
561
- onClick = { this . _openDiffViewFactory ( file , currentRef ) }
562
- />
563
- )
564
- ) ;
565
- }
648
+ )
649
+ ) ;
566
650
}
567
651
568
652
/**
569
653
* Returns a callback which opens a diff of the file
570
654
*
571
- * @param file
655
+ * @param file File to open diff for
572
656
* @param currentRef the ref to diff against the git 'HEAD' ref
573
657
*/
574
- private _openDiffViewFactory (
658
+ private async _openDiffView (
575
659
file : Git . IStatusFile ,
576
660
currentRef : ISpecialRef [ 'specialRef' ]
577
- ) {
578
- const self = this ;
579
- return genDiff ;
580
-
581
- async function genDiff ( ) {
582
- try {
583
- await openDiffView (
584
- file . to ,
585
- self . props . model ,
586
- {
587
- previousRef : { gitRef : 'HEAD' } ,
588
- currentRef : { specialRef : currentRef }
589
- } ,
590
- self . props . renderMime ,
591
- ! file . is_binary
592
- ) ;
593
- } catch ( reason ) {
594
- console . error ( `Fail to open diff view for ${ file . to } .\n${ reason } ` ) ;
595
- }
596
- }
597
- }
598
-
599
- /**
600
- * Returns a callback which is invoked upon double clicking a file
601
- *
602
- * @param file
603
- * @param currentRef the ref to diff against the current git 'HEAD' ref
604
- */
605
- private _onDoubleClickFactory (
606
- file : Git . IStatusFile ,
607
- currentRef : ISpecialRef [ 'specialRef' ]
608
- ) {
609
- if (
610
- this . props . settings . composite [ 'doubleClickDiff' ] &&
611
- ( isDiffSupported ( file . to ) || ! file . is_binary )
612
- ) {
613
- return this . _openDiffViewFactory ( file , currentRef ) ;
661
+ ) : Promise < void > {
662
+ try {
663
+ await openDiffView (
664
+ file . to ,
665
+ this . props . model ,
666
+ {
667
+ previousRef : { gitRef : 'HEAD' } ,
668
+ currentRef : { specialRef : currentRef }
669
+ } ,
670
+ this . props . renderMime ,
671
+ ! file . is_binary
672
+ ) ;
673
+ } catch ( reason ) {
674
+ console . error ( `Fail to open diff view for ${ file . to } .\n${ reason } ` ) ;
614
675
}
615
676
}
616
677
0 commit comments