@@ -12,10 +12,6 @@ namespace GitHub.Unity
12
12
class SettingsView : Subview
13
13
{
14
14
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" ;
19
15
private const string GitRepositoryTitle = "Repository Configuration" ;
20
16
private const string GitRepositoryRemoteLabel = "Remote" ;
21
17
private const string GitRepositorySave = "Save Repository" ;
@@ -31,9 +27,6 @@ class SettingsView : Subview
31
27
[ NonSerialized ] private int newGitIgnoreRulesSelection = - 1 ;
32
28
[ NonSerialized ] private bool isBusy ;
33
29
34
- [ SerializeField ] private string gitName ;
35
- [ SerializeField ] private string gitEmail ;
36
-
37
30
[ SerializeField ] private int gitIgnoreRulesSelection = 0 ;
38
31
[ SerializeField ] private string initDirectory ;
39
32
[ SerializeField ] private List < GitLock > lockedFiles = new List < GitLock > ( ) ;
@@ -44,7 +37,6 @@ class SettingsView : Subview
44
37
[ SerializeField ] private int lockedFileSelection = - 1 ;
45
38
[ SerializeField ] private bool hasRemote ;
46
39
[ NonSerialized ] private bool remoteHasChanged ;
47
- [ NonSerialized ] private bool userDataHasChanged ;
48
40
[ NonSerialized ] private bool locksHaveChanged ;
49
41
50
42
[ SerializeField ] private string newGitName ;
@@ -57,17 +49,21 @@ class SettingsView : Subview
57
49
58
50
[ SerializeField ] private GitPathView gitPathView = new GitPathView ( ) ;
59
51
52
+ [ SerializeField ] private UserSettingsView userSettingsView = new UserSettingsView ( ) ;
53
+
60
54
public override void InitializeView ( IView parent )
61
55
{
62
56
base . InitializeView ( parent ) ;
63
57
gitPathView . InitializeView ( this ) ;
58
+ userSettingsView . InitializeView ( this ) ;
64
59
}
65
60
66
61
67
62
public override void OnEnable ( )
68
63
{
69
64
base . OnEnable ( ) ;
70
65
gitPathView . OnEnable ( ) ;
66
+ userSettingsView . OnEnable ( ) ;
71
67
AttachHandlers ( Repository ) ;
72
68
73
69
remoteHasChanged = true ;
@@ -79,20 +75,24 @@ public override void OnDisable()
79
75
{
80
76
base . OnDisable ( ) ;
81
77
gitPathView . OnDisable ( ) ;
78
+ userSettingsView . OnDisable ( ) ;
82
79
DetachHandlers ( Repository ) ;
83
80
}
84
81
85
82
public override void OnDataUpdate ( )
86
83
{
87
84
base . OnDataUpdate ( ) ;
85
+ userSettingsView . OnDataUpdate ( ) ;
88
86
gitPathView . OnDataUpdate ( ) ;
87
+
89
88
MaybeUpdateData ( ) ;
90
89
}
91
90
92
91
public override void OnRepositoryChanged ( IRepository oldRepository )
93
92
{
94
93
base . OnRepositoryChanged ( oldRepository ) ;
95
94
gitPathView . OnRepositoryChanged ( oldRepository ) ;
95
+ userSettingsView . OnRepositoryChanged ( oldRepository ) ;
96
96
97
97
DetachHandlers ( oldRepository ) ;
98
98
AttachHandlers ( Repository ) ;
@@ -102,15 +102,11 @@ public override void OnRepositoryChanged(IRepository oldRepository)
102
102
Refresh ( ) ;
103
103
}
104
104
105
- public override bool IsBusy
106
- {
107
- get { return isBusy || gitPathView . IsBusy ; }
108
- }
109
-
110
105
public override void Refresh ( )
111
106
{
112
107
base . Refresh ( ) ;
113
108
gitPathView . Refresh ( ) ;
109
+ userSettingsView . Refresh ( ) ;
114
110
if ( Repository != null && Repository . CurrentRemote . HasValue )
115
111
{
116
112
Repository . ListLocks ( ) . Start ( ) ;
@@ -139,7 +135,7 @@ public override void OnGUI()
139
135
{
140
136
scroll = GUILayout . BeginScrollView ( scroll ) ;
141
137
{
142
- OnUserSettingsGUI ( ) ;
138
+ userSettingsView . OnGUI ( ) ;
143
139
144
140
GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
145
141
@@ -174,48 +170,11 @@ private void MaybeUpdateData()
174
170
lockedFiles = new List < GitLock > ( ) ;
175
171
176
172
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
-
204
173
return ;
205
- }
206
174
207
- userDataHasChanged = Repository . User . Name != gitName || Repository . User . Email != gitEmail ;
208
-
209
- if ( ! remoteHasChanged && ! userDataHasChanged && ! locksHaveChanged )
175
+ if ( ! remoteHasChanged && ! locksHaveChanged )
210
176
return ;
211
177
212
- if ( userDataHasChanged )
213
- {
214
- userDataHasChanged = false ;
215
- newGitName = gitName = Repository . User . Name ;
216
- newGitEmail = gitEmail = Repository . User . Email ;
217
- }
218
-
219
178
if ( remoteHasChanged )
220
179
{
221
180
remoteHasChanged = false ;
@@ -268,71 +227,6 @@ private void OnLocksUpdate(IEnumerable<GitLock> update)
268
227
Redraw ( ) ;
269
228
}
270
229
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
-
336
230
private void OnRepositorySettingsGUI ( )
337
231
{
338
232
GUILayout . Label ( GitRepositoryTitle , EditorStyles . boldLabel ) ;
@@ -475,5 +369,10 @@ private void OnLoggingSettingsGui()
475
369
}
476
370
EditorGUI . EndDisabledGroup ( ) ;
477
371
}
372
+
373
+ public override bool IsBusy
374
+ {
375
+ get { return isBusy || userSettingsView . IsBusy || gitPathView . IsBusy ; }
376
+ }
478
377
}
479
378
}
0 commit comments