@@ -651,23 +651,19 @@ private GenericMenu CreateChangesTreeContextMenu(ChangesTreeNode node)
651
651
class FileHistoryView : HistoryBase
652
652
{
653
653
[ SerializeField ] private bool currentFileLogHasUpdate ;
654
+ [ SerializeField ] private bool currentStatusEntriesHasUpdate ;
654
655
655
656
[ SerializeField ] private GitFileLog gitFileLog ;
656
657
657
658
[ SerializeField ] private HistoryControl historyControl ;
658
659
[ SerializeField ] private GitLogEntry selectedEntry = GitLogEntry . Default ;
659
660
[ SerializeField ] private ChangesTree treeChanges = new ChangesTree { DisplayRootNode = false } ;
660
661
[ SerializeField ] private Vector2 detailsScroll ;
661
- [ SerializeField ] private NPath fullPath ;
662
+ [ SerializeField ] private List < GitStatusEntry > gitStatusEntries = new List < GitStatusEntry > ( ) ;
662
663
664
+ [ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
663
665
[ SerializeField ] private CacheUpdateEvent lastFileLogChangedEvent ;
664
666
665
- public void SetFullPath ( NPath inFullPath )
666
- {
667
- this . fullPath = inFullPath ;
668
-
669
- }
670
-
671
667
public override void Refresh ( )
672
668
{
673
669
base . Refresh ( ) ;
@@ -686,6 +682,17 @@ private void RepositoryOnFileLogChanged(CacheUpdateEvent cacheUpdateEvent)
686
682
}
687
683
}
688
684
685
+ private void RepositoryOnStatusEntriesChanged ( CacheUpdateEvent cacheUpdateEvent )
686
+ {
687
+ if ( ! lastStatusEntriesChangedEvent . Equals ( cacheUpdateEvent ) )
688
+ {
689
+ ReceivedEvent ( cacheUpdateEvent . cacheType ) ;
690
+ lastStatusEntriesChangedEvent = cacheUpdateEvent ;
691
+ currentStatusEntriesHasUpdate = true ;
692
+ Redraw ( ) ;
693
+ }
694
+ }
695
+
689
696
protected override void AttachHandlers ( IRepository repository )
690
697
{
691
698
if ( repository == null )
@@ -694,6 +701,7 @@ protected override void AttachHandlers(IRepository repository)
694
701
}
695
702
696
703
repository . FileLogChanged += RepositoryOnFileLogChanged ;
704
+ repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
697
705
}
698
706
699
707
protected override void DetachHandlers ( IRepository repository )
@@ -704,6 +712,7 @@ protected override void DetachHandlers(IRepository repository)
704
712
}
705
713
706
714
repository . FileLogChanged -= RepositoryOnFileLogChanged ;
715
+ repository . FileLogChanged -= RepositoryOnStatusEntriesChanged ;
707
716
}
708
717
709
718
protected override void ValidateCachedData ( IRepository repository )
@@ -726,6 +735,13 @@ protected override void MaybeUpdateData()
726
735
727
736
BuildHistoryControl ( 0 , gitFileLog . LogEntries ) ;
728
737
}
738
+
739
+ if ( currentStatusEntriesHasUpdate )
740
+ {
741
+ currentStatusEntriesHasUpdate = false ;
742
+
743
+ gitStatusEntries = Repository . CurrentChanges ;
744
+ }
729
745
}
730
746
731
747
public override void OnGUI ( )
@@ -734,7 +750,7 @@ public override void OnGUI()
734
750
DoHistoryGui ( lastRect , entry => {
735
751
GenericMenu menu = new GenericMenu ( ) ;
736
752
string checkoutPrompt = string . Format ( "Checkout revision {0}" , entry . ShortID ) ;
737
- menu . AddItem ( new GUIContent ( checkoutPrompt ) , false , ( ) => { Checkout ( entry ) ; } ) ;
753
+ menu . AddItem ( new GUIContent ( checkoutPrompt ) , false , ( ) => Checkout ( entry . commitID ) ) ;
738
754
menu . ShowAsContext ( ) ;
739
755
} , node => {
740
756
} ) ;
@@ -769,36 +785,16 @@ protected override Vector2 DetailsScroll
769
785
private const string ConfirmCheckoutOK = "Overwrite" ;
770
786
private const string ConfirmCheckoutCancel = "Cancel" ;
771
787
772
- protected void Checkout ( GitLogEntry entry )
788
+ protected void Checkout ( string commitId )
773
789
{
774
- GitClient . Status ( ) . ThenInUI ( ( success , status ) =>
775
- {
776
- if ( success )
777
- {
778
- bool promptUser = false ;
779
-
780
- foreach ( var e in status . Entries )
781
- {
782
- if ( e . FullPath == this . fullPath )
783
- {
784
- // locally modified file; prompt user
785
- promptUser = true ;
786
- break ;
787
- }
788
- }
790
+ var promptUser = gitStatusEntries . Count > 0 && gitStatusEntries . Any ( statusEntry => gitFileLog . Path . Equals ( statusEntry . Path . ToNPath ( ) ) ) ;
789
791
790
- if ( ! promptUser || EditorUtility . DisplayDialog ( ConfirmCheckoutTitle , string . Format ( ConfirmCheckoutMessage , this . fullPath ) , ConfirmCheckoutOK , ConfirmCheckoutCancel ) )
791
- {
792
- Repository . CheckoutVersion ( entry . commitID , new string [ ] { fullPath } )
793
- . ThenInUI ( AssetDatabase . Refresh )
794
- . Start ( ) ;
795
- }
796
- }
797
- else
798
- {
799
- EditorUtility . DisplayDialog ( "Oops" , "There was an error checking out this version of the file. Try again!" , "OK" ) ;
800
- }
801
- } ) . Start ( ) ;
792
+ if ( ! promptUser || EditorUtility . DisplayDialog ( ConfirmCheckoutTitle , string . Format ( ConfirmCheckoutMessage , gitFileLog . Path ) , ConfirmCheckoutOK , ConfirmCheckoutCancel ) )
793
+ {
794
+ Repository . CheckoutVersion ( commitId , new string [ ] { gitFileLog . Path } )
795
+ . ThenInUI ( AssetDatabase . Refresh )
796
+ . Start ( ) ;
797
+ }
802
798
}
803
799
}
804
800
}
0 commit comments