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

Commit 784d624

Browse files
Merge pull request #207 from MunchyYDL/fixes/gui_enabled
* Changes direct usages of GUI.enabled to instead use EditorGUI.Begin… fixes #107
2 parents 61c24f1 + 57da18f commit 784d624

File tree

4 files changed

+225
-212
lines changed

4 files changed

+225
-212
lines changed

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

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AuthenticationView : Subview
2222
[SerializeField] private string two2fa = "";
2323

2424
[NonSerialized] private bool need2fa;
25-
[NonSerialized] private bool busy;
25+
[NonSerialized] private bool isBusy;
2626
[NonSerialized] private string errorMessage;
2727
[NonSerialized] private bool enterPressed;
2828
[NonSerialized] private string password = "";
@@ -58,7 +58,7 @@ private AuthenticationService AuthenticationService
5858
public override void InitializeView(IView parent)
5959
{
6060
base.InitializeView(parent);
61-
need2fa = busy = false;
61+
need2fa = isBusy = false;
6262
}
6363

6464
public override void OnEnable()
@@ -131,81 +131,83 @@ private void HandleEnterPressed()
131131

132132
private void OnGUILogin()
133133
{
134-
GUILayout.Space(3);
135-
GUILayout.BeginHorizontal();
134+
EditorGUI.BeginDisabledGroup(isBusy);
136135
{
137-
if (busy) GUI.enabled = false;
138-
username = EditorGUILayout.TextField(usernameLabel ,username, Styles.TextFieldStyle);
139-
GUI.enabled = true;
140-
}
141-
GUILayout.EndHorizontal();
142-
GUILayout.Space(Styles.BaseSpacing);
143-
GUILayout.BeginHorizontal();
144-
{
145-
if (busy) GUI.enabled = false;
146-
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
147-
GUI.enabled = true;
148-
}
149-
GUILayout.EndHorizontal();
136+
GUILayout.Space(3);
137+
GUILayout.BeginHorizontal();
138+
{
139+
username = EditorGUILayout.TextField(usernameLabel, username, Styles.TextFieldStyle);
140+
}
141+
GUILayout.EndHorizontal();
150142

151-
ShowErrorMessage();
143+
GUILayout.Space(Styles.BaseSpacing);
144+
GUILayout.BeginHorizontal();
145+
{
146+
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
147+
}
148+
GUILayout.EndHorizontal();
152149

153-
GUILayout.Space(Styles.BaseSpacing + 3);
150+
ShowErrorMessage();
154151

155-
if (busy) GUI.enabled = false;
156-
GUILayout.BeginHorizontal();
157-
GUILayout.FlexibleSpace();
158-
if (GUILayout.Button(loginButton) || (GUI.enabled && enterPressed))
159-
{
160-
GUI.FocusControl(null);
161-
busy = true;
162-
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
152+
GUILayout.Space(Styles.BaseSpacing + 3);
153+
GUILayout.BeginHorizontal();
154+
{
155+
GUILayout.FlexibleSpace();
156+
if (GUILayout.Button(loginButton) || (!isBusy && enterPressed))
157+
{
158+
GUI.FocusControl(null);
159+
isBusy = true;
160+
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
161+
}
162+
}
163+
GUILayout.EndHorizontal();
163164
}
164-
GUILayout.EndHorizontal();
165-
GUI.enabled = true;
165+
EditorGUI.EndDisabledGroup();
166166
}
167167

