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

Commit 26f76ec

Browse files
committed
Show Create Repository UI outside of VS
1 parent c7af72c commit 26f76ec

File tree

6 files changed

+72
-63
lines changed

6 files changed

+72
-63
lines changed

src/GitHub.VisualStudio.16/CompositionServices.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,19 @@ public CompositionContainer CreateCompositionContainer(ExportProvider defaultExp
4646
var loginManager = CreateLoginManager(compositionContainer);
4747
compositionContainer.ComposeExportedValue<ILoginManager>(loginManager);
4848

49+
// HACK: Stop ViewLocator from attempting to fetch a global service
50+
var viewViewModelFactory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
51+
InitializeViewLocator(viewViewModelFactory);
52+
4953
return compositionContainer;
5054
}
5155

56+
static void InitializeViewLocator(IViewViewModelFactory viewViewModelFactory)
57+
{
58+
var factoryProviderFiled = typeof(ViewLocator).GetField("factoryProvider", BindingFlags.Static | BindingFlags.NonPublic);
59+
factoryProviderFiled.SetValue(null, viewViewModelFactory);
60+
}
61+
5262
private static LoginManager CreateLoginManager(CompositionContainer compositionContainer)
5363
{
5464
var keychain = compositionContainer.GetExportedValue<IKeychain>();
@@ -90,27 +100,6 @@ static TypeCatalog GetCatalog(Assembly assembly)
90100
}
91101
}
92102

93-
public class ViewLocatorInitializer : IDisposable
94-
{
95-
object value;
96-
97-
public ViewLocatorInitializer(IViewViewModelFactory viewViewModelFactory)
98-
{
99-
value = FactoryProviderFiled().GetValue(null);
100-
FactoryProviderFiled().SetValue(null, viewViewModelFactory);
101-
}
102-
103-
public void Dispose()
104-
{
105-
FactoryProviderFiled().SetValue(null, value);
106-
}
107-
108-
private static FieldInfo FactoryProviderFiled()
109-
{
110-
return typeof(ViewLocator).GetField("factoryProvider", BindingFlags.Static | BindingFlags.NonPublic);
111-
}
112-
}
113-
114103
public class MyGitHubServiceProvider : IGitHubServiceProvider
115104
{
116105
readonly IServiceProvider serviceProvider;

src/GitHub.VisualStudio.16/GitHub.VisualStudio.16.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@
209209
<IncludeInVSIX>true</IncludeInVSIX>
210210
<VSIXSubPath>lib\win32\x86</VSIXSubPath>
211211
</Content>
212+
<Content Include="..\..\build\Content\x86\e_sqlite3.dll">
213+
<Link>x86\e_sqlite3.dll</Link>
214+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
215+
<IncludeInVSIX>true</IncludeInVSIX>
216+
<VSIXSubPath>x86</VSIXSubPath>
217+
</Content>
212218
</ItemGroup>
213219
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
214220
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />

src/GitHub.VisualStudio.16/OpenFromGitHubCommand.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,6 @@ private void Execute(object sender, EventArgs e)
9999
}
100100
}
101101

102-
[STAThread]
103-
static async Task Go()
104-
{
105-
var window = new Window();
106-
var app = new Application();
107-
app.Startup += App_Startup;
108-
app.Run(window);
109-
}
110-
111-
private static void App_Startup(object sender, StartupEventArgs e)
112-
{
113-
ShowCloneDialogAsync(null);
114-
}
115-
116102
[STAThread]
117103
static async Task ShowCloneDialogAsync(IServiceProvider serviceProvider)
118104
{
@@ -121,17 +107,13 @@ static async Task ShowCloneDialogAsync(IServiceProvider serviceProvider)
121107
var compositionServices = new CompositionServices();
122108
var compositionContainer = compositionServices.CreateCompositionContainer(componentModel.DefaultExportProvider);
123109

124-
var viewViewModelFactory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
125-
using (new ViewLocatorInitializer(viewViewModelFactory))
110+
var url = null as string;
111+
var dialogService = compositionContainer.GetExportedValue<IDialogService>();
112+
var cloneDialogResult = await dialogService.ShowCloneDialog(null, url);
113+
if (cloneDialogResult != null)
126114
{
127-
var url = null as string;
128-
var dialogService = compositionContainer.GetExportedValue<IDialogService>();
129-
var cloneDialogResult = await dialogService.ShowCloneDialog(null, url);
130-
if (cloneDialogResult != null)
131-
{
132-
var repositoryCloneService = compositionContainer.GetExportedValue<IRepositoryCloneService>();
133-
await repositoryCloneService.CloneOrOpenRepository(cloneDialogResult);
134-
}
115+
var repositoryCloneService = compositionContainer.GetExportedValue<IRepositoryCloneService>();
116+
await repositoryCloneService.CloneOrOpenRepository(cloneDialogResult);
135117
}
136118
}
137119
}

