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

Commit f5369ba

Browse files
committed
Implement browse button.
1 parent 2224fb3 commit f5369ba

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public RepositoryCloneViewModelDesigner()
2323
public IRepositorySelectViewModel GitHubTab { get; }
2424
public IRepositorySelectViewModel EnterpriseTab { get; }
2525
public IRepositoryUrlViewModel UrlTab { get; }
26+
public ReactiveCommand<object> Browse { get; }
2627
public ReactiveCommand<CloneDialogResult> Clone { get; }
2728

2829
public Task InitializeAsync(IConnection connection)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using GitHub.Models;
1111
using GitHub.Services;
1212
using ReactiveUI;
13+
using Rothko;
1314
using Serilog;
1415

1516
namespace GitHub.ViewModels.Dialog.Clone
@@ -19,6 +20,7 @@ namespace GitHub.ViewModels.Dialog.Clone
1920
public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2021
{
2122
static readonly ILogger log = LogManager.ForContext<RepositoryCloneViewModel>();
23+
readonly IOperatingSystem os;
2224
readonly IConnectionManager connectionManager;
2325
readonly IRepositoryCloneService service;
2426
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
@@ -28,12 +30,14 @@ public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2830

2931
[ImportingConstructor]
3032
public RepositoryCloneViewModel(
33+
IOperatingSystem os,
3134
IConnectionManager connectionManager,
3235
IRepositoryCloneService service,
3336
IRepositorySelectViewModel gitHubTab,
3437
IRepositorySelectViewModel enterpriseTab,
3538
IRepositoryUrlViewModel urlTab)
3639
{
40+
this.os = os;
3741
this.connectionManager = connectionManager;
3842
this.service = service;
3943

@@ -60,6 +64,7 @@ public RepositoryCloneViewModel(
6064
(repo, error) => (repo, error))
6165
.Select(x => x.repo != null && x.error == null);
6266

67+
Browse = ReactiveCommand.Create().OnExecuteCompleted(_ => BrowseForDirectory());
6368
Clone = ReactiveCommand.CreateAsyncObservable(
6469
canClone,
6570
_ => repository.Select(x => new CloneDialogResult(Path, x)));
@@ -87,6 +92,8 @@ public int SelectedTabIndex
8792

8893
public IObservable<object> Done => Clone;
8994

95+
public ReactiveCommand<object> Browse { get; }
96+
9097
public ReactiveCommand<CloneDialogResult> Clone { get; }
9198

9299
public async Task InitializeAsync(IConnection connection)
@@ -113,6 +120,24 @@ public async Task InitializeAsync(IConnection connection)
113120
this.WhenAnyValue(x => x.SelectedTabIndex).Subscribe(x => tabs[x].Activate().Forget());
114121
}
115122

123+
void BrowseForDirectory()
124+
{
125+
var result = os.Dialog.BrowseForDirectory(Path, Resources.BrowseForDirectory);
126+
127+
if (result != BrowseDirectoryResult.Failed)
128+
{
129+
var path = result.DirectoryPath;
130+
var selected = tabs[SelectedTabIndex].Repository;
131+
132+
if (selected != null)
133+
{
134+
path = System.IO.Path.Combine(path, selected.Name);
135+
}
136+
137+
Path = path;
138+
}
139+
}
140+
116141
void UpdatePath(IRepositoryModel x)
117142
{
118143
if (x != null)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public interface IRepositoryCloneViewModel : IDialogContentViewModel, IConnectio
4242
/// </remarks>
4343
int SelectedTabIndex { get; }
4444

45+
/// <summary>
46+
/// Gets the command executed when the user clicks "Browse".
47+
/// </summary>
48+
ReactiveCommand<object> Browse { get; }
49+
4550
/// <summary>
4651
/// Gets the command executed when the user clicks "Clone".
4752
/// </summary>

src/GitHub.VisualStudio/Views/Dialog/Clone/RepositoryCloneView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
Margin="16">
3737
<Label DockPanel.Dock="Left">Local Path</Label>
3838
<Button DockPanel.Dock="Right"
39+
Command="{Binding Browse}"
3940
Style="{DynamicResource GitHubBlueLinkButton}"
4041
VerticalContentAlignment="Center">
4142
Browse

test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using GitHub.ViewModels.Dialog.Clone;
99
using NSubstitute;
1010
using NUnit.Framework;
11+
using Rothko;
1112

1213
namespace GitHub.App.UnitTests.ViewModels.Dialog.Clone
1314
{
@@ -241,19 +242,22 @@ static IRepositoryCloneService CreateRepositoryCloneService()
241242
}
242243

243244
static RepositoryCloneViewModel CreateTarget(
245+
IOperatingSystem os = null,
244246
IConnectionManager connectionManager = null,
245247
IRepositoryCloneService service = null,
246248
IRepositorySelectViewModel gitHubTab = null,
247249
IRepositorySelectViewModel enterpriseTab = null,
248250
IRepositoryUrlViewModel urlTab = null)
249251
{
252+
os = os ?? Substitute.For<IOperatingSystem>();
250253
connectionManager = connectionManager ?? CreateConnectionManager("https://github.com");
251254
service = service ?? CreateRepositoryCloneService();
252255
gitHubTab = gitHubTab ?? CreateSelectViewModel();
253256
enterpriseTab = enterpriseTab ?? CreateSelectViewModel();
254257
urlTab = urlTab ?? Substitute.For<IRepositoryUrlViewModel>();
255258

256259
return new RepositoryCloneViewModel(
260+
os,
257261
connectionManager,
258262
service,
259263
gitHubTab,

0 commit comments

Comments
 (0)