@@ -54,6 +54,7 @@ class Window : BaseWindow
54
54
[ SerializeField ] private string repositoryProgressMessage ;
55
55
[ SerializeField ] private float appManagerProgressValue ;
56
56
[ SerializeField ] private string appManagerProgressMessage ;
57
+ [ SerializeField ] private Connection connection ;
57
58
58
59
[ MenuItem ( Menu_Window_GitHub ) ]
59
60
public static void Window_GitHub ( )
@@ -210,6 +211,8 @@ private void ValidateCachedData(IRepository repository)
210
211
211
212
private void MaybeUpdateData ( )
212
213
{
214
+ connection = Platform . Keychain . Connections . FirstOrDefault ( ) ;
215
+
213
216
if ( repositoryProgressHasUpdate )
214
217
{
215
218
if ( repositoryProgress != null )
@@ -351,6 +354,7 @@ private void AttachHandlers(IRepository repository)
351
354
repository . TrackingStatusChanged += RepositoryOnTrackingStatusChanged ;
352
355
repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
353
356
repository . OnProgress += UpdateProgress ;
357
+ Platform . Keychain . ConnectionsChanged += ConnectionsChanged ;
354
358
}
355
359
356
360
private void DetachHandlers ( IRepository repository )
@@ -362,6 +366,7 @@ private void DetachHandlers(IRepository repository)
362
366
repository . StatusEntriesChanged -= RepositoryOnStatusEntriesChanged ;
363
367
repository . OnProgress -= UpdateProgress ;
364
368
Manager . OnProgress -= ApplicationManagerOnProgress ;
369
+ Platform . Keychain . ConnectionsChanged -= ConnectionsChanged ;
365
370
}
366
371
367
372
private void RepositoryOnCurrentBranchAndRemoteChanged ( CacheUpdateEvent cacheUpdateEvent )
@@ -419,6 +424,14 @@ private void ApplicationManagerOnProgress(IProgress progress)
419
424
appManagerProgressHasUpdate = true ;
420
425
}
421
426
427
+ private void ConnectionsChanged ( )
428
+ {
429
+ if ( ! ThreadingHelper . InUIThread )
430
+ TaskManager . RunInUI ( Redraw ) ;
431
+ else
432
+ Redraw ( ) ;
433
+ }
434
+
422
435
public override void OnUI ( )
423
436
{
424
437
base . OnUI ( ) ;
@@ -610,8 +623,18 @@ private void DoActionbarGUI()
610
623
611
624
GUILayout . FlexibleSpace ( ) ;
612
625
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
+ }
615
638
}
616
639
EditorGUILayout . EndHorizontal ( ) ;
617
640
}
@@ -770,23 +793,15 @@ private void SwitchView(Subview fromView, Subview toView)
770
793
toView . OnDataUpdate ( ) ;
771
794
772
795
// this triggers a repaint
773
- Repaint ( ) ;
796
+ Redraw ( ) ;
774
797
}
775
798
776
799
private void DoAccountDropdown ( )
777
800
{
778
801
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" ) ;
790
805
accountMenu . ShowAsContext ( ) ;
791
806
}
792
807
@@ -809,15 +824,15 @@ private void SignOut(object obj)
809
824
if ( Repository != null && Repository . CloneUrl != null && Repository . CloneUrl . IsValidUri )
810
825
{
811
826
host = new UriString ( Repository . CloneUrl . ToRepositoryUri ( )
812
- . GetComponents ( UriComponents . SchemeAndServer , UriFormat . SafeUnescaped ) ) ;
827
+ . GetComponents ( UriComponents . SchemeAndServer , UriFormat . SafeUnescaped ) ) ;
813
828
}
814
829
else
815
830
{
816
831
host = UriString . ToUriString ( HostAddress . GitHubDotComHostAddress . WebUri ) ;
817
832
}
818
833
819
834
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 ( ) ) ;
821
836
}
822
837
823
838
public new void ShowNotification ( GUIContent content )
0 commit comments