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

Commit 6487aad

Browse files
Merge pull request #270 from github-for-unity/enhancements/user-settings-view
Isolating the git user and email into a UserSettingsView
2 parents 00d0637 + a37267d commit 6487aad

File tree

4 files changed

+180
-122
lines changed

4 files changed

+180
-122
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="UI\IView.cs" />
103103
<Compile Include="UI\LoadingView.cs" />
104104
<Compile Include="UI\PublishView.cs" />
105+
<Compile Include="UI\UserSettingsView.cs" />
105106
<Compile Include="UI\GitPathView.cs" />
106107
<Compile Include="UI\SettingsView.cs" />
107108
<Compile Include="UI\Subview.cs" />

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ public override void OnDestroy()
113113
OnClose = null;
114114
}
115115

116-
public override bool IsBusy
117-
{
118-
get { return ActiveView.IsBusy; }
119-
}
120-
121116
private Subview ActiveView
122117
{
123118
get
@@ -146,5 +141,10 @@ private PopupViewType ActiveViewType
146141
}
147142
}
148143
}
144+
145+
public override bool IsBusy
146+
{
147+
get { return ActiveView.IsBusy; }
148+
}
149149
}
150150
}

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

Lines changed: 16 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ namespace GitHub.Unity
1212
class SettingsView : Subview
1313
{
1414
private const string GitInstallTitle = "Git installation";
15-
private const string GitConfigTitle = "Git Configuration";
16-
private const string GitConfigNameLabel = "Name";
17-
private const string GitConfigEmailLabel = "Email";
18-
private const string GitConfigUserSave = "Save User";
1915
private const string GitRepositoryTitle = "Repository Configuration";
2016
private const string GitRepositoryRemoteLabel = "Remote";
2117
private const string GitRepositorySave = "Save Repository";
@@ -31,9 +27,6 @@ class SettingsView : Subview
3127
[NonSerialized] private int newGitIgnoreRulesSelection = -1;
3228
[NonSerialized] private bool isBusy;
3329

34-
[SerializeField] private string gitName;
35-
[SerializeField] private string gitEmail;
36-
3730
[SerializeField] private int gitIgnoreRulesSelection = 0;
3831
[SerializeField] private string initDirectory;
3932
[SerializeField] private List<GitLock> lockedFiles = new List<GitLock>();
@@ -44,7 +37,6 @@ class SettingsView : Subview
4437
[SerializeField] private int lockedFileSelection = -1;
4538
[SerializeField] private bool hasRemote;
4639
[NonSerialized] private bool remoteHasChanged;
47-
[NonSerialized] private bool userDataHasChanged;
4840
[NonSerialized] private bool locksHaveChanged;
4941

5042
[SerializeField] private string newGitName;
@@ -57,17 +49,21 @@ class SettingsView : Subview
5749

5850
[SerializeField] private GitPathView gitPathView = new GitPathView();
5951

52+
[SerializeField] private UserSettingsView userSettingsView = new UserSettingsView();
53+
6054
public override void InitializeView(IView parent)
6155
{
6256
base.InitializeView(parent);
6357
gitPathView.InitializeView(this);
58+
userSettingsView.InitializeView(this);
6459
}
6560

6661

6762
public override void OnEnable()
6863
{
6964
base.OnEnable();
7065
gitPathView.OnEnable();
66+
userSettingsView.OnEnable();
7167
AttachHandlers(Repository);
7268

7369
remoteHasChanged = true;
@@ -79,20 +75,24 @@ public override void OnDisable()
7975
{
8076
base.OnDisable();
8177
gitPathView.OnDisable();
78+
userSettingsView.OnDisable();
8279
DetachHandlers(Repository);
8380
}
8481

8582
public override void OnDataUpdate()
8683
{
8784
base.OnDataUpdate();
85+
userSettingsView.OnDataUpdate();
8886
gitPathView.OnDataUpdate();
87+
8988
MaybeUpdateData();
9089
}
9190

9291
public override void OnRepositoryChanged(IRepository oldRepository)
9392
{
9493
base.OnRepositoryChanged(oldRepository);
9594
gitPathView.OnRepositoryChanged(oldRepository);
95+
userSettingsView.OnRepositoryChanged(oldRepository);
9696

9797
DetachHandlers(oldRepository);
9898
AttachHandlers(Repository);
@@ -102,15 +102,11 @@ public override void OnRepositoryChanged(IRepository oldRepository)
102102
Refresh();
103103
}
104104

105-
public override bool IsBusy
106-
{
107-
get { return isBusy || gitPathView.IsBusy; }
108-
}
109-
110105
public override void Refresh()
111106
{
112107
base.Refresh();
113108
gitPathView.Refresh();
109+
userSettingsView.Refresh();
114110
if (Repository != null && Repository.CurrentRemote.HasValue)
115111
{
116112
Repository.ListLocks().Start();
@@ -139,7 +135,7 @@ public override void OnGUI()
139135
{
140136
scroll = GUILayout.BeginScrollView(scroll);
141137
{
142-
OnUserSettingsGUI();
138+
userSettingsView.OnGUI();
143139

144140
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
145141

@@ -174,48 +170,11 @@ private void MaybeUpdateData()
174170
lockedFiles = new List<GitLock>();
175171

176172
if (Repository == null)
177-
{
178-
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
179-
{
180-
var user = new User();
181-
GitClient.GetConfig("user.name", GitConfigSource.User)
182-
.Then((success, value) => user.Name = value).Then(
183-
GitClient.GetConfig("user.email", GitConfigSource.User)
184-
.Then((success, value) => user.Email = value))
185-
.FinallyInUI((success, ex) =>
186-
{
187-
if (success && !String.IsNullOrEmpty(user.Name))
188-
{
189-
cachedUser = user;
190-
userDataHasChanged = true;
191-
Redraw();
192-
}
193-
})
194-
.Start();
195-
}
196-
197-
if (userDataHasChanged)
198-
{
199-
newGitName = gitName = cachedUser.Name;
200-
newGitEmail = gitEmail = cachedUser.Email;
201-
userDataHasChanged = false;
202-
}
203-
204173
return;
205-
}
206174

207-
userDataHasChanged = Repository.User.Name != gitName || Repository.User.Email != gitEmail;
208-
209-
if (!remoteHasChanged && !userDataHasChanged && !locksHaveChanged)
175+
if (!remoteHasChanged && !locksHaveChanged)
210176
return;
211177

212-
if (userDataHasChanged)
213-
{
214-
userDataHasChanged = false;
215-
newGitName = gitName = Repository.User.Name;
216-
newGitEmail = gitEmail = Repository.User.Email;
217-
}
218-
219178
if (remoteHasChanged)
220179
{
221180
remoteHasChanged = false;
@@ -268,71 +227,6 @@ private void OnLocksUpdate(IEnumerable<GitLock> update)
268227
Redraw();
269228
}
270229

271-
private void OnUserSettingsGUI()
272-
{
273-
GUILayout.Label(GitConfigTitle, EditorStyles.boldLabel);
274-
275-
EditorGUI.BeginDisabledGroup(isBusy);
276-
{
277-
newGitName = EditorGUILayout.TextField(GitConfigNameLabel, newGitName);
278-
newGitEmail = EditorGUILayout.TextField(GitConfigEmailLabel, newGitEmail);
279-
280-
var needsSaving = newGitName != gitName || newGitEmail != gitEmail;
281-
EditorGUI.BeginDisabledGroup(!needsSaving);
282-
{
283-
if (GUILayout.Button(GitConfigUserSave, GUILayout.ExpandWidth(false)))
284-
{
285-
GitClient.SetConfig("user.name", newGitName, GitConfigSource.User)
286-
.Then((success, value) =>
287-
{
288-
if (success)
289-
{
290-
if (Repository != null)
291-
{
292-
Repository.User.Name = newGitName;
293-
}
294-
else
295-
{
296-
if (cachedUser == null)
297-
{
298-
cachedUser = new User();
299-
}
300-
cachedUser.Name = newGitName;
301-
}
302-
}
303-
})
304-
.Then(
305-
GitClient.SetConfig("user.email", newGitEmail, GitConfigSource.User)
306-
.Then((success, value) =>
307-
{
308-
if (success)
309-
{
310-
if (Repository != null)
311-
{
312-
Repository.User.Email = newGitEmail;
313-
}
314-
else
315-
{
316-
cachedUser.Email = newGitEmail;
317-
}
318-
319-
userDataHasChanged = true;
320-
}
321-
}))
322-
.FinallyInUI((_, __) =>
323-
{
324-
isBusy = false;
325-
Redraw();
326-
})
327-
.Start();
328-
isBusy = true;
329-
}
330-
}
331-
EditorGUI.EndDisabledGroup();
332-
}
333-
EditorGUI.EndDisabledGroup();
334-
}
335-
336230
private void OnRepositorySettingsGUI()
337231
{
338232
GUILayout.Label(GitRepositoryTitle, EditorStyles.boldLabel);
@@ -475,5 +369,10 @@ private void OnLoggingSettingsGui()
475369
}
476370
EditorGUI.EndDisabledGroup();
477371
}
372+
373+
public override bool IsBusy
374+
{
375+
get { return isBusy || userSettingsView.IsBusy || gitPathView.IsBusy; }
376+
}
478377
}
479378
}

0 commit comments

Comments
 (0)