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

Commit f0f7d55

Browse files
author
Marcus Christensen
committed
* Changes direct usages of GUI.enabled to instead use EditorGUI.BeginDisabledGroup() / EditorGUI.EndDisabledGroup()
1 parent 6c0791f commit f0f7d55

File tree

4 files changed

+256
-219
lines changed

4 files changed

+256
-219
lines changed

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

Lines changed: 48 additions & 37 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()
@@ -134,35 +134,42 @@ private void OnGUILogin()
134134
GUILayout.Space(3);
135135
GUILayout.BeginHorizontal();
136136
{
137-
if (busy) GUI.enabled = false;
138-
username = EditorGUILayout.TextField(usernameLabel ,username, Styles.TextFieldStyle);
139-
GUI.enabled = true;
137+
EditorGUI.BeginDisabledGroup(isBusy);
138+
{
139+
username = EditorGUILayout.TextField(usernameLabel, username, Styles.TextFieldStyle);
140+
}
141+
EditorGUI.EndDisabledGroup();
140142
}
141143
GUILayout.EndHorizontal();
142144
GUILayout.Space(Styles.BaseSpacing);
143145
GUILayout.BeginHorizontal();
144146
{
145-
if (busy) GUI.enabled = false;
146-
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
147-
GUI.enabled = true;
147+
EditorGUI.BeginDisabledGroup(isBusy);
148+
{
149+
password = EditorGUILayout.PasswordField(passwordLabel, password, Styles.TextFieldStyle);
150+
}
151+
EditorGUI.EndDisabledGroup();
148152
}
149153
GUILayout.EndHorizontal();
150154

151155
ShowErrorMessage();
152156

153157
GUILayout.Space(Styles.BaseSpacing + 3);
154158

155-
if (busy) GUI.enabled = false;
156-
GUILayout.BeginHorizontal();
157-
GUILayout.FlexibleSpace();
158-
if (GUILayout.Button(loginButton) || (GUI.enabled && enterPressed))
159+
160+
EditorGUI.BeginDisabledGroup(isBusy);
159161
{
160-
GUI.FocusControl(null);
161-
busy = true;
162-
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
162+
GUILayout.BeginHorizontal();
163+
GUILayout.FlexibleSpace();
164+
if (GUILayout.Button(loginButton) || (GUI.enabled && enterPressed))
165+
{
166+
GUI.FocusControl(null);
167+
isBusy = true;
168+
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
169+
}
170+
GUILayout.EndHorizontal();
163171
}
164-
GUILayout.EndHorizontal();
165-
GUI.enabled = true;
172+
EditorGUI.EndDisabledGroup();
166173
}
167174

168175
private void OnGUI2FA()
@@ -175,9 +182,11 @@ private void OnGUI2FA()
175182

176183
GUILayout.BeginHorizontal();
177184
{
178-
if (busy) GUI.enabled = false;
179-
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
180-
GUI.enabled = true;
185+
EditorGUI.BeginDisabledGroup(isBusy);
186+
{
187+
two2fa = EditorGUILayout.TextField(twofaLabel, two2fa, Styles.TextFieldStyle);
188+
}
189+
EditorGUI.EndDisabledGroup();
181190
}
182191
GUILayout.EndHorizontal();
183192
GUILayout.Space(Styles.BaseSpacing);
@@ -186,25 +195,27 @@ private void OnGUI2FA()
186195

187196
GUILayout.Space(Styles.BaseSpacing);
188197

189-
if (busy) GUI.enabled = false;
190-
GUILayout.BeginHorizontal();
191-
GUILayout.FlexibleSpace();
192-
if (GUILayout.Button(backButton))
198+
EditorGUI.BeginDisabledGroup(isBusy);
193199
{
194-
GUI.FocusControl(null);
195-
need2fa = false;
196-
Redraw();
197-
}
200+
GUILayout.BeginHorizontal();
201+
GUILayout.FlexibleSpace();
202+
if (GUILayout.Button(backButton))
203+
{
204+
GUI.FocusControl(null);
205+
need2fa = false;
206+
Redraw();
207+
}
198208

199-
if (GUILayout.Button(twofaButton) || (GUI.enabled && enterPressed))
200-
{
201-
GUI.FocusControl(null);
202-
busy = true;
203-
AuthenticationService.LoginWith2fa(two2fa);
209+
if (GUILayout.Button(twofaButton) || (GUI.enabled && enterPressed))
210+
{
211+
GUI.FocusControl(null);
212+
isBusy = true;
213+
AuthenticationService.LoginWith2fa(two2fa);
214+
}
215+
GUILayout.EndHorizontal();
204216
}
205-
GUILayout.EndHorizontal();
217+
EditorGUI.EndDisabledGroup();
206218

207-
GUI.enabled = true;
208219
GUILayout.Space(Styles.BaseSpacing);
209220
GUILayout.EndVertical();
210221
}
@@ -215,7 +226,7 @@ private void DoRequire2fa(string msg)
215226

216227
need2fa = true;
217228
errorMessage = msg;
218-
busy = false;
229+
isBusy = false;
219230
Redraw();
220231
}
221232

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

226237
errorMessage = msg;
227-
busy = false;
238+
isBusy = false;
228239