src/GitHub.VisualStudio.TestApp/GitHub.VisualStudio.TestApp.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38+
<Reference Include="Akavache, Version=6.0.0.0, Culture=neutral, PublicKeyToken=decff03a04a41f69, processorArchitecture=MSIL">
39+
<SpecificVersion>False</SpecificVersion>
40+
<HintPath>..\..\build\Content\Akavache.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Akavache.Sqlite3, Version=6.0.0.0, Culture=neutral, PublicKeyToken=decff03a04a41f69, processorArchitecture=MSIL">
43+
<SpecificVersion>False</SpecificVersion>
44+
<HintPath>..\..\build\Content\Akavache.Sqlite3.dll</HintPath>
45+
</Reference>
3846
<Reference Include="GitHub.Exports">
3947
<HintPath>..\..\build\Content\GitHub.Exports.dll</HintPath>
4048
</Reference>
@@ -47,6 +55,13 @@
4755
<Reference Include="ReactiveUI">
4856
<HintPath>..\..\build\Content\ReactiveUI.dll</HintPath>
4957
</Reference>
58+
<Reference Include="ReactiveUI.Events.WPF, Version=8.7.0.0, Culture=neutral, PublicKeyToken=31f8874b2ce7ed44, processorArchitecture=MSIL">
59+
<SpecificVersion>False</SpecificVersion>
60+
<HintPath>..\..\build\Content\ReactiveUI.Events.WPF.dll</HintPath>
61+
</Reference>
62+
<Reference Include="ReactiveUI.Wpf">
63+
<HintPath>..\..\build\Content\ReactiveUI.Wpf.dll</HintPath>
64+
</Reference>
5065
<Reference Include="Splat">
5166
<HintPath>..\..\build\Content\Splat.dll</HintPath>
5267
</Reference>

src/GitHub.VisualStudio.TestApp/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
mc:Ignorable="d"
88
Title="MainWindow" Height="450" Width="800">
99
<Grid>
10-
<Button Content="Open from GitHub" HorizontalAlignment="Left" Margin="57,55,0,0" VerticalAlignment="Top" Width="133" Click="Button_Click"/>
11-
10+
<Button Content="Open from GitHub" HorizontalAlignment="Left" Margin="57,55,0,0" VerticalAlignment="Top" Width="133" Click="CloneOrOpenRepository_Click" />
11+
<Button Content="Create Repository" HorizontalAlignment="Left" Margin="57,80,0,0" VerticalAlignment="Top" Width="133" Click="CreateRepository_Click" />
1212
</Grid>
1313
</Window>

src/GitHub.VisualStudio.TestApp/MainWindow.xaml.cs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Windows;
33
using System.ComponentModel.Composition;
44
using System.ComponentModel.Composition.Hosting;
5-
using GitHub.Factories;
65
using GitHub.Services;
76
using GitHub.VisualStudio.UI.Services;
87
using GitHubCore;
@@ -21,12 +20,43 @@ public MainWindow()
2120
InitializeComponent();
2221
}
2322

24-
private void Button_Click(object sender, RoutedEventArgs e)
23+
private void CloneOrOpenRepository_Click(object sender, RoutedEventArgs e)
2524
{
2625
CloneOrOpenRepositoryAsync();
2726
}
2827

28+
private void CreateRepository_Click(object sender, RoutedEventArgs e)
29+
{
30+
CreateRepositoryAsync();
31+
}
32+
33+
async Task CreateRepositoryAsync()
34+
{
35+
var compositionContainer = CreateCompositionContainer();
36+
37+
var dialogService = compositionContainer.GetExportedValue<IDialogService>();
38+
var connection = await dialogService.ShowLoginDialog();
39+
if(connection != null)
40+
{
41+
await dialogService.ShowCreateRepositoryDialog(connection);
42+
}
43+
}
44+
2945
async Task CloneOrOpenRepositoryAsync()
46+
{
47+
var compositionContainer = CreateCompositionContainer();
48+
49+
var url = null as string;
50+
var dialogService = compositionContainer.GetExportedValue<IDialogService>();
51+
var cloneDialogResult = await dialogService.ShowCloneDialog(null, url);
52+
if (cloneDialogResult != null)
53+
{
54+
var repositoryCloneService = compositionContainer.GetExportedValue<IRepositoryCloneService>();
55+
await repositoryCloneService.CloneOrOpenRepository(cloneDialogResult);
56+
}
57+
}
58+
59+
CompositionContainer CreateCompositionContainer()
3060
{
3161
var compositionServices = new CompositionServices();
3262
var exports = CreateOutOfProcExports();
@@ -35,19 +65,7 @@ async Task CloneOrOpenRepositoryAsync()
3565
var gitHubServiceProvider = compositionContainer.GetExportedValue<IGitHubServiceProvider>();
3666
var externalShowDialogService = new ExternalShowDialogService(gitHubServiceProvider, this);
3767
compositionContainer.ComposeExportedValue<IShowDialogService>(externalShowDialogService);
38-
39-
var viewViewModelFactory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
40-
using (new ViewLocatorInitializer(viewViewModelFactory))
41-
{
42-
var url = null as string;
43-
var dialogService = compositionContainer.GetExportedValue<IDialogService>();
44-
var cloneDialogResult = await dialogService.ShowCloneDialog(null, url);
45-
if (cloneDialogResult != null)
46-
{
47-
var repositoryCloneService = compositionContainer.GetExportedValue<IRepositoryCloneService>();
48-
await repositoryCloneService.CloneOrOpenRepository(cloneDialogResult);
49-
}
50-
}
68+
return compositionContainer;
5169
}
5270

5371
static CompositionContainer CreateOutOfProcExports()
@@ -66,6 +84,5 @@ public object GetService(Type serviceType)
6684
return null;
6785
}
6886
}
69-
7087
}
7188
}

0 commit comments

Comments
 (0)