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

Commit 7294e09

Browse files
Merge pull request #194 from github-for-unity/fixes/popup-window-refactor
Refactoring popups to use the same window class
2 parents ffc1d53 + 7105dec commit 7294e09

File tree

12 files changed

+205
-194
lines changed

12 files changed

+205
-194
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<Compile Include="EntryPoint.cs" />
8686
<Compile Include="Misc\Installer.cs" />
8787
<Compile Include="UI\BaseWindow.cs" />
88-
<Compile Include="UI\PublishWindow.cs" />
88+
<Compile Include="UI\PopupWindow.cs" />
8989
<Compile Include="UI\ProjectWindowInterface.cs" />
9090
<Compile Include="Misc\Styles.cs" />
9191
<Compile Include="Misc\Utility.cs" />
@@ -95,12 +95,12 @@
9595
<Compile Include="Tasks\TaskException.cs" />
9696
<Compile Include="Tools\MozRoots.cs" />
9797
<Compile Include="UI\AuthenticationView.cs" />
98-
<Compile Include="UI\AuthenticationWindow.cs" />
9998
<Compile Include="UI\BranchesView.cs" />
10099
<Compile Include="UI\ChangesetTreeView.cs" />
101100
<Compile Include="UI\ChangesView.cs" />
102101
<Compile Include="UI\HistoryView.cs" />
103102
<Compile Include="UI\IView.cs" />
103+
<Compile Include="UI\LoadingView.cs" />
104104
<Compile Include="UI\PublishView.cs" />
105105
<Compile Include="UI\SettingsView.cs" />
106106
<Compile Include="UI\Subview.cs" />

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ namespace GitHub.Unity
77
[Serializable]
88
class AuthenticationView : Subview
99
{
10-
const string usernameLabel = "Username";
11-
const string passwordLabel = "Password";
12-
const string twofaLabel = "2FA Code";
13-
const string loginButton = "Sign in";
14-
const string backButton = "Back";
15-
const string authTitle = "Sign in to GitHub";
16-
const string twofaTitle = "Two-Factor Authentication";
17-
const string twofaDescription = "Open the two-factor authentication app on your device to view your 2FA code and verify your identity.";
18-
const string twofaButton = "Verify";
10+
private static readonly Vector2 viewSize = new Vector2(290, 290);
11+
12+
private const string WindowTitle = "Authenticate";
13+
private const string UsernameLabel = "Username";
14+
private const string PasswordLabel = "Password";
15+
private const string TwofaLabel = "2FA Code";
16+
private const string LoginButton = "Sign in";
17+
private const string BackButton = "Back";
18+
private const string AuthTitle = "Sign in to GitHub";
19+
private const string TwofaTitle = "Two-Factor Authentication";
20+
private const string TwofaDescription = "Open the two-factor authentication app on your device to view your 2FA code and verify your identity.";
21+
private const string TwofaButton = "Verify";
1922

2023
[SerializeField] private Vector2 scroll;
2124
[SerializeField] private string username = "";
@@ -59,6 +62,8 @@ public override void InitializeView(IView parent)
5962
{
6063
base.InitializeView(parent);
6164
need2fa = isBusy = false;
65+
Title = WindowTitle;
66+
Size = viewSize;
6267
}
6368

6469
public override void OnEnable()
@@ -91,7 +96,7 @@ public override void OnGUI()
9196
GUILayout.BeginVertical();
9297
{
9398
GUILayout.Space(11);
94-
GUILayout.Label(authTitle, Styles.HeaderRepoLabelStyle);
99+
GUILayout.Label(AuthTitle, Styles.HeaderRepoLabelStyle);
95100
}
96101
GUILayout.EndVertical();
97102
}
@@ -136,14 +141,14 @@ private void OnGUILogin()
136141
GUILayout.Space(3);
137142
GUILayout.BeginHorizontal();
138143
{
139-
username = EditorGUILayout.TextField(usernameLabel, username, Styles.TextFieldStyle);
144+
username = EditorGUILayout.TextField(UsernameLabel ,username, Styles.TextFieldStyle);
140145
}
141146
GUILayout.EndHorizontal();
142147

143148
GUILayout.Space(Styles.BaseSpacing);
144149
GUILayout.BeginHorizontal();
145150
{
146-
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
151+
password = EditorGUILayout.PasswordField(PasswordLabel, password, Styles.TextFieldStyle);
147152
}
148153
GUILayout.EndHorizontal();
149154

@@ -153,7 +158,7 @@ private void OnGUILogin()
153158
GUILayout.BeginHorizontal();
154159
{
155160
GUILayout.FlexibleSpace();
156-
if (GUILayout.Button(loginButton) || (!isBusy && enterPressed))
161+
if (GUILayout.Button(LoginButton) || (!isBusy && enterPressed))
157162
{
158163
GUI.FocusControl(null);
159164
isBusy = true;
@@ -169,15 +174,15 @@ private void OnGUI2FA()
169174
{
170175
GUILayout.BeginVertical();
171176
{
172-
GUILayout.Label(twofaTitle, EditorStyles.boldLabel);
173-
GUILayout.Label(twofaDescription, EditorStyles.wordWrappedLabel);
177+
GUILayout.Label(TwofaTitle, EditorStyles.boldLabel);
178+
GUILayout.Label(TwofaDescription, EditorStyles.wordWrappedLabel);
174179

175180
EditorGUI.BeginDisabledGroup(isBusy);
176181
{
177182
GUILayout.Space(Styles.BaseSpacing);
178183
GUILayout.BeginHorizontal();
179184
{
180-
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
185+
two2fa = EditorGUILayout.TextField(TwofaLabel, two2fa, Styles.TextFieldStyle);
181186
}
182187
GUILayout.EndHorizontal();
183188

@@ -188,14 +193,14 @@ private void OnGUI2FA()
188193
GUILayout.BeginHorizontal();
189194
{
190195
GUILayout.FlexibleSpace();
191-
if (GUILayout.Button(backButton))
196+
if (GUILayout.Button(BackButton))
192197
{
193198
GUI.FocusControl(null);
194199
need2fa = false;
195200
Redraw();
196201
}
197202

198-
if (GUILayout.Button(twofaButton) || (!isBusy && enterPressed))
203+
if (GUILayout.Button(TwofaButton) || (!isBusy && enterPressed))
199204
{
200205
GUI.FocusControl(null);
201206
isBusy = true;

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

Lines changed: 0 additions & 77 deletions
This file was deleted.

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ namespace GitHub.Unity
66
{
77
abstract class BaseWindow : EditorWindow, IView
88
{
9-
[NonSerialized] private bool finishCalled = false;
109
[NonSerialized] private bool initialized = false;
11-
1210
[NonSerialized] private IApplicationManager cachedManager;
1311
[NonSerialized] private IRepository cachedRepository;
1412
[NonSerialized] private bool initializeWasCalled;
1513
[NonSerialized] private bool inLayout;
1614

17-
public event Action<bool> OnClose;
18-
1915
public virtual void Initialize(IApplicationManager applicationManager)
2016
{
2117
Logger.Trace("Initialize ApplicationManager:{0} Initialized:{1}", applicationManager, initialized);
@@ -49,15 +45,7 @@ public virtual void Refresh()
4945
}
5046

5147
public virtual void Finish(bool result)
52-
{
53-
finishCalled = true;
54-
RaiseOnClose(result);
55-
}
56-
57-
protected void RaiseOnClose(bool result)
58-
{
59-
OnClose.SafeInvoke(result);
60-
}
48+
{}
6149

6250
public virtual void Awake()
6351
{
@@ -73,9 +61,11 @@ public virtual void OnEnable()
7361
InitializeWindow(EntryPoint.ApplicationManager);
7462
}
7563

76-
public virtual void OnDisable() {}
64+
public virtual void OnDisable()
65+
{}
7766

78-
public virtual void Update() {}
67+
public virtual void Update()
68+
{}
7969

8070
public virtual void OnDataUpdate()
8171
{}
@@ -114,17 +104,12 @@ private void OnGUI()
114104
}
115105

116106
public virtual void OnDestroy()
117-
{
118-
if (!finishCalled)
119-
{
120-
RaiseOnClose(false);
121-
}
122-
}
107+
{}
123108

124109
public virtual void OnSelectionChange()
125110
{}
126111

127-
public virtual Rect Position { get { return position; } }
112+
public Rect Position { get { return position; } }
128113
public IApplicationManager Manager { get; private set; }
129114
public IRepository Repository { get { return inLayout ? cachedRepository : Environment.Repository; } }
130115
public bool HasRepository { get { return Environment.RepositoryPath != null; } }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public void OnEmbeddedGUI()
404404
var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
405405
if (publishedClicked)
406406
{
407-
PublishWindow.Open();
407+
PopupWindow.Open(PopupWindow.PopupViewType.PublishView);
408408
}
409409
}
410410
EditorGUI.EndDisabledGroup();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface IView
1212
Rect Position { get; }
1313

1414
void Finish(bool result);
15-
event Action<bool> OnClose;
1615
IRepository Repository { get; }
1716
bool HasRepository { get; }
1817
IApplicationManager Manager { get; }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Octokit;
5+
using Rackspace.Threading;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace GitHub.Unity
10+
{
11+
class LoadingView : Subview
12+
{
13+
private static readonly Vector2 viewSize = new Vector2(300, 250);
14+
15+
private const string WindowTitle = "Loading...";
16+
private const string Header = "";
17+
18+
19+
public override void InitializeView(IView parent)
20+
{
21+
base.InitializeView(parent);
22+
Title = WindowTitle;
23+
Size = viewSize;
24+
}
25+
26+
public override void OnGUI()
27+
{}
28+
}
29+
}

0 commit comments

Comments
 (0)