168168
private void OnGUI2FA()
169169
{
170170
GUILayout.BeginVertical();
171-
GUILayout.Label(twofaTitle, EditorStyles.boldLabel);
172-
GUILayout.Label(twofaDescription, EditorStyles.wordWrappedLabel);
173-
174-
GUILayout.Space(Styles.BaseSpacing);
175-
176-
GUILayout.BeginHorizontal();
177171
{
178-
if (busy) GUI.enabled = false;
179-
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
180-
GUI.enabled = true;
181-
}
182-
GUILayout.EndHorizontal();
183-
GUILayout.Space(Styles.BaseSpacing);
172+
GUILayout.Label(twofaTitle, EditorStyles.boldLabel);
173+
GUILayout.Label(twofaDescription, EditorStyles.wordWrappedLabel);
184174

185-
ShowErrorMessage();
175+
EditorGUI.BeginDisabledGroup(isBusy);
176+
{
177+
GUILayout.Space(Styles.BaseSpacing);
178+
GUILayout.BeginHorizontal();
179+
{
180+
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
181+
}
182+
GUILayout.EndHorizontal();
186183

187-
GUILayout.Space(Styles.BaseSpacing);
184+
GUILayout.Space(Styles.BaseSpacing);
185+
ShowErrorMessage();
188186

189-
if (busy) GUI.enabled = false;
190-
GUILayout.BeginHorizontal();
191-
GUILayout.FlexibleSpace();
192-
if (GUILayout.Button(backButton))
193-
{
194-
GUI.FocusControl(null);
195-
need2fa = false;
196-
Redraw();
197-
}
187+
GUILayout.Space(Styles.BaseSpacing);
188+
GUILayout.BeginHorizontal();
189+
{
190+
GUILayout.FlexibleSpace();
191+
if (GUILayout.Button(backButton))
192+
{
193+
GUI.FocusControl(null);
194+
need2fa = false;
195+
Redraw();
196+
}
197+
198+
if (GUILayout.Button(twofaButton) || (!isBusy && enterPressed))
199+
{
200+
GUI.FocusControl(null);
201+
isBusy = true;
202+
AuthenticationService.LoginWith2fa(two2fa);
203+
}
204+
}
205+
GUILayout.EndHorizontal();
198206

199-
if (GUILayout.Button(twofaButton) || (GUI.enabled && enterPressed))
200-
{
201-
GUI.FocusControl(null);
202-
busy = true;
203-
AuthenticationService.LoginWith2fa(two2fa);
207+
GUILayout.Space(Styles.BaseSpacing);
208+
}
209+
EditorGUI.EndDisabledGroup();
204210
}
205-
GUILayout.EndHorizontal();
206-
207-
GUI.enabled = true;
208-
GUILayout.Space(Styles.BaseSpacing);
209211
GUILayout.EndVertical();
210212
}
211213

@@ -215,7 +217,7 @@ private void DoRequire2fa(string msg)
215217

216218
need2fa = true;
217219
errorMessage = msg;
218-
busy = false;
220+
isBusy = false;
219221
Redraw();
220222
}
221223

@@ -224,7 +226,7 @@ private void DoResult(bool success, string msg)
224226
Logger.Trace("DoResult - Success:{0} Message:\"{1}\"", success, msg);
225227

226228
errorMessage = msg;
227-
busy = false;
229+
isBusy = false;
228230

