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

Commit 2914c3e

Browse files
Initial ForkRepositorySwitchView
1 parent 22b9ef7 commit 2914c3e

File tree

11 files changed

+280
-12
lines changed

11 files changed

+280
-12
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
<Compile Include="SampleData\ForkRepositoryExecuteViewModelDesigner.cs" />
214214
<Compile Include="SampleData\ForkRepositorySelectViewModelDesigner.cs" />
215215
<Compile Include="Models\PullRequestReviewModel.cs" />
216+
<Compile Include="SampleData\ForkRepositorySwitchViewModelDesigner.cs" />
216217
<Compile Include="SampleData\PullRequestFilesViewModelDesigner.cs" />
217218
<Compile Include="SampleData\PullRequestReviewAuthoringViewModelDesigner.cs" />
218219
<Compile Include="SampleData\PullRequestReviewFileCommentViewModelDesigner.cs" />
@@ -222,6 +223,7 @@
222223
<Compile Include="Services\GlobalConnection.cs" />
223224
<Compile Include="Services\RepositoryForkService.cs" />
224225
<Compile Include="ViewModels\Dialog\ForkRepositoryExecuteViewModel.cs" />
226+
<Compile Include="ViewModels\Dialog\ForkRepositorySwitchViewModel.cs" />
225227
<Compile Include="ViewModels\Dialog\ForkRepositoryViewModel.cs" />
226228
<Compile Include="ViewModels\Dialog\ForkRepositorySelectViewModel.cs" />
227229
<Compile Include="Services\PullRequestEditorService.cs" />
@@ -401,6 +403,7 @@
401403
<EmbeddedResource Include="Resources.resx">
402404
<Generator>ResXFileCodeGenerator</Generator>
403405
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
406+
<SubType>Designer</SubType>
404407
</EmbeddedResource>
405408
</ItemGroup>
406409
<ItemGroup>

