@@ -651,23 +651,19 @@ private GenericMenu CreateChangesTreeContextMenu(ChangesTreeNode node)
651651 class FileHistoryView : HistoryBase
652652 {
653653 [ SerializeField ] private bool currentFileLogHasUpdate ;
654+ [ SerializeField ] private bool currentStatusEntriesHasUpdate ;
654655
655656 [ SerializeField ] private GitFileLog gitFileLog ;
656657
657658 [ SerializeField ] private HistoryControl historyControl ;
658659 [ SerializeField ] private GitLogEntry selectedEntry = GitLogEntry . Default ;
659660 [ SerializeField ] private ChangesTree treeChanges = new ChangesTree { DisplayRootNode = false } ;
660661 [ SerializeField ] private Vector2 detailsScroll ;
661- [ SerializeField ] private NPath fullPath ;
662+ [ SerializeField ] private List < GitStatusEntry > gitStatusEntries = new List < GitStatusEntry > ( ) ;
662663
664+ [ SerializeField ] private CacheUpdateEvent lastStatusEntriesChangedEvent ;
663665 [ SerializeField ] private CacheUpdateEvent lastFileLogChangedEvent ;
664666
665- public void SetFullPath ( NPath inFullPath )
666- {
667- this . fullPath = inFullPath ;
668-
669- }
670-
671667 public override void Refresh ( )
672668 {
673669 base . Refresh ( ) ;
@@ -686,6 +682,17 @@ private void RepositoryOnFileLogChanged(CacheUpdateEvent cacheUpdateEvent)
686682 }
687683 }
688684
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+
689696 protected override void AttachHandlers ( IRepository repository )
690697 {
691698 if ( repository == null )
@@ -694,6 +701,7 @@ protected override void AttachHandlers(IRepository repository)
694701 }
695702
696703 repository . FileLogChanged += RepositoryOnFileLogChanged ;
704+ repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
697705 }
698706
699707 protected override void DetachHandlers ( IRepository repository )
@@ -704,6 +712,7 @@ protected override void DetachHandlers(IRepository repository)
704712 }
705713
706714 repository . FileLogChanged -= RepositoryOnFileLogChanged ;
715+ repository . FileLogChanged -= RepositoryOnStatusEntriesChanged ;
707716 }
708717
709718 protected override void ValidateCachedData ( IRepository repository )
@@ -726,6 +735,13 @@ protected override void MaybeUpdateData()
726735
727736 BuildHistoryControl ( 0 , gitFileLog . LogEntries ) ;
728737 }
738+
739+ if ( currentStatusEntriesHasUpdate )
740+ {
741+ currentStatusEntriesHasUpdate = false ;
742+
743+ gitStatusEntries = Repository . CurrentChanges ;
744+ }
729745 }
730746
731747 public override void OnGUI ( )
@@ -734,7 +750,7 @@ public override void OnGUI()
734750 DoHistoryGui ( lastRect , entry => {
735751 GenericMenu menu = new GenericMenu ( ) ;
736752 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 ) ) ;
738754 menu . ShowAsContext ( ) ;
739755 } , node => {
740756 } ) ;
@@ -769,36 +785,16 @@ protected override Vector2 DetailsScroll
769785 private const string ConfirmCheckoutOK = "Overwrite" ;
770786 private const string ConfirmCheckoutCancel = "Cancel" ;
771787
772- protected void Checkout ( GitLogEntry entry )
788+ protected void Checkout ( string commitId )
773789 {
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 ( ) ) ) ;
789791
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+ }
802798 }
803799 }
804800}
0 commit comments