@@ -52,11 +52,6 @@ class SettingsView : Subview
52
52
private const string GitIgnoreRulesDescription = "Description" ;
53
53
private const string NewGitIgnoreRuleButton = "New" ;
54
54
private const string DeleteGitIgnoreRuleButton = "Delete" ;
55
- private const string GitConfigTitle = "Git Configuration" ;
56
- private const string GitConfigNameLabel = "Name" ;
57
- private const string GitConfigEmailLabel = "Email" ;
58
- private const string GitConfigUserSave = "Save User" ;
59
- private const string GitConfigUserSaved = "Saved" ;
60
55
private const string GitRepositoryTitle = "Repository Configuration" ;
61
56
private const string GitRepositoryRemoteLabel = "Remote" ;
62
57
private const string GitRepositorySave = "Save Repository" ;
@@ -68,9 +63,6 @@ class SettingsView : Subview
68
63
69
64
[ NonSerialized ] private int newGitIgnoreRulesSelection = - 1 ;
70
65
71
- [ SerializeField ] private string gitName ;
72
- [ SerializeField ] private string gitEmail ;
73
-
74
66
[ SerializeField ] private int gitIgnoreRulesSelection = 0 ;
75
67
[ SerializeField ] private string initDirectory ;
76
68
[ SerializeField ] private List < GitLock > lockedFiles = new List < GitLock > ( ) ;
@@ -82,16 +74,23 @@ class SettingsView : Subview
82
74
[ SerializeField ] private int lockedFileSelection = - 1 ;
83
75
[ SerializeField ] private bool hasRemote ;
84
76
[ SerializeField ] private bool remoteHasChanged ;
85
- [ NonSerialized ] private bool userDataHasChanged ;
86
77
87
78
[ SerializeField ] private string newGitName ;
88
79
[ SerializeField ] private string newGitEmail ;
89
80
[ SerializeField ] private string newRepositoryRemoteUrl ;
90
81
[ SerializeField ] private User cachedUser ;
82
+ [ SerializeField ] private UserSettingsView userSettingsView = new UserSettingsView ( ) ;
83
+
84
+ public override void InitializeView ( IView parent )
85
+ {
86
+ base . InitializeView ( parent ) ;
87
+ userSettingsView . InitializeView ( this ) ;
88
+ }
91
89
92
90
public override void OnEnable ( )
93
91
{
94
92
base . OnEnable ( ) ;
93
+ userSettingsView . OnEnable ( ) ;
95
94
AttachHandlers ( Repository ) ;
96
95
97
96
remoteHasChanged = true ;
@@ -100,6 +99,7 @@ public override void OnEnable()
100
99
public override void OnDisable ( )
101
100
{
102
101
base . OnDisable ( ) ;
102
+ userSettingsView . OnDisable ( ) ;
103
103
DetachHandlers ( Repository ) ;
104
104
}
105
105
@@ -112,6 +112,7 @@ public override void OnDataUpdate()
112
112
public override void OnRepositoryChanged ( IRepository oldRepository )
113
113
{
114
114
base . OnRepositoryChanged ( oldRepository ) ;
115
+ userSettingsView . OnRepositoryChanged ( oldRepository ) ;
115
116
116
117
DetachHandlers ( oldRepository ) ;
117
118
AttachHandlers ( Repository ) ;
@@ -152,7 +153,7 @@ public override void OnGUI()
152
153
{
153
154
scroll = GUILayout . BeginScrollView ( scroll ) ;
154
155
{
155
- OnUserSettingsGUI ( ) ;
156
+ userSettingsView . OnGUI ( ) ;
156
157
157
158
GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
158
159
@@ -182,72 +183,27 @@ private void MaybeUpdateData()
182
183
183
184
if ( Repository == null )
184
185
{
185
- if ( ( cachedUser == null || String . IsNullOrEmpty ( cachedUser . Name ) ) && GitClient != null )
186
- {
187
- var user = new User ( ) ;
188
- GitClient . GetConfig ( "user.name" , GitConfigSource . User )
189
- . Then ( ( success , value ) => user . Name = value ) . Then (
190
- GitClient . GetConfig ( "user.email" , GitConfigSource . User )
191
- . Then ( ( success , value ) => user . Email = value ) )
192
- . FinallyInUI ( ( success , ex ) =>
193
- {
194
- if ( success && ! String . IsNullOrEmpty ( user . Name ) )
195
- {
196
- cachedUser = user ;
197
- userDataHasChanged = true ;
198
- Redraw ( ) ;
199
- }
200
- } )
201
- . Start ( ) ;
202
- }
203
-
204
- if ( userDataHasChanged )
205
- {
206
- newGitName = gitName = cachedUser . Name ;
207
- newGitEmail = gitEmail = cachedUser . Email ;
208
- userDataHasChanged = false ;
209
- }
210
186
return ;
211
187
}
212
188
213
- userDataHasChanged = Repository . User . Name != gitName || Repository . User . Email != gitEmail ;
214
-
215
- if ( ! remoteHasChanged && ! userDataHasChanged )
189
+ if ( ! remoteHasChanged )
216
190
return ;
217
191
218
- if ( userDataHasChanged )
192
+ remoteHasChanged = false ;
193
+ var activeRemote = Repository . CurrentRemote ;
194
+ hasRemote = activeRemote . HasValue && ! String . IsNullOrEmpty ( activeRemote . Value . Url ) ;
195
+ if ( ! hasRemote )
219
196
{
220
- userDataHasChanged = false ;
221
- newGitName = gitName = Repository . User . Name ;
222
- newGitEmail = gitEmail = Repository . User . Email ;
197
+ repositoryRemoteName = DefaultRepositoryRemoteName ;
198
+ newRepositoryRemoteUrl = repositoryRemoteUrl = string . Empty ;
223
199
}
224
-
225
- if ( remoteHasChanged )
200
+ else
226
201
{
227
- remoteHasChanged = false ;
228
- var activeRemote = Repository . CurrentRemote ;
229
- hasRemote = activeRemote . HasValue && ! String . IsNullOrEmpty ( activeRemote . Value . Url ) ;
230
- if ( ! hasRemote )
231
- {
232
- repositoryRemoteName = DefaultRepositoryRemoteName ;
233
- newRepositoryRemoteUrl = repositoryRemoteUrl = string . Empty ;
234
- }
235
- else
236
- {
237
- repositoryRemoteName = activeRemote . Value . Name ;
238
- newRepositoryRemoteUrl = repositoryRemoteUrl = activeRemote . Value . Url ;
239
- }
202
+ repositoryRemoteName = activeRemote . Value . Name ;
203
+ newRepositoryRemoteUrl = repositoryRemoteUrl = activeRemote . Value . Url ;
240
204
}
241
205
}
242
206
243
- private void ResetToDefaults ( )
244
- {
245
- gitName = Repository != null ? Repository . User . Name : String . Empty ;
246
- gitEmail = Repository != null ? Repository . User . Email : String . Empty ;
247
- repositoryRemoteName = DefaultRepositoryRemoteName ;
248
- repositoryRemoteUrl = string . Empty ;
249
- }
250
-
251
207
private void Repository_OnActiveRemoteChanged ( string remote )
252
208
{
253
209
remoteHasChanged = true ;
@@ -273,70 +229,6 @@ private void OnLocksUpdate(IEnumerable<GitLock> update)
273
229
Redraw ( ) ;
274
230
}
275
231
276
- private void OnUserSettingsGUI ( )
277
- {
278
- GUILayout . Label ( GitConfigTitle , EditorStyles . boldLabel ) ;
279
-
280
- EditorGUI . BeginDisabledGroup ( isBusy ) ;
281
- {
282
- newGitName = EditorGUILayout . TextField ( GitConfigNameLabel , newGitName ) ;
283
- newGitEmail = EditorGUILayout . TextField ( GitConfigEmailLabel , newGitEmail ) ;
284
-
285
- var needsSaving = newGitName != gitName || newGitEmail != gitEmail ;
286
- EditorGUI . BeginDisabledGroup ( ! needsSaving ) ;
287
- {
288
- if ( GUILayout . Button ( GitConfigUserSave , GUILayout . ExpandWidth ( false ) ) )
289
- {
290
- GitClient . SetConfig ( "user.name" , newGitName , GitConfigSource . User )
291
- . Then ( ( success , value ) =>
292
- {
293
- if ( success )
294
- {
295
- if ( Repository != null )
296
- {
297
- Repository . User . Name = value ;
298
- }
299
- else
300
- {
301
- if ( cachedUser == null )
302
- {
303
- cachedUser = new User ( ) ;
304
- }
305
- cachedUser . Name = value ;
306
- }
307
- }
308
- } )
309
- . Then (
310
- GitClient . SetConfig ( "user.email" , newGitEmail , GitConfigSource . User )
311
- . Then ( ( success , value ) =>
312
- {
313
- if ( success )
314
- {
315
- if ( Repository != null )
316
- {
317
- Repository . User . Email = value ;
318
- }
319
- else
320
- {
321
- cachedUser . Email = value ;
322
- userDataHasChanged = true ;
323
- }
324
- }
325
- } ) )
326
- . FinallyInUI ( ( _ , __ ) =>
327
- {
328
- isBusy = false ;
329
- Redraw ( ) ;
330
- } )
331
- . Start ( ) ;
332
- isBusy = true ;
333
- }
334
- }
335
- EditorGUI . EndDisabledGroup ( ) ;
336
- }
337
- EditorGUI . EndDisabledGroup ( ) ;
338
- }
339
-
340
232
private void OnRepositorySettingsGUI ( )
341
233
{
342
234
GUILayout . Label ( GitRepositoryTitle , EditorStyles . boldLabel ) ;
0 commit comments