src/GitHub.App/Resources.Designer.cs

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.App/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,7 @@ https://git-scm.com/download/win</value>
318318
<data name="ForkRepositoryTitle" xml:space="preserve">
319319
<value>Fork Repository</value>
320320
</data>
321+
<data name="SwitchOriginTitle" xml:space="preserve">
322+
<value>Switch Origin</value>
323+
</data>
321324
</root>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using GitHub.Models;
3+
using GitHub.ViewModels;
4+
using GitHub.ViewModels.Dialog;
5+
using ReactiveUI;
6+
7+
namespace GitHub.SampleData
8+
{
9+
public class ForkRepositorySwitchViewModelDesigner : ViewModelBase, IForkRepositorySwitchViewModel
10+
{
11+
public ForkRepositorySwitchViewModelDesigner()
12+
{
13+
SourceRepository = new RemoteRepositoryModelDesigner
14+
{
15+
Owner = "github",
16+
Name = "VisualStudio",
17+
CloneUrl = "https://github.com/github/VisualStudio",
18+
};
19+
DestinationRepository = new RemoteRepositoryModelDesigner
20+
{
21+
Owner = "user",
22+
Name = "VisualStudio",
23+
CloneUrl = "https://github.com/user/VisualStudio",
24+
};
25+
}
26+
27+
public string Title => null;
28+
29+
public IObservable<object> Done => null;
30+
31+
public IRepositoryModel SourceRepository { get; }
32+
33+
public IRepositoryModel DestinationRepository { get; }
34+
35+
public IReactiveCommand<object> SwitchFork => null;
36+
37+
public bool ResetMasterTracking { get; set; } = true;
38+
39+
public bool AddUpstream { get; set; } = true;
40+
41+
public bool UpdateOrigin { get; set; } = true;
42+
43+
public void Initialize(ILocalRepositoryModel sourceRepository, IRemoteRepositoryModel remoteRepository)
44+
{
45+
}
46+
}
47+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using System.Reactive;
4+
using System.Reactive.Linq;
5+
using System.Reactive.Threading.Tasks;
6+
using System.Threading.Tasks;
7+
using GitHub.App;
8+
using GitHub.Extensions;
9+
using GitHub.Logging;
10+
using GitHub.Models;
11+
using GitHub.Primitives;
12+
using GitHub.Services;
13+
using Octokit;
14+
using ReactiveUI;
15+
using Serilog;
16+
17+
namespace GitHub.ViewModels.Dialog
18+
{
19+
[Export(typeof(IForkRepositorySwitchViewModel))]
20+
[PartCreationPolicy(CreationPolicy.NonShared)]
21+
public class ForkRepositorySwitchViewModel : ViewModelBase, IForkRepositorySwitchViewModel
22+
{
23+
static readonly ILogger log = LogManager.ForContext<ForkRepositorySwitchViewModel>();
24+
25+
readonly IRepositoryForkService repositoryForkService;
26+
27+
[ImportingConstructor]
28+
public ForkRepositorySwitchViewModel(IRepositoryForkService repositoryForkService)
29+
{
30+
this.repositoryForkService = repositoryForkService;
31+
32+
SwitchFork = ReactiveCommand.CreateAsyncObservable(OnSwitchFork);
33+
}
34+
35+
public IRepositoryModel SourceRepository { get; private set; }
36+
37+
public IRepositoryModel DestinationRepository { get; private set; }
38+
39+
public IReactiveCommand<object> SwitchFork { get; }
40+
41+
public string Title => Resources.SwitchOriginTitle;
42+
43+
public IObservable<object> Done => SwitchFork.Where(value => value != null);
44+
45+
public void Initialize(ILocalRepositoryModel sourceRepository, IRemoteRepositoryModel remoteRepository)
46+
{
47+
SourceRepository = sourceRepository;
48+
DestinationRepository = remoteRepository;
49+
}
50+
51+
IObservable<object> OnSwitchFork(object o)
52+
{
53+
return repositoryForkService.SwitchRemotes(DestinationRepository, UpdateOrigin, AddUpstream, ResetMasterTracking);
54+
}
55+
56+
bool resetMasterTracking = true;
57+
public bool ResetMasterTracking
58+
{
59+
get { return resetMasterTracking; }
60+
set { this.RaiseAndSetIfChanged(ref resetMasterTracking, value); }
61+
}
62+
63+
bool addUpstream = true;
64+
public bool AddUpstream
65+
{
66+
get { return addUpstream; }
67+
set { this.RaiseAndSetIfChanged(ref addUpstream, value); }
68+
}
69+
70+
bool updateOrigin = true;
71+
public bool UpdateOrigin
72+
{
73+
get { return updateOrigin; }
74+
set { this.RaiseAndSetIfChanged(ref updateOrigin, value); }
75+
}
76+
}
77+
}

src/GitHub.App/ViewModels/Dialog/ForkRepositoryViewModel.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using System.Reactive.Linq;
34
using System.Threading.Tasks;
45
using GitHub.Extensions;
56
using GitHub.Logging;
@@ -17,20 +18,21 @@ public class ForkRepositoryViewModel : PagedDialogViewModelBase, IForkRepository
1718
static readonly ILogger log = LogManager.ForContext<ForkRepositoryViewModel>();
1819

1920
readonly IForkRepositorySelectViewModel selectPage;
21+
readonly IForkRepositorySwitchViewModel switchPage;
2022
readonly IForkRepositoryExecuteViewModel executePage;
21-
private readonly IRepositoryForkService repositoryForkService;
23+
2224
ILocalRepositoryModel repository;
2325
IConnection connection;
2426

2527
[ImportingConstructor]
2628
public ForkRepositoryViewModel(
2729
IForkRepositorySelectViewModel selectPage,
28-
IForkRepositoryExecuteViewModel executePage,
29-
IRepositoryForkService repositoryForkService)
30+
IForkRepositorySwitchViewModel switchPage,
31+
IForkRepositoryExecuteViewModel executePage)
3032
{
3133
this.selectPage = selectPage;
3234
this.executePage = executePage;
33-
this.repositoryForkService = repositoryForkService;
35+
this.switchPage = switchPage;
3436

3537
Completed = ReactiveCommand.Create();
3638

@@ -40,7 +42,7 @@ public ForkRepositoryViewModel(
4042

4143
private ReactiveCommand<object> Completed { get; }
4244

43-
public override IObservable<object> Done => executePage.Done;
45+
public override IObservable<object> Done => Observable.SelectMany(executePage.Done, switchPage.Done);
4446

4547
public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection connection)
4648
{
@@ -58,6 +60,8 @@ async Task ShowExecutePage(IAccount account)
5860

5961
void ShowSwitchRepositoryPath(IRemoteRepositoryModel remoteRepository)
6062
{
63+
switchPage.Initialize(repository, remoteRepository);
64+
Content = switchPage;
6165
}
6266
}
6367
}

