@@ -330,6 +330,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
330
330
}
331
331
332
332
private _renderStaged ( files : Git . IStatusFile [ ] ) {
333
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
334
+ . composite as boolean ;
333
335
return (
334
336
< GitStage
335
337
actions = {
@@ -346,12 +348,22 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
346
348
nFiles = { files . length }
347
349
>
348
350
{ files . map ( ( file : Git . IStatusFile ) => {
351
+ const openFile = ( ) => {
352
+ openListedFile ( file , this . props . model ) ;
353
+ } ;
354
+ const diffButton = this . _createDiffButton ( file , 'INDEX' ) ;
349
355
return (
350
356
< FileItem
351
357
key = { file . to }
352
358
actions = {
353
359
< React . Fragment >
354
- { this . _createDiffButton ( file , 'INDEX' ) }
360
+ < ActionButton
361
+ className = { hiddenButtonStyle }
362
+ iconName = { 'open-file' }
363
+ title = { 'Open this file' }
364
+ onClick = { openFile }
365
+ />
366
+ { diffButton }
355
367
< ActionButton
356
368
className = { hiddenButtonStyle }
357
369
iconName = { 'git-remove' }
@@ -367,6 +379,13 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
367
379
model = { this . props . model }
368
380
selected = { this . _isSelectedFile ( file ) }
369
381
selectFile = { this . updateSelectedFile }
382
+ onDoubleClick = {
383
+ doubleClickDiff
384
+ ? diffButton
385
+ ? ( ) => this . _openDiffView ( file , 'INDEX' )
386
+ : ( ) => undefined
387
+ : openFile
388
+ }
370
389
/>
371
390
) ;
372
391
} ) }
@@ -375,6 +394,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
375
394
}
376
395
377
396
private _renderChanged ( files : Git . IStatusFile [ ] ) {
397
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
398
+ . composite as boolean ;
378
399
const disabled = files . length === 0 ;
379
400
return (
380
401
< GitStage
@@ -401,11 +422,22 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
401
422
nFiles = { files . length }
402
423
>
403
424
{ files . map ( ( file : Git . IStatusFile ) => {
425
+ const openFile = ( ) => {
426
+ openListedFile ( file , this . props . model ) ;
427
+ } ;
428
+ const diffButton = this . _createDiffButton ( file , 'WORKING' ) ;
404
429
return (
405
430
< FileItem
406
431
key = { file . to }
407
432
actions = {
408
433
< React . Fragment >
434
+ < ActionButton
435
+ className = { hiddenButtonStyle }
436
+ iconName = { 'open-file' }
437
+ title = { 'Open this file' }
438
+ onClick = { openFile }
439
+ />
440
+ { diffButton }
409
441
< ActionButton
410
442
className = { hiddenButtonStyle }
411
443
iconName = { 'git-discard' }
@@ -414,7 +446,6 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
414
446
this . discardChanges ( file . to ) ;
415
447
} }
416
448
/>
417
- { this . _createDiffButton ( file , 'WORKING' ) }
418
449
< ActionButton
419
450
className = { hiddenButtonStyle }
420
451
iconName = { 'git-add' }
@@ -430,6 +461,13 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
430
461
model = { this . props . model }
431
462
selected = { this . _isSelectedFile ( file ) }
432
463
selectFile = { this . updateSelectedFile }
464
+ onDoubleClick = {
465
+ doubleClickDiff
466
+ ? diffButton
467
+ ? ( ) => this . _openDiffView ( file , 'WORKING' )
468
+ : ( ) => undefined
469
+ : openFile
470
+ }
433
471
/>
434
472
) ;
435
473
} ) }
@@ -438,6 +476,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
438
476
}
439
477
440
478
private _renderUntracked ( files : Git . IStatusFile [ ] ) {
479
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
480
+ . composite as boolean ;
441
481
return (
442
482
< GitStage
443
483
actions = {
@@ -458,18 +498,33 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
458
498
< FileItem
459
499
key = { file . to }
460
500
actions = {
461
- < ActionButton
462
- className = { hiddenButtonStyle }
463
- iconName = { 'git-add' }
464
- title = { 'Track this file' }
465
- onClick = { ( ) => {
466
- this . addFile ( file . to ) ;
467
- } }
468
- />
501
+ < React . Fragment >
502
+ < ActionButton
503
+ className = { hiddenButtonStyle }
504
+ iconName = { 'open-file' }
505
+ title = { 'Open this file' }
506
+ onClick = { async ( ) => {
507
+ openListedFile ( file , this . props . model ) ;
508
+ } }
509
+ />
510
+ < ActionButton
511
+ className = { hiddenButtonStyle }
512
+ iconName = { 'git-add' }
513
+ title = { 'Track this file' }
514
+ onClick = { ( ) => {
515
+ this . addFile ( file . to ) ;
516
+ } }
517
+ />
518
+ </ React . Fragment >
469
519
}
470
520
file = { file }
471
521
contextMenu = { this . contextMenuUntracked }
472
522
model = { this . props . model }
523
+ onDoubleClick = { ( ) => {
524
+ if ( ! doubleClickDiff ) {
525
+ openListedFile ( file , this . props . model ) ;
526
+ }
527
+ } }
473
528
selected = { this . _isSelectedFile ( file ) }
474
529
selectFile = { this . updateSelectedFile }
475
530
/>
@@ -480,6 +535,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
480
535
}
481
536
482
537
private _renderSimpleStage ( files : Git . IStatusFile [ ] ) {
538
+ const doubleClickDiff = this . props . settings . get ( 'doubleClickDiff' )
539
+ . composite as boolean ;
483
540
return (
484
541
< GitStage
485
542
actions = {
@@ -495,10 +552,35 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
495
552
nFiles = { files . length }
496
553
>
497
554
{ files . map ( ( file : Git . IStatusFile ) => {
498
- let actions = null ;
555
+ const openFile = ( ) => {
556
+ openListedFile ( file , this . props . model ) ;
557
+ } ;
558
+
559
+ // Default value for actions and double click
560
+ let actions : JSX . Element = (
561
+ < ActionButton
562
+ className = { hiddenButtonStyle }
563
+ iconName = { 'open-file' }
564
+ title = { 'Open this file' }
565
+ onClick = { openFile }
566
+ />
567
+ ) ;
568
+ let onDoubleClick = doubleClickDiff
569
+ ? ( ) : void => undefined
570
+ : openFile ;
571
+
572
+ let diffButton : JSX . Element ;
499
573
if ( file . status === 'unstaged' ) {
574
+ diffButton = this . _createDiffButton ( file , 'WORKING' ) ;
500
575
actions = (
501
576
< React . Fragment >
577
+ < ActionButton
578
+ className = { hiddenButtonStyle }
579
+ iconName = { 'open-file' }
580
+ title = { 'Open this file' }
581
+ onClick = { openFile }
582
+ />
583
+ { diffButton }
502
584
< ActionButton
503
585
className = { hiddenButtonStyle }
504
586
iconName = { 'git-discard' }
@@ -507,11 +589,31 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
507
589
this . discardChanges ( file . to ) ;
508
590
} }
509
591
/>
510
- { this . _createDiffButton ( file , 'WORKING' ) }
511
592
</ React . Fragment >
512
593
) ;
594
+ onDoubleClick = doubleClickDiff
595
+ ? diffButton
596
+ ? ( ) => this . _openDiffView ( file , 'WORKING' )
597
+ : ( ) => undefined
598
+ : openFile ;
513
599
} else if ( file . status === 'staged' ) {
514
- actions = this . _createDiffButton ( file , 'INDEX' ) ;
600
+ diffButton = this . _createDiffButton ( file , 'INDEX' ) ;
601
+ actions = (
602
+ < React . Fragment >
603
+ < ActionButton
604
+ className = { hiddenButtonStyle }
605
+ iconName = { 'open-file' }
606
+ title = { 'Open this file' }
607
+ onClick = { openFile }
608
+ />
609
+ { diffButton }
610
+ </ React . Fragment >
611
+ ) ;
612
+ onDoubleClick = doubleClickDiff
613
+ ? diffButton
614
+ ? ( ) => this . _openDiffView ( file , 'INDEX' )
615
+ : ( ) => undefined
616
+ : openFile ;
515
617
}
516
618
517
619
return (
@@ -521,6 +623,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
521
623
file = { file }
522
624
markBox = { true }
523
625
model = { this . props . model }
626
+ onDoubleClick = { onDoubleClick }
524
627
/>
525
628
) ;
526
629
} ) }
@@ -529,7 +632,8 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
529
632
}
530
633
531
634
/**
532
- * Creates a button element which is used to request diff of a file.
635
+ * Creates a button element which, depending on the settings, is used
636
+ * to either request a diff of the file, or open the file
533
637
*
534
638
* @param path File path of interest
535
639
* @param currentRef the ref to diff against the git 'HEAD' ref
@@ -544,29 +648,38 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
544
648
className = { hiddenButtonStyle }
545
649
iconName = { 'git-diff' }
546
650
title = { 'Diff this file' }
547
- onClick = { async ( ) => {
548
- try {
549
- await openDiffView (
550
- file . to ,
551
- this . props . model ,
552
- {
553
- previousRef : { gitRef : 'HEAD' } ,
554
- currentRef : { specialRef : currentRef }
555
- } ,
556
- this . props . renderMime ,
557
- ! file . is_binary
558
- ) ;
559
- } catch ( reason ) {
560
- console . error (
561
- `Fail to open diff view for ${ file . to } .\n${ reason } `
562
- ) ;
563
- }
564
- } }
651
+ onClick = { ( ) => this . _openDiffView ( file , currentRef ) }
565
652
/>
566
653
)
567
654
) ;
568
655
}
569
656
657
+ /**
658
+ * Returns a callback which opens a diff of the file
659
+ *
660
+ * @param file File to open diff for
661
+ * @param currentRef the ref to diff against the git 'HEAD' ref
662
+ */
663
+ private async _openDiffView (
664
+ file : Git . IStatusFile ,
665
+ currentRef : ISpecialRef [ 'specialRef' ]
666
+ ) : Promise < void > {
667
+ try {
668
+ await openDiffView (
669
+ file . to ,
670
+ this . props . model ,
671
+ {
672
+ previousRef : { gitRef : 'HEAD' } ,
673
+ currentRef : { specialRef : currentRef }
674
+ } ,
675
+ this . props . renderMime ,
676
+ ! file . is_binary
677
+ ) ;
678
+ } catch ( reason ) {
679
+ console . error ( `Failed to open diff view for ${ file . to } .\n${ reason } ` ) ;
680
+ }
681
+ }
682
+
570
683
private _contextMenuStaged : Menu ;
571
684
private _contextMenuUnstaged : Menu ;
572
685
private _contextMenuUntracked : Menu ;
0 commit comments