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

Commit ba38028

Browse files
authored
Merge pull request #2353 from github/fixes/2352-open-fron-github-login
Add a login option to Open from GitHub
2 parents e9e2449 + 27f8b1a commit ba38028

22 files changed

+101
-13
lines changed

src/GitHub.App/SampleData/Dialog/Clone/RepositoryCloneViewModelDesigner.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public RepositoryCloneViewModelDesigner()
2727
public IRepositorySelectViewModel EnterpriseTab { get; }
2828
public ReactiveCommand<Unit, Unit> Browse { get; }
2929
public ReactiveCommand<Unit, CloneDialogResult> Clone { get; }
30+
public ReactiveCommand<Unit, Unit> LoginAsDifferentUser { get; }
3031

3132
public Task InitializeAsync(IConnection connection)
3233
{

src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2626
readonly IRepositoryCloneService service;
2727
readonly IGitService gitService;
2828
readonly IUsageTracker usageTracker;
29+
readonly IDialogService dialogService;
2930
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
3031
string path;
3132
UriString url;
@@ -40,6 +41,7 @@ public RepositoryCloneViewModel(
4041
IRepositoryCloneService service,
4142
IGitService gitService,
4243
IUsageTracker usageTracker,
44+
IDialogService dialogService,
4345
IRepositorySelectViewModel gitHubTab,
4446
IRepositorySelectViewModel enterpriseTab)
4547
{
@@ -48,6 +50,7 @@ public RepositoryCloneViewModel(
4850
this.service = service;
4951
this.gitService = gitService;
5052
this.usageTracker = usageTracker;
53+
this.dialogService = dialogService;
5154

5255
GitHubTab = gitHubTab;
5356
EnterpriseTab = enterpriseTab;
@@ -82,6 +85,8 @@ public RepositoryCloneViewModel(
8285
Open = ReactiveCommand.CreateFromObservable(
8386
() => repository.Select(x => new CloneDialogResult(Path, x?.CloneUrl)),
8487
canOpen);
88+
89+
LoginAsDifferentUser = ReactiveCommand.CreateFromTask(LoginAsDifferentUserAsync);
8590
}
8691

8792
public IRepositorySelectViewModel GitHubTab { get; }
@@ -111,6 +116,8 @@ public int SelectedTabIndex
111116

112117
public IObservable<object> Done => Observable.Merge(Clone, Open);
113118

119+
public ReactiveCommand<Unit, Unit> LoginAsDifferentUser { get; }
120+
114121
public ReactiveCommand<Unit, Unit> Browse { get; }
115122

116123
public ReactiveCommand<Unit, CloneDialogResult> Clone { get; }
@@ -133,7 +140,11 @@ public async Task InitializeAsync(IConnection connection)
133140
EnterpriseTab.Initialize(enterpriseConnection);
134141
}
135142

136-
if (connection == enterpriseConnection)
143+
if (connection == gitHubConnection)
144+
{
145+
SelectedTabIndex = 0;
146+
}
147+
else if (connection == enterpriseConnection)
137148
{
138149
SelectedTabIndex = 1;
139150
}
@@ -155,6 +166,28 @@ public async Task InitializeAsync(IConnection connection)
155166
this.WhenAnyValue(x => x.SelectedTabIndex).Subscribe(x => tabs[x].Activate().Forget());
156167
}
157168

169+
async Task LoginAsDifferentUserAsync()
170+
{
171+
if (await dialogService.ShowLoginDialog() is IConnection connection)
172+
{
173+
var connections = await connectionManager.GetLoadedConnections();
174+
var gitHubConnection = connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom());
175+
176+
if (connection == gitHubConnection)
177+
{
178+
SelectedTabIndex = 0;
179+
GitHubTab.Initialize(connection);
180+
GitHubTab.Activate().Forget();
181+
}
182+
else
183+
{
184+
SelectedTabIndex = 1;
185+
EnterpriseTab.Initialize(connection);
186+
EnterpriseTab.Activate().Forget();
187+
}
188+
}
189+
}
190+
158191
void BrowseForDirectory()
159192
{
160193
var result = os.Dialog.BrowseForDirectory(Path, Resources.BrowseForDirectory);

src/GitHub.App/ViewModels/Dialog/Clone/RepositorySelectViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static string GroupName(KeyValuePair<string, IReadOnlyList<RepositoryListItemMod
129129

130130
async Task LoadItems(bool refresh)
131131
{
132-
if (connection == null && !IsLoading) return;
132+
if (connection == null || IsLoading) return;
133133

134134
Error = null;
135135
IsLoading = true;

src/GitHub.Exports.Reactive/ViewModels/Dialog/Clone/IRepositoryCloneViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ public interface IRepositoryCloneViewModel : IDialogContentViewModel, IConnectio
5353
/// Gets the command executed when the user clicks "Clone".
5454
/// </summary>
5555
ReactiveCommand<Unit, CloneDialogResult> Clone { get; }
56+
57+
ReactiveCommand<Unit, Unit> LoginAsDifferentUser { get; }
5658
}
5759
}

src/GitHub.Resources/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Resources/Resources.cs-CZ.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,7 @@ https://git-scm.com/download/win</value>
888888
<data name="OpenFromGitHubClone" xml:space="preserve">
889889
<value>Klon</value>
890890
</data>
891+
<data name="AddChangeAccounts" xml:space="preserve">
892+
<value>Add/Change Accounts</value>
893+
</data>
891894
</root>

src/GitHub.Resources/Resources.de-DE.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,7 @@ https://git-scm.com/download/win</value>
888888
<data name="OpenFromGitHubClone" xml:space="preserve">
889889
<value>Klonen</value>
890890
</data>
891+
<data name="AddChangeAccounts" xml:space="preserve">
892+
<value>Add/Change Accounts</value>
893+
</data>
891894
</root>

src/GitHub.Resources/Resources.es-ES.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,7 @@ https://git-scm.com/download/win</value>
888888
<data name="OpenFromGitHubClone" xml:space="preserve">
889889
<value>Clonar</value>
890890
</data>
891+
<data name="AddChangeAccounts" xml:space="preserve">
892+
<value>Add/Change Accounts</value>
893+
</data>
891894
</root>

src/GitHub.Resources/Resources.fr-FR.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,7 @@ https://git-scm.com/download/win</value>
888888
<data name="OpenFromGitHubClone" xml:space="preserve">
889889
<value>Cloner</value>
890890
</data>
891+
<data name="AddChangeAccounts" xml:space="preserve">
892+
<value>Add/Change Accounts</value>
893+
</data>
891894
</root>

src/GitHub.Resources/Resources.it-IT.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,7 @@ https://git-scm.com/download/win</value>
888888
<data name="OpenFromGitHubClone" xml:space="preserve">
889889
<value>Clona</value>
890890
</data>
891+
<data name="AddChangeAccounts" xml:space="preserve">
892+
<value>Add/Change Accounts</value>
893+
</data>
891894
</root>

0 commit comments

Comments
 (0)