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

Commit 9775a0e

Browse files
Changing popup button functionality to display an error label instead
1 parent 79e339f commit 9775a0e

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Styles
5353

5454
private static GUIStyle label,
5555
boldLabel,
56+
centeredErrorLabel,
5657
errorLabel,
5758
deletedFileLabel,
5859
longMessageStyle,
@@ -337,6 +338,22 @@ public static GUIStyle ErrorLabel
337338
}
338339
}
339340

341+
public static GUIStyle CenteredErrorLabel
342+
{
343+
get
344+
{
345+
if (centeredErrorLabel == null)
346+
{
347+
centeredErrorLabel = new GUIStyle(EditorStyles.label);
348+
centeredErrorLabel.alignment = TextAnchor.MiddleCenter;
349+
centeredErrorLabel.name = "CenteredErrorLabel";
350+
centeredErrorLabel.wordWrap = true;
351+
centeredErrorLabel.normal.textColor = Color.red;
352+
}
353+
return centeredErrorLabel;
354+
}
355+
}
356+
340357
public static GUIStyle LongMessageStyle
341358
{
342359
get

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ class InitProjectView : Subview
99
{
1010
private const string NoRepoTitle = "No Git repository found for this project";
1111
private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others.";
12+
private const string NoUserOrEmailError = "Name and Email must be configured in Settings";
1213

1314
[SerializeField] private bool isBusy;
1415
[SerializeField] private bool isUserDataPresent = true;
1516

17+
[NonSerialized] private string errorMessage;
1618
[NonSerialized] private bool userDataHasChanged;
1719

1820
public override void InitializeView(IView parent)
@@ -81,25 +83,6 @@ public override void OnGUI()
8183

8284
GUILayout.BeginVertical(Styles.GenericBoxStyle);
8385
{
84-
if (!isUserDataPresent)
85-
{
86-
GUILayout.FlexibleSpace();
87-
88-
EditorGUI.BeginDisabledGroup(isBusy);
89-
{
90-
if (GUILayout.Button("Finish Git Configuration", "Button"))
91-
{
92-
PopupWindow.Open(PopupWindow.PopupViewType.UserSettingsView, completed => {
93-
if (completed)
94-
{
95-
userDataHasChanged = true;
96-
}
97-
});
98-
}
99-
}
100-
EditorGUI.EndDisabledGroup();
101-
}
102-
10386
GUILayout.FlexibleSpace();
10487

10588
GUILayout.Label(NoRepoDescription, Styles.CenteredLabel);
@@ -122,11 +105,26 @@ public override void OnGUI()
122105
GUILayout.FlexibleSpace();
123106
GUILayout.EndHorizontal();
124107

108+
ShowErrorMessage();
109+
125110
GUILayout.FlexibleSpace();
126111
}
127112
GUILayout.EndVertical();
128113
}
129114

115+
private void ShowErrorMessage()
116+
{
117+
if (errorMessage != null)
118+
{
119+
GUILayout.Space(Styles.BaseSpacing);
120+
GUILayout.BeginHorizontal();
121+
{
122+
GUILayout.Label(errorMessage, Styles.CenteredErrorLabel);
123+
}
124+
GUILayout.EndHorizontal();
125+
}
126+
}
127+
130128
private void MaybeUpdateData()
131129
{
132130
if (userDataHasChanged)
@@ -160,6 +158,7 @@ private void CheckForUser()
160158

161159
isBusy = false;
162160
isUserDataPresent = success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email);
161+
errorMessage = isUserDataPresent ? null : NoUserOrEmailError;
163162

164163
Logger.Trace("Finally: {0}", isUserDataPresent);
165164

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ public enum PopupViewType
1212
None,
1313
PublishView,
1414
AuthenticationView,
15-
UserSettingsView
1615
}
1716

1817
[SerializeField] private PopupViewType activeViewType;
1918

2019
[SerializeField] private AuthenticationView authenticationView;
21-
[SerializeField] private UserSettingsView userSettingsView;
2220
[SerializeField] private PublishView publishView;
2321
[SerializeField] private LoadingView loadingView;
2422

@@ -54,12 +52,10 @@ public override void Initialize(IApplicationManager applicationManager)
5452
{
5553
base.Initialize(applicationManager);
5654

57-
userSettingsView = userSettingsView ?? new UserSettingsView();
5855
publishView = publishView ?? new PublishView();
5956
authenticationView = authenticationView ?? new AuthenticationView();
6057
loadingView = loadingView ?? new LoadingView();
6158

62-
userSettingsView.InitializeView(this);
6359
publishView.InitializeView(this);
6460
authenticationView.InitializeView(this);
6561
loadingView.InitializeView(this);
@@ -127,8 +123,6 @@ private Subview ActiveView
127123
return publishView;
128124
case PopupViewType.AuthenticationView:
129125
return authenticationView;
130-
case PopupViewType.UserSettingsView:
131-
return userSettingsView;
132126
default:
133127
return loadingView;
134128
}

0 commit comments

Comments
 (0)