@@ -459,6 +459,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
459
459
460
460
var menu = new ContextMenu ( ) ;
461
461
var tags = new List < Models . Tag > ( ) ;
462
+ var isHead = commit . IsCurrentHead ;
462
463
463
464
if ( commit . HasDecorators )
464
465
{
@@ -525,32 +526,14 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
525
526
{
526
527
var target = commit . GetFriendlyName ( ) ;
527
528
528
- if ( current . Head != commit . SHA )
529
- {
530
- var reset = new MenuItem ( ) ;
531
- reset . Header = App . Text ( "CommitCM.Reset" , current . Name , target ) ;
532
- reset . Icon = App . CreateMenuIcon ( "Icons.Reset" ) ;
533
- reset . Click += ( _ , e ) =>
534
- {
535
- if ( repo . CanCreatePopup ( ) )
536
- repo . ShowPopup ( new ViewModels . Reset ( repo , current , commit ) ) ;
537
- e . Handled = true ;
538
- } ;
539
- menu . Items . Add ( reset ) ;
540
- }
541
- else
529
+ if ( isHead )
542
530
{
543
531
var reword = new MenuItem ( ) ;
544
532
reword . Header = App . Text ( "CommitCM.Reword" ) ;
545
533
reword . Icon = App . CreateMenuIcon ( "Icons.Edit" ) ;
546
534
reword . Click += async ( _ , e ) =>
547
535
{
548
- if ( repo . CanCreatePopup ( ) )
549
- {
550
- var message = await new Commands . QueryCommitFullMessage ( repo . FullPath , commit . SHA ) . GetResultAsync ( ) ;
551
- repo . ShowPopup ( new ViewModels . Reword ( repo , commit , message ) ) ;
552
- }
553
-
536
+ await vm . RewordHeadAsync ( commit ) ;
554
537
e . Handled = true ;
555
538
} ;
556
539
menu . Items . Add ( reword ) ;
@@ -561,18 +544,24 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
561
544
squash . IsEnabled = commit . Parents . Count == 1 ;
562
545
squash . Click += async ( _ , e ) =>
563
546
{
564
- if ( commit . Parents . Count == 1 )
565
- {
566
- var message = await new Commands . QueryCommitFullMessage ( repo . FullPath , commit . SHA ) . GetResultAsync ( ) ;
567
- var parent = vm . Commits . Find ( x => x . SHA . Equals ( commit . Parents [ 0 ] ) ) ;
568
- if ( parent != null && repo . CanCreatePopup ( ) )
569
- repo . ShowPopup ( new ViewModels . Squash ( repo , parent , message ) ) ;
570
- }
571
-
547
+ await vm . SquashHeadAsync ( commit ) ;
572
548
e . Handled = true ;
573
549
} ;
574
550
menu . Items . Add ( squash ) ;
575
551
}
552
+ else
553
+ {
554
+ var reset = new MenuItem ( ) ;
555
+ reset . Header = App . Text ( "CommitCM.Reset" , current . Name , target ) ;
556
+ reset . Icon = App . CreateMenuIcon ( "Icons.Reset" ) ;
557
+ reset . Click += ( _ , e ) =>
558
+ {
559
+ if ( repo . CanCreatePopup ( ) )
560
+ repo . ShowPopup ( new ViewModels . Reset ( repo , current , commit ) ) ;
561
+ e . Handled = true ;
562
+ } ;
563
+ menu . Items . Add ( reset ) ;
564
+ }
576
565
577
566
if ( ! commit . IsMerged )
578
567
{
@@ -607,29 +596,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
607
596
cherryPick . Icon = App . CreateMenuIcon ( "Icons.CherryPick" ) ;
608
597
cherryPick . Click += async ( _ , e ) =>
609
598
{
610
- if ( repo . CanCreatePopup ( ) )
611
- {
612
- if ( commit . Parents . Count <= 1 )
613
- {
614
- repo . ShowPopup ( new ViewModels . CherryPick ( repo , [ commit ] ) ) ;
615
- }
616
- else
617
- {
618
- var parents = new List < Models . Commit > ( ) ;
619
- foreach ( var sha in commit . Parents )
620
- {
621
- var parent = vm . Commits . Find ( x => x . SHA == sha ) ;
622
- if ( parent == null )
623
- parent = await new Commands . QuerySingleCommit ( repo . FullPath , sha ) . GetResultAsync ( ) ;
624
-
625
- if ( parent != null )
626
- parents . Add ( parent ) ;
627
- }
628
-
629
- repo . ShowPopup ( new ViewModels . CherryPick ( repo , commit , parents ) ) ;
630
- }
631
- }
632
-
599
+ await vm . CherryPickAsync ( commit ) ;
633
600
e . Handled = true ;
634
601
} ;
635
602
menu . Items . Add ( cherryPick ) ;
@@ -648,7 +615,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
648
615
menu . Items . Add ( revert ) ;
649
616
}
650
617
651
- if ( current . Head != commit . SHA )
618
+ if ( ! isHead )
652
619
{
653
620
var checkoutCommit = new MenuItem ( ) ;
654
621
checkoutCommit . Header = App . Text ( "CommitCM.Checkout" ) ;
@@ -679,57 +646,39 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
679
646
reword . Header = App . Text ( "CommitCM.InteractiveRebase.Reword" ) ;
680
647
reword . Click += async ( _ , e ) =>
681
648
{
682
- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Reword ) ;
683
- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~") . GetResultAsync ( ) ;
684
- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
649
+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Reword ) ;
685
650
e . Handled = true ;
686
651
} ;
687
652
688
653
var edit = new MenuItem ( ) ;
689
654
edit . Header = App . Text ( "CommitCM.InteractiveRebase.Edit" ) ;
690
655
edit . Click += async ( _ , e ) =>
691
656
{
692
- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Edit ) ;
693
- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~") . GetResultAsync ( ) ;
694
- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
657
+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Edit ) ;
695
658
e . Handled = true ;
696
659
} ;
697
660
698
661
var squash = new MenuItem ( ) ;
699
662
squash . Header = App . Text ( "CommitCM.InteractiveRebase.Squash" ) ;
700
663
squash . Click += async ( _ , e ) =>
701
664
{
702
- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Squash ) ;
703
- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~~") . GetResultAsync ( ) ;
704
- if ( on != null )
705
- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
706
- else
707
- App . RaiseException ( repo . FullPath , $ "Can not squash current commit into parent!") ;
708
-
665
+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Squash ) ;
709
666
e . Handled = true ;
710
667
} ;
711
668
712
669
var fixup = new MenuItem ( ) ;
713
670
fixup . Header = App . Text ( "CommitCM.InteractiveRebase.Fixup" ) ;
714
671
fixup . Click += async ( _ , e ) =>
715
672
{
716
- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Fixup ) ;
717
- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~~") . GetResultAsync ( ) ;
718
- if ( on != null )
719
- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
720
- else
721
- App . RaiseException ( repo . FullPath , $ "Can not fixup current commit into parent!") ;
722
-
673
+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Fixup ) ;
723
674
e . Handled = true ;
724
675
} ;
725
676
726
677
var drop = new MenuItem ( ) ;
727
678
drop . Header = App . Text ( "CommitCM.InteractiveRebase.Drop" ) ;
728
679
drop . Click += async ( _ , e ) =>
729
680
{
730
- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Drop ) ;
731
- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~") . GetResultAsync ( ) ;
732
- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
681
+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Drop ) ;
733
682
e . Handled = true ;
734
683
} ;
735
684
@@ -763,7 +712,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
763
712
menu . Items . Add ( new MenuItem ( ) { Header = "-" } ) ;
764
713
}
765
714
766
- if ( current . Head != commit . SHA )
715
+ if ( ! isHead )
767
716
{
768
717
if ( current . TrackStatus . Ahead . Contains ( commit . SHA ) )
769
718
{
@@ -786,18 +735,9 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
786
735
compareWithHead . Icon = App . CreateMenuIcon ( "Icons.Compare" ) ;
787
736
compareWithHead . Click += async ( _ , e ) =>
788
737
{
789
- var head = vm . Commits . Find ( x => x . SHA == current . Head ) ;
790
- if ( head == null )
791
- {
792
- repo . SelectedSearchedCommit = null ;
793
- head = await new Commands . QuerySingleCommit ( repo . FullPath , current . Head ) . GetResultAsync ( ) ;
794
- if ( head != null )
795
- vm . DetailContext = new ViewModels . RevisionCompare ( repo . FullPath , commit , head ) ;
796
- }
797
- else
798
- {
738
+ var head = await vm . CompareWithHeadAsync ( commit ) ;
739
+ if ( head != null )
799
740
CommitListContainer . SelectedItems . Add ( head ) ;
800
- }
801
741
802
742
e . Handled = true ;
803
743
} ;
@@ -810,7 +750,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
810
750
compareWithWorktree . Icon = App . CreateMenuIcon ( "Icons.Compare" ) ;
811
751
compareWithWorktree . Click += ( _ , e ) =>
812
752
{
813
- vm . DetailContext = new ViewModels . RevisionCompare ( repo . FullPath , commit , null ) ;
753
+ vm . CompareWithWorktree ( commit ) ;
814
754
e . Handled = true ;
815
755
} ;
816
756
menu . Items . Add ( compareWithWorktree ) ;
@@ -920,8 +860,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
920
860
copyMessage . Icon = App . CreateMenuIcon ( "Icons.Info" ) ;
921
861
copyMessage . Click += async ( _ , e ) =>
922
862
{
923
- var message = await new Commands . QueryCommitFullMessage ( repo . FullPath , commit . SHA ) . GetResultAsync ( ) ;
924
- await App . CopyTextAsync ( message ) ;
863
+ await vm . CopyCommitFullMessageAsync ( commit ) ;
925
864
e . Handled = true ;
926
865
} ;
927
866
0 commit comments