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

Commit

Permalink
Merge pull request #299 from github-for-unity/fixes/publish-view-loading
Browse files Browse the repository at this point in the history
Fixes to keep the publish view from loading twice
  • Loading branch information
StanleyGoldman authored Sep 12, 2017
2 parents acc6efc + b069134 commit 06cdff2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
20 changes: 16 additions & 4 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PopupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public static PopupWindow Open(PopupViewType popupViewType, Action<bool> onClose

popupWindow.ActiveViewType = popupViewType;
popupWindow.titleContent = new GUIContent(popupWindow.ActiveView.Title, Styles.SmallLogo);

popupWindow.InitializeWindow(EntryPoint.ApplicationManager);
popupWindow.OnEnable();
popupWindow.Show();
popupWindow.Refresh();

return popupWindow;
}
Expand All @@ -64,7 +64,6 @@ public override void Initialize(IApplicationManager applicationManager)
public override void OnEnable()
{
base.OnEnable();

minSize = maxSize = ActiveView.Size;
ActiveView.OnEnable();
}
Expand All @@ -75,6 +74,12 @@ public override void OnDisable()
ActiveView.OnDisable();
}

public override void OnDataUpdate()
{
base.OnDataUpdate();
ActiveView.OnDataUpdate();
}

public override void OnUI()
{
base.OnUI();
Expand Down Expand Up @@ -132,7 +137,14 @@ private Subview ActiveView
private PopupViewType ActiveViewType
{
get { return activeViewType; }
set { activeViewType = value; }
set
{
if (activeViewType != value)
{
ActiveView.OnDisable();
activeViewType = value;
}
}
}
}
}
56 changes: 41 additions & 15 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PublishView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Octokit;
using UnityEditor;
Expand All @@ -23,6 +24,7 @@ class PublishView : Subview

[SerializeField] private string username;
[SerializeField] private string[] owners = { OwnersDefaultText };
[SerializeField] private IList<Organization> organizations;
[SerializeField] private int selectedOwner;
[SerializeField] private string repoName = String.Empty;
[SerializeField] private string repoDescription = "";
Expand All @@ -31,6 +33,7 @@ class PublishView : Subview
[NonSerialized] private IApiClient client;
[NonSerialized] private bool isBusy;
[NonSerialized] private string error;
[NonSerialized] private bool organizationsNeedLoading;

public IApiClient Client
{
Expand All @@ -56,23 +59,43 @@ public IApiClient Client
}
}

public override void OnEnable()
{
base.OnEnable();
organizationsNeedLoading = organizations == null && !isBusy;
}

public override void OnDataUpdate()
{
base.OnDataUpdate();
MaybeUpdateData();
}

private void MaybeUpdateData()
{
if (organizationsNeedLoading)
{
organizationsNeedLoading = false;
LoadOrganizations();
}
}

public override void InitializeView(IView parent)
{
base.InitializeView(parent);
Title = WindowTitle;
Size = viewSize;
PopulateView();
}

private void PopulateView()
private void LoadOrganizations()
{
try
var keychainConnections = Platform.Keychain.Connections;
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
if (keychainConnections.Any())
{
var keychainConnections = Platform.Keychain.Connections;
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
if (keychainConnections.Any())
try
{
Logger.Trace("GetCurrentUser");
Logger.Trace("Loading Keychain");

isBusy = true;

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

Client.GetOrganizations(organizations => {
Logger.Trace("Loading Organizations");

Client.GetOrganizations(orgs => {
organizations = orgs;
Logger.Trace("Loaded {0} organizations", organizations.Count);

var organizationLogins = organizations
.OrderBy(organization => organization.Login)
.Select(organization => organization.Login);
.OrderBy(organization => organization.Login).Select(organization => organization.Login);

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

isBusy = false;
});
});
}
else
catch (Exception e)
{
Logger.Warning("No Keychain connections to use");
Logger.Error(e, "Error PopulateView & GetOrganizations");
isBusy = false;
}
}
catch (Exception e)
else
{
Logger.Error(e, "Error PopulateView & GetOrganizations");
throw;
Logger.Warning("No Keychain connections to use");
}
}

Expand Down Expand Up @@ -196,6 +221,7 @@ public override void OnGUI()
EditorGUI.BeginDisabledGroup(!IsFormValid);
if (GUILayout.Button(PublishViewCreateButton))
{
GUI.FocusControl(null);
isBusy = true;

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

0 comments on commit 06cdff2

Please sign in to comment.