src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<Compile Include="Services\PullRequestSessionExtensions.cs" />
187187
<Compile Include="ViewModels\Dialog\IDialogContentViewModel.cs" />
188188
<Compile Include="ViewModels\Dialog\IForkRepositoryExecuteViewModel.cs" />
189+
<Compile Include="ViewModels\Dialog\IForkRepositorySwitchViewModel.cs" />
189190
<Compile Include="ViewModels\Dialog\IForkRepositoryViewModel.cs" />
190191
<Compile Include="ViewModels\Dialog\IForkRepositorySelectViewModel.cs" />
191192
<Compile Include="ViewModels\Dialog\IGitHubDialogWindowViewModel.cs" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using GitHub.Models;
2+
using ReactiveUI;
3+
4+
namespace GitHub.ViewModels.Dialog
5+
{
6+
/// <summary>
7+
/// View model for selecting the fork to switch to
8+
/// </summary>
9+
public interface IForkRepositorySwitchViewModel : IDialogContentViewModel
10+
{
11+
IRepositoryModel SourceRepository { get; }
12+
13+
IRepositoryModel DestinationRepository { get; }
14+
15+
/// <summary>
16+
/// Gets a command that is executed when the user clicks the "Fork" button.
17+
/// </summary>
18+
IReactiveCommand<object> SwitchFork { get; }
19+
20+
bool ResetMasterTracking { get; set; }
21+
22+
bool AddUpstream { get; set; }
23+
24+
bool UpdateOrigin { get; set; }
25+
26+
/// <summary>
27+
/// Initializes the view model.
28+
/// </summary>
29+
/// <param name="sourceRepository">The repository to fork.</param>
30+
/// <param name="remoteRepository"></param>
31+
void Initialize(ILocalRepositoryModel sourceRepository, IRemoteRepositoryModel remoteRepository);
32+
}
33+
}

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@
356356
<DependentUpon>OptionsControl.xaml</DependentUpon>
357357
</Compile>
358358
<Compile Include="Views\ContentView.cs" />
359+
<Compile Include="Views\Dialog\ForkRepositorySwitchView.xaml.cs">
360+
<DependentUpon>ForkRepositorySwitchView.xaml</DependentUpon>
361+
</Compile>
359362
<Compile Include="Views\Dialog\ForkRepositoryExecuteView.xaml.cs">
360363
<DependentUpon>ForkRepositoryExecuteView.xaml</DependentUpon>
361364
</Compile>
@@ -520,6 +523,10 @@
520523
<Generator>MSBuild:Compile</Generator>
521524
<CustomToolNamespace>GitHub.VisualStudio.UI</CustomToolNamespace>
522525
</Page>
526+
<Page Include="Views\Dialog\ForkRepositorySwitchView.xaml">
527+
<Generator>MSBuild:Compile</Generator>
528+
<SubType>Designer</SubType>
529+
</Page>
523530
<Page Include="Views\Dialog\ForkRepositoryExecuteView.xaml">
524531
<SubType>Designer</SubType>
525532
<Generator>MSBuild:Compile</Generator>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<UserControl x:Class="GitHub.VisualStudio.Views.Dialog.ForkRepositorySwitchView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
7+
xmlns:sampleData="clr-namespace:GitHub.SampleData;assembly=GitHub.App"
8+
Margin="8"
9+
mc:Ignorable="d"
10+
d:DesignHeight="300" d:DesignWidth="300">
11+
12+
<d:DesignProperties.DataContext>
13+
<sampleData:ForkRepositorySwitchViewModelDesigner/>
14+
</d:DesignProperties.DataContext>
15+
16+
<StackPanel>
17+
<ItemsControl Margin="8,16,8,8">
18+
<ItemsControl.Resources>
19+
<Style x:Key="ItemBorder" TargetType="Border">
20+
<Setter Property="Background" Value="#10000000"/>
21+
<Setter Property="CornerRadius" Value="3"/>
22+
<Setter Property="Margin" Value="4"/>
23+
<Setter Property="Padding" Value="4,8"/>
24+
</Style>
25+
<Style TargetType="CheckBox">
26+
<Setter Property="Margin" Value="0,1,6,0"/>
27+
<Setter Property="VerticalAlignment" Value="Center"/>
28+
</Style>
29+
</ItemsControl.Resources>
30+
<Border Style="{StaticResource ItemBorder}">
31+
<DockPanel>
32+
<CheckBox IsChecked="{Binding UpdateOrigin}"/>
33+
<TextBlock TextWrapping="Wrap">
34+
Update your local repository's <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">origin</Run> to point to
35+
<Hyperlink><Run Text="{Binding DestinationRepository.CloneUrl, Mode=OneWay}"/></Hyperlink>
36+
</TextBlock>
37+
</DockPanel>
38+
</Border>
39+
<Border Style="{StaticResource ItemBorder}">
40+
<DockPanel>
41+
<CheckBox IsChecked="{Binding AddUpstream}"/>
42+
<TextBlock TextWrapping="Wrap">
43+
Add an <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">upstream</Run> remote pointing to
44+
<Hyperlink><Run Text="{Binding SourceRepository.CloneUrl, Mode=OneWay}"/></Hyperlink>
45+
</TextBlock>
46+
</DockPanel>
47+
</Border>
48+
<Border Style="{StaticResource ItemBorder}">
49+
<DockPanel>
50+
<CheckBox IsChecked="{Binding ResetMasterTracking}"/>
51+
<TextBlock TextWrapping="Wrap">
52+
Reset the <Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">master</Run> branch to
53+
<Run Style="{DynamicResource {x:Static markdig:Styles.CodeStyleKey}}">upstream/master</Run>
54+
</TextBlock>
55+
</DockPanel>
56+
</Border>
57+
<Border Style="{StaticResource ItemBorder}">
58+
<Button Click="repoSwitchButton_OnClick">Switch Origin</Button>
59+
</Border>
60+
</ItemsControl>
61+
</StackPanel>
62+
</UserControl>

0 commit comments

Comments
 (0)