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

Commit 4bdd3f9

Browse files
committed
Fix reacting to new repos on the list
If the user is logged out and clicks Create or Clone, they'll go through the login dialog and the repository list will get populated as soon as that's done, before the actual create/clone action starts. We don't want to handle those "new" repos on the list as if they've just been cloned/created.
1 parent 53bac89 commit 4bdd3f9

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/GitHub.Exports/Exports/ExportMetadata.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.ComponentModel.Composition;
33
using GitHub.UI;
44
using GitHub.ViewModels;
5+
using System.Windows.Controls;
6+
using System.Linq;
57

68
namespace GitHub.Exports {
79

@@ -42,4 +44,12 @@ public interface IViewModelMetadata
4244
{
4345
UIViewType ViewType { get; }
4446
}
47+
48+
public static class ExportViewAttributeExtensions
49+
{
50+
public static bool IsViewType(this UserControl c, UIViewType type)
51+
{
52+
return c.GetType().GetCustomAttributesData().Any(x => x.AttributeType.Equals(typeof(ExportViewAttribute)) && (UIViewType)x.NamedArguments[0].TypedValue.Value == type);
53+
}
54+
}
4555
}

src/GitHub.Exports/Services/IUIProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel.Composition.Hosting;
33
using GitHub.Models;
44
using GitHub.UI;
5+
using System.Windows.Controls;
56

67
namespace GitHub.Services
78
{
@@ -20,7 +21,7 @@ public interface IUIProvider
2021
void AddService(Type t, object instance);
2122
void RemoveService(Type t);
2223

23-
IObservable<object> SetupUI(UIControllerFlow controllerFlow, IConnection connection);
24+
IObservable<UserControl> SetupUI(UIControllerFlow controllerFlow, IConnection connection);
2425
void RunUI();
2526
void RunUI(UIControllerFlow controllerFlow, IConnection connection);
2627
}

src/GitHub.VisualStudio/Services/UIProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using NLog;
1818
using System.Reactive.Linq;
1919
using GitHub.Infrastructure;
20+
using System.Windows.Controls;
2021

2122
namespace GitHub.VisualStudio
2223
{
@@ -184,12 +185,12 @@ public void RemoveService(Type t)
184185
}
185186

186187
UI.WindowController windowController;
187-
public IObservable<object> SetupUI(UIControllerFlow controllerFlow, [AllowNull] IConnection connection)
188+
public IObservable<UserControl> SetupUI(UIControllerFlow controllerFlow, [AllowNull] IConnection connection)
188189
{
189190
if (!Initialized)
190191
{
191192
log.Error("ExportProvider is not initialized, cannot setup UI.");
192-
return Observable.Return<object>(null);
193+
return Observable.Return<UserControl>(null);
193194
}
194195

195196
StopUI();

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Windows.Data;
1717
using System.ComponentModel;
1818
using ReactiveUI;
19+
using GitHub.Exports;
1920

2021
namespace GitHub.VisualStudio.TeamExplorer.Connect
2122
{
@@ -227,13 +228,11 @@ void RefreshRepositories()
227228

228229
public void DoCreate()
229230
{
230-
isCreating = true;
231231
StartFlow(UIControllerFlow.Create);
232232
}
233233

234234
public void DoClone()
235235
{
236-
isCloning = true;
237236
StartFlow(UIControllerFlow.Clone);
238237
}
239238

@@ -272,7 +271,15 @@ void StartFlow(UIControllerFlow controllerFlow)
272271
{
273272
var uiProvider = ServiceProvider.GetExportedValue<IUIProvider>();
274273
uiProvider.GitServiceProvider = ServiceProvider;
275-
uiProvider.RunUI(controllerFlow, SectionConnection);
274+
var ret = uiProvider.SetupUI(controllerFlow, SectionConnection);
275+
ret.Subscribe((c) =>
276+
{
277+
if (c.IsViewType(UIViewType.Clone))
278+
isCloning = true;
279+
else if (c.IsViewType(UIViewType.Create))
280+
isCreating = true;
281+
});
282+
uiProvider.RunUI();
276283
}
277284

278285
bool disposed;

0 commit comments

Comments
 (0)