@@ -54,6 +54,7 @@ class Window : BaseWindow
5454 [ SerializeField ] private string repositoryProgressMessage ;
5555 [ SerializeField ] private float appManagerProgressValue ;
5656 [ SerializeField ] private string appManagerProgressMessage ;
57+ [ SerializeField ] private Connection connection ;
5758
5859 [ MenuItem ( Menu_Window_GitHub ) ]
5960 public static void Window_GitHub ( )
@@ -210,6 +211,8 @@ private void ValidateCachedData(IRepository repository)
210211
211212 private void MaybeUpdateData ( )
212213 {
214+ connection = Platform . Keychain . Connections . FirstOrDefault ( ) ;
215+
213216 if ( repositoryProgressHasUpdate )
214217 {
215218 if ( repositoryProgress != null )
@@ -351,6 +354,7 @@ private void AttachHandlers(IRepository repository)
351354 repository . TrackingStatusChanged += RepositoryOnTrackingStatusChanged ;
352355 repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
353356 repository . OnProgress += UpdateProgress ;
357+ Platform . Keychain . ConnectionsChanged += ConnectionsChanged ;
354358 }
355359
356360 private void DetachHandlers ( IRepository repository )
@@ -362,6 +366,7 @@ private void DetachHandlers(IRepository repository)
362366 repository . StatusEntriesChanged -= RepositoryOnStatusEntriesChanged ;
363367 repository . OnProgress -= UpdateProgress ;
364368 Manager . OnProgress -= ApplicationManagerOnProgress ;
369+ Platform . Keychain . ConnectionsChanged -= ConnectionsChanged ;
365370 }
366371
367372 private void RepositoryOnCurrentBranchAndRemoteChanged ( CacheUpdateEvent cacheUpdateEvent )
@@ -419,6 +424,14 @@ private void ApplicationManagerOnProgress(IProgress progress)
419424 appManagerProgressHasUpdate = true ;
420425 }
421426
427+ private void ConnectionsChanged ( )
428+ {
429+ if ( ! ThreadingHelper . InUIThread )
430+ TaskManager . RunInUI ( Redraw ) ;
431+ else
432+ Redraw ( ) ;
433+ }
434+
422435 public override void OnUI ( )
423436 {
424437 base . OnUI ( ) ;
@@ -610,8 +623,18 @@ private void DoActionbarGUI()
610623
611624 GUILayout . FlexibleSpace ( ) ;
612625
613- if ( GUILayout . Button ( Localization . AccountButton , EditorStyles . toolbarDropDown ) )
614- DoAccountDropdown ( ) ;
626+ if ( connection == null )
627+ {
628+ if ( GUILayout . Button ( "Sign in" , EditorStyles . toolbarButton ) )
629+ SignIn ( null ) ;
630+ }
631+ else
632+ {
633+ if ( GUILayout . Button ( connection . Username , EditorStyles . toolbarDropDown ) )
634+ {
635+ DoAccountDropdown ( ) ;
636+ }
637+ }
615638 }
616639 EditorGUILayout . EndHorizontal ( ) ;
617640 }
@@ -770,23 +793,15 @@ private void SwitchView(Subview fromView, Subview toView)
770793 toView . OnDataUpdate ( ) ;
771794
772795 // this triggers a repaint
773- Repaint ( ) ;
796+ Redraw ( ) ;
774797 }
775798
776799 private void DoAccountDropdown ( )
777800 {
778801 GenericMenu accountMenu = new GenericMenu ( ) ;
779-
780- if ( ! Platform . Keychain . HasKeys )
781- {
782- accountMenu . AddItem ( new GUIContent ( "Sign in" ) , false , SignIn , "sign in" ) ;
783- }
784- else
785- {
786- accountMenu . AddItem ( new GUIContent ( "Go to Profile" ) , false , GoToProfile , "profile" ) ;
787- accountMenu . AddSeparator ( "" ) ;
788- accountMenu . AddItem ( new GUIContent ( "Sign out" ) , false , SignOut , "sign out" ) ;
789- }
802+ accountMenu . AddItem ( new GUIContent ( "Go to Profile" ) , false , GoToProfile , "profile" ) ;
803+ accountMenu . AddSeparator ( "" ) ;
804+ accountMenu . AddItem ( new GUIContent ( "Sign out" ) , false , SignOut , "sign out" ) ;
790805 accountMenu . ShowAsContext ( ) ;
791806 }
792807
@@ -809,15 +824,15 @@ private void SignOut(object obj)
809824 if ( Repository != null && Repository . CloneUrl != null && Repository . CloneUrl . IsValidUri )
810825 {
811826 host = new UriString ( Repository . CloneUrl . ToRepositoryUri ( )
812- . GetComponents ( UriComponents . SchemeAndServer , UriFormat . SafeUnescaped ) ) ;
827+ . GetComponents ( UriComponents . SchemeAndServer , UriFormat . SafeUnescaped ) ) ;
813828 }
814829 else
815830 {
816831 host = UriString . ToUriString ( HostAddress . GitHubDotComHostAddress . WebUri ) ;
817832 }
818833
819834 var apiClient = new ApiClient ( host , Platform . Keychain , null , null , NPath . Default , NPath . Default ) ;
820- apiClient . Logout ( host ) ;
835+ apiClient . Logout ( host ) . FinallyInUI ( ( s , e ) => Redraw ( ) ) ;
821836 }
822837
823838 public new void ShowNotification ( GUIContent content )
0 commit comments