66using GitHub . Commands ;
77using GitHub . Logging ;
88using GitHub . Services ;
9+ using GitHub . Extensions ;
910using GitHub . Services . Vssdk . Commands ;
1011
1112namespace GitHub . VisualStudio . Commands
@@ -21,7 +22,8 @@ protected CreateGistCommand(
2122 Lazy < IDialogService > dialogService ,
2223 Lazy < ISelectedTextProvider > selectedTextProvider ,
2324 Lazy < IConnectionManager > connectionManager )
24- : base ( CommandSet , CommandId , dialogService , selectedTextProvider , connectionManager , true )
25+ : base ( CommandSet , CommandId , dialogService , selectedTextProvider , connectionManager , true ,
26+ isNotLoggedInDefault : true )
2527 {
2628 }
2729
@@ -68,6 +70,7 @@ protected CreateGistEnterpriseCommand(
6870 public abstract class CreateGistCommandBase : VsCommand
6971 {
7072 readonly bool isGitHubDotCom ;
73+ readonly bool isNotLoggedInDefault ;
7174 readonly Lazy < IDialogService > dialogService ;
7275 readonly Lazy < ISelectedTextProvider > selectedTextProvider ;
7376 readonly Lazy < IConnectionManager > connectionManager ;
@@ -77,13 +80,15 @@ protected CreateGistCommandBase(
7780 Lazy < IDialogService > dialogService ,
7881 Lazy < ISelectedTextProvider > selectedTextProvider ,
7982 Lazy < IConnectionManager > connectionManager ,
80- bool isGitHubDotCom )
83+ bool isGitHubDotCom ,
84+ bool isNotLoggedInDefault = false )
8185 : base ( commandSet , commandId )
8286 {
83- this . isGitHubDotCom = isGitHubDotCom ;
8487 this . dialogService = dialogService ;
8588 this . selectedTextProvider = selectedTextProvider ;
8689 this . connectionManager = connectionManager ;
90+ this . isGitHubDotCom = isGitHubDotCom ;
91+ this . isNotLoggedInDefault = isNotLoggedInDefault ;
8792 }
8893
8994 ISelectedTextProvider SelectedTextProvider => selectedTextProvider . Value ;
@@ -100,7 +105,8 @@ public override async Task Execute()
100105 protected override void QueryStatus ( )
101106 {
102107 Log . Assert ( SelectedTextProvider != null , "Could not get an instance of ISelectedTextProvider" ) ;
103- Visible = ! string . IsNullOrWhiteSpace ( SelectedTextProvider ? . GetSelectedText ( ) ) && HasConnection ( ) ;
108+ Visible = ! string . IsNullOrWhiteSpace ( SelectedTextProvider ? . GetSelectedText ( ) ) &&
109+ ( HasConnection ( ) || isNotLoggedInDefault && IsLoggedIn ( ) == false ) ;
104110 }
105111
106112 bool HasConnection ( )
@@ -114,5 +120,16 @@ async Task<IConnection> FindConnectionAsync()
114120 var connections = await connectionManager . Value . GetLoadedConnections ( ) ;
115121 return connections . FirstOrDefault ( x => x . IsLoggedIn && x . HostAddress . IsGitHubDotCom ( ) == isGitHubDotCom ) ;
116122 }
123+
124+ bool ? IsLoggedIn ( )
125+ {
126+ var task = connectionManager . Value . IsLoggedIn ( ) ;
127+ if ( task . IsCompleted )
128+ {
129+ return task . Result ;
130+ }
131+
132+ return null ;
133+ }
117134 }
118135}
0 commit comments