Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit dd2609d

Browse files
committed
Show Create a GitHub Gist if user not logged in
If user isn't logged in to either GitHub or GitHub Enterprise, allow them to login as part of the create a Gist workflow.
1 parent 2888313 commit dd2609d

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/GitHub.App/Services/DialogService.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ public async Task<string> ShowReCloneDialog(IRepositoryModel repository)
5454
public async Task ShowCreateGist(IConnection connection)
5555
{
5656
var viewModel = factory.CreateViewModel<IGistCreationViewModel>();
57-
await viewModel.InitializeAsync(connection);
58-
await showDialog.Show(viewModel);
57+
58+
if (connection != null)
59+
{
60+
await viewModel.InitializeAsync(connection);
61+
await showDialog.Show(viewModel);
62+
}
63+
else
64+
{
65+
await showDialog.ShowWithFirstConnection(viewModel);
66+
}
5967
}
6068

6169
public async Task ShowCreateRepositoryDialog(IConnection connection)

src/GitHub.Exports/Services/IDialogService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public interface IDialogService
4040
/// Shows the Create Gist dialog.
4141
/// </summary>
4242
/// <param name="connection">
43-
/// The connection to use. May not be null.
43+
/// The connection to use. If null, the first connection will be used, or the user promted
44+
/// to log in if there are no connections.
4445
/// </param>
4546
Task ShowCreateGist(IConnection connection);
4647

src/GitHub.VisualStudio/Commands/CreateGistCommand.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using GitHub.Commands;
77
using GitHub.Logging;
88
using GitHub.Services;
9+
using GitHub.Extensions;
910
using GitHub.Services.Vssdk.Commands;
1011

1112
namespace 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

Comments
 (0)