Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 06cdff2

Browse files
Merge pull request #299 from github-for-unity/fixes/publish-view-loading
Fixes to keep the publish view from loading twice
2 parents acc6efc + b069134 commit 06cdff2

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PopupWindow.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public static PopupWindow Open(PopupViewType popupViewType, Action<bool> onClose
4141

4242
popupWindow.ActiveViewType = popupViewType;
4343
popupWindow.titleContent = new GUIContent(popupWindow.ActiveView.Title, Styles.SmallLogo);
44-
45-
popupWindow.InitializeWindow(EntryPoint.ApplicationManager);
44+
popupWindow.OnEnable();
4645
popupWindow.Show();
46+
popupWindow.Refresh();
4747

4848
return popupWindow;
4949
}
@@ -64,7 +64,6 @@ public override void Initialize(IApplicationManager applicationManager)
6464
public override void OnEnable()
6565
{
6666
base.OnEnable();
67-
6867
minSize = maxSize = ActiveView.Size;
6968
ActiveView.OnEnable();
7069
}
@@ -75,6 +74,12 @@ public override void OnDisable()
7574
ActiveView.OnDisable();
7675
}
7776

77+
public override void OnDataUpdate()
78+
{
79+
base.OnDataUpdate();
80+
ActiveView.OnDataUpdate();
81+
}
82+
7883
public override void OnUI()
7984
{
8085
base.OnUI();
@@ -132,7 +137,14 @@ private Subview ActiveView
132137
private PopupViewType ActiveViewType
133138
{
134139
get { return activeViewType; }
135-
set { activeViewType = value; }
140+
set
141+
{
142+
if (activeViewType != value)
143+
{
144+
ActiveView.OnDisable();
145+
activeViewType = value;
146+
}
147+
}
136148
}
137149
}
138150
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PublishView.cs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Octokit;
45
using UnityEditor;
@@ -23,6 +24,7 @@ class PublishView : Subview
2324

2425
[SerializeField] private string username;
2526
[SerializeField] private string[] owners = { OwnersDefaultText };
27+
[SerializeField] private IList<Organization> organizations;
2628
[SerializeField] private int selectedOwner;
2729
[SerializeField] private string repoName = String.Empty;
2830
[SerializeField] private string repoDescription = "";
@@ -31,6 +33,7 @@ class PublishView : Subview
3133
[NonSerialized] private IApiClient client;
3234
[NonSerialized] private bool isBusy;
3335
[NonSerialized] private string error;
36+
[NonSerialized] private bool organizationsNeedLoading;
3437

3538
public IApiClient Client
3639
{
@@ -56,23 +59,43 @@ public IApiClient Client
5659
}
5760
}
5861

62+
public override void OnEnable()
63+
{
64+
base.OnEnable();
65+
organizationsNeedLoading = organizations == null && !isBusy;
66+
}
67+
68+
public override void OnDataUpdate()
69+
{
70+
base.OnDataUpdate();
71+
MaybeUpdateData();
72+
}
73+
74+
private void MaybeUpdateData()
75+
{
76+
if (organizationsNeedLoading)
77+
{
78+
organizationsNeedLoading = false;
79+
LoadOrganizations();
80+
}
81+
}
82+
5983
public override void InitializeView(IView parent)
6084
{
6185
base.InitializeView(parent);
6286
Title = WindowTitle;
6387
Size = viewSize;
64-
PopulateView();
6588
}
6689

67-
private void PopulateView()
90+
private void LoadOrganizations()
6891
{
69-
try
92+
var keychainConnections = Platform.Keychain.Connections;
93+
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
94+
if (keychainConnections.Any())
7095
{
71-
var keychainConnections = Platform.Keychain.Connections;
72-
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
73-
if (keychainConnections.Any())
96+
try
7497
{
75-
Logger.Trace("GetCurrentUser");
98+
Logger.Trace("Loading Keychain");
7699

77100
isBusy = true;
78101

@@ -87,28 +110,30 @@ private void PopulateView()
87110
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
88111
username = keychainConnections.First().Username;
89112

90-
Client.GetOrganizations(organizations => {
113+
Logger.Trace("Loading Organizations");
114+
115+
Client.GetOrganizations(orgs => {
116+
organizations = orgs;
91117
Logger.Trace("Loaded {0} organizations", organizations.Count);
92118

93119
var organizationLogins = organizations
94-
.OrderBy(organization => organization.Login)
95-
.Select(organization => organization.Login);
120+
.OrderBy(organization => organization.Login).Select(organization => organization.Login);
96121

97122
owners = new[] { OwnersDefaultText, username }.Union(organizationLogins).ToArray();
98123

99124
isBusy = false;
100125
});
101126
});
102127
}
103-
else
128+
catch (Exception e)
104129
{
105-
Logger.Warning("No Keychain connections to use");
130+
Logger.Error(e, "Error PopulateView & GetOrganizations");
131+
isBusy = false;
106132
}
107133
}
108-
catch (Exception e)
134+
else
109135
{
110-
Logger.Error(e, "Error PopulateView & GetOrganizations");
111-
throw;
136+
Logger.Warning("No Keychain connections to use");
112137
}
113138
}
114139

@@ -196,6 +221,7 @@ public override void OnGUI()
196221
EditorGUI.BeginDisabledGroup(!IsFormValid);
197222
if (GUILayout.Button(PublishViewCreateButton))
198223
{
224+
GUI.FocusControl(null);
199225
isBusy = true;
200226

201227
var organization = owners[selectedOwner] == username ? null : owners[selectedOwner];

0 commit comments

Comments
 (0)