229240
if (success == true)
230241
{

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

Lines changed: 68 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public override void OnGUI()
135135
OnBroadGUI();
136136
else
137137
#endif
138-
OnEmbeddedGUI();
138+
OnEmbeddedGUI();
139139

140140
#if ENABLE_BROADMODE
141141
if (Event.current.type == EventType.Repaint && EvaluateBroadMode())
@@ -207,7 +207,8 @@ private void RefreshLog()
207207
{
208208
if (Repository != null)
209209
{
210-
GitClient.Log().ThenInUI((success, log) => {
210+
GitClient.Log().ThenInUI((success, log) =>
211+
{
211212
if (success) OnLogUpdate(log);
212213
}).Start();
213214
}
@@ -308,16 +309,19 @@ private void DoOfferToInitializeRepositoryGUI()
308309
GUILayout.FlexibleSpace();
309310

310311
var enabled = GUI.enabled;
311-
GUI.enabled = !isBusy;
312-
313-
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
312+
EditorGUI.BeginDisabledGroup(isBusy);
314313
{
315-
isBusy = true;
316-
Manager.InitializeRepository()
317-
.FinallyInUI(() => isBusy = false)
318-
.Start();
314+
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
315+
{
316+
isBusy = true;
317+
Manager.InitializeRepository()
318+
.FinallyInUI(() => isBusy = false)
319+
.Start();
320+
}
319321
}
322+
EditorGUI.EndDisabledGroup();
320323
GUI.enabled = enabled;
324+
321325
GUILayout.FlexibleSpace();
322326
GUILayout.EndHorizontal();
323327

@@ -335,8 +339,8 @@ public void OnEmbeddedGUI()
335339
EditorGUI.BeginDisabledGroup(historyTarget == null);
336340
{
337341
if (GUILayout.Button(
338-
historyTarget == null ? HistoryFocusAll : String.Format(HistoryFocusSingle, historyTarget.name),
339-
Styles.HistoryToolbarButtonStyle)
342+
historyTarget == null ? HistoryFocusAll : String.Format(HistoryFocusSingle, historyTarget.name),
343+
Styles.HistoryToolbarButtonStyle)
340344
)
341345
{
342346
historyTarget = null;
@@ -351,53 +355,65 @@ public void OnEmbeddedGUI()
351355
var isPublished = Repository.CurrentRemote.HasValue;
352356
if (isPublished)
353357
{
354-
GUI.enabled = currentRemote != null;
355-
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
356-
GUI.enabled = true;
357-
if (fetchClicked)
358+
// Fetch button
359+
EditorGUI.BeginDisabledGroup(currentRemote == null);
358360
{
359-
Fetch();
361+
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
362+
if (fetchClicked)
363+
{
364+
Fetch();
365+
}
360366
}
367+
EditorGUI.EndDisabledGroup();
361368

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

377-
var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
378-
GUI.enabled = currentRemote != null && statusBehind == 0;
379-
var pushClicked = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);
380-
GUI.enabled = true;
381-
if (pushClicked &&
382-
EditorUtility.DisplayDialog(PushConfirmTitle,
383-
String.Format(PushConfirmDescription, currentRemote),
384-
PushConfirmYes,
385-
PushConfirmCancel)
386-
)
387+
// Push button
388+
EditorGUI.BeginDisabledGroup(currentRemote == null || statusBehind != 0);
387389
{
388-
Push();
390+
var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
391+
var pushClicked = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);
392+
393+
if (pushClicked &&
394+
EditorUtility.DisplayDialog(PushConfirmTitle,
395+
String.Format(PushConfirmDescription, currentRemote),
396+
PushConfirmYes,
397+
PushConfirmCancel)
398+
)
399+
{
400+
Push();
401+
}
389402
}
403+
EditorGUI.EndDisabledGroup();
390404
}
391405
else
392406
{
393407
// Publishing a repo
394-
GUI.enabled = Platform.Keychain.Connections.Any();
395-
var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
396-
if (publishedClicked)
408+
EditorGUI.BeginDisabledGroup(!Platform.Keychain.Connections.Any());
397409
{
398-
PublishWindow.Open();
410+
var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
411+
if (publishedClicked)
412+
{
413+
PublishWindow.Open();
414+
}
399415
}
400-
GUI.enabled = true;
416+
EditorGUI.EndDisabledGroup();
401417
}
402418
}
403419
GUILayout.EndHorizontal();
@@ -569,7 +585,8 @@ private void RevertCommit()
569585
{
570586
Repository
571587
.Revert(selection.CommitID)
572-
.FinallyInUI((success, e) => {
588+
.FinallyInUI((success, e) =>
589+
{
573590
if (!success)
574591
{
575592
EditorUtility.DisplayDialog(dialogTitle,
@@ -699,7 +716,8 @@ private void Pull()
699716
// (either git rebase --abort or git merge --abort)
700717
}
701718
}, true)
702-
.FinallyInUI((success, e) => {
719+
.FinallyInUI((success, e) =>
720+
{
703721
if (success)
704722
{
705723
EditorUtility.DisplayDialog(Localization.PullActionTitle,
@@ -722,7 +740,8 @@ private void Push()
722740
var remote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : String.Empty;
723741
Repository
724742
.Push()
725-
.FinallyInUI((success, e) => {
743+
.FinallyInUI((success, e) =>
744+
{
726745
if (success)
727746
{
728747
EditorUtility.DisplayDialog(Localization.PushActionTitle,
@@ -744,7 +763,8 @@ private void Fetch()
744763
var remote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : String.Empty;
745764
Repository
746765
.Fetch()
747-
.FinallyInUI((success, e) => {
766+
.FinallyInUI((success, e) =>
767+
{
748768
if (!success)
749769
{
750770
EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription,

0 commit comments

Comments
 (0)