229231
if (success == true)
230232
{

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

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public override void OnGUI()
136136
OnBroadGUI();
137137
else
138138
#endif
139-
OnEmbeddedGUI();
139+
OnEmbeddedGUI();
140140

141141
#if ENABLE_BROADMODE
142142
if (Event.current.type == EventType.Repaint && EvaluateBroadMode())
@@ -310,17 +310,18 @@ private void DoOfferToInitializeRepositoryGUI()
310310
GUILayout.BeginHorizontal();
311311
GUILayout.FlexibleSpace();
312312

313-
var enabled = GUI.enabled;
314-
GUI.enabled = !isBusy;
315-
316-
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
313+
EditorGUI.BeginDisabledGroup(isBusy);
317314
{
318-
isBusy = true;
319-
Manager.InitializeRepository()
320-
.FinallyInUI(() => isBusy = false)
321-
.Start();
315+
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
316+
{
317+
isBusy = true;
318+
Manager.InitializeRepository()
319+
.FinallyInUI(() => isBusy = false)
320+
.Start();
321+
}
322322
}
323-
GUI.enabled = enabled;
323+
EditorGUI.EndDisabledGroup();
324+
324325
GUILayout.FlexibleSpace();
325326
GUILayout.EndHorizontal();
326327

@@ -338,8 +339,8 @@ public void OnEmbeddedGUI()
338339
EditorGUI.BeginDisabledGroup(historyTarget == null);
339340
{
340341
if (GUILayout.Button(
341-
historyTarget == null ? HistoryFocusAll : String.Format(HistoryFocusSingle, historyTarget.name),
342-
Styles.HistoryToolbarButtonStyle)
342+
historyTarget == null ? HistoryFocusAll : String.Format(HistoryFocusSingle, historyTarget.name),
343+
Styles.HistoryToolbarButtonStyle)
343344
)
344345
{
345346
historyTarget = null;
@@ -352,53 +353,61 @@ public void OnEmbeddedGUI()
352353

353354
if (isPublished)
354355
{
355-
GUI.enabled = currentRemote != null;
356-
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
357-
GUI.enabled = true;
358-
if (fetchClicked)
356+
EditorGUI.BeginDisabledGroup(currentRemote == null);
359357
{
360-
Fetch();
361-
}
358+
// Fetch button
359+
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
360+
if (fetchClicked)
361+
{
362+
Fetch();
363+
}
362364

363-
// Pull / Push buttons
364-
var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
365-
GUI.enabled = currentRemote != null;
366-
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
367-
GUI.enabled = true;
368-
if (pullClicked &&
369-
EditorUtility.DisplayDialog(PullConfirmTitle,
370-
String.Format(PullConfirmDescription, currentRemote),
371-
PullConfirmYes,
372-
PullConfirmCancel)
373-
)
374-
{
375-
Pull();
365+
// Pull button
366+
var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
367+
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
368+
369+
if (pullClicked &&
370+
EditorUtility.DisplayDialog(PullConfirmTitle,
371+
String.Format(PullConfirmDescription, currentRemote),
372+
PullConfirmYes,
373+
PullConfirmCancel)
374+
)
375+
{
376+
Pull();
377+
}
376378
}
379+
EditorGUI.EndDisabledGroup();
377380

378-
var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
379-
GUI.enabled = currentRemote != null && statusBehind == 0;
380-
var pushClicked = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);
381-
GUI.enabled = true;
382-
if (pushClicked &&
383-
EditorUtility.DisplayDialog(PushConfirmTitle,
384-
String.Format(PushConfirmDescription, currentRemote),
385-
PushConfirmYes,
386-
PushConfirmCancel)
387-
)
381+
// Push button
382+
EditorGUI.BeginDisabledGroup(currentRemote == null || statusBehind != 0);
388383
{
389-
Push();
384+
var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
385+
var pushClicked = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);
386+
387+
if (pushClicked &&
388+
EditorUtility.DisplayDialog(PushConfirmTitle,
389+
String.Format(PushConfirmDescription, currentRemote),
390+
PushConfirmYes,
391+
PushConfirmCancel)
392+
)
393+
{
394+
Push();
395+
}
390396
}
397+
EditorGUI.EndDisabledGroup();
391398
}
392399
else
393400
{
394401
// Publishing a repo
395-
GUI.enabled = Platform.Keychain.Connections.Any();
396-
var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
397-
if (publishedClicked)
402+
EditorGUI.BeginDisabledGroup(!Platform.Keychain.Connections.Any());
398403
{
399-
PublishWindow.Open();
404+
var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
405+
if (publishedClicked)
406+
{
407+
PublishWindow.Open();
408+
}
400409
}
401-
GUI.enabled = true;
410+
EditorGUI.EndDisabledGroup();
402411
}
403412
}
404413
GUILayout.EndHorizontal();
@@ -691,8 +700,7 @@ private void Pull()
691700
Repository
692701
.Pull()
693702
// we need the error propagated from the original git command to handle things appropriately
694-
.Then(success =>
695-
{
703+
.Then(success => {
696704
if (!success)
697705
{
698706
// if Pull fails we need to parse the output of the command, figure out

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PUblishView.cs renamed to src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PublishView.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public override void OnGUI()
138138
GUILayout.BeginVertical();
139139
{
140140
GUILayout.Label(SelectedOwnerLabel);
141-
142141
selectedOwner = EditorGUILayout.Popup(selectedOwner, owners);
143142
}
144143
GUILayout.EndVertical();
@@ -179,7 +178,7 @@ public override void OnGUI()
179178
}
180179
GUILayout.EndHorizontal();
181180
}
182-
GUILayout.EndVertical();;
181+
GUILayout.EndVertical();
183182

184183
GUILayout.Space(Styles.PublishViewSpacingHeight);
185184

0 commit comments

Comments
 (0)