@@ -83,11 +83,12 @@ class SettingsView : Subview
83
83
[ SerializeField ] private int lockedFileSelection = - 1 ;
84
84
[ SerializeField ] private bool hasRemote ;
85
85
[ SerializeField ] private bool remoteHasChanged ;
86
- [ SerializeField ] private bool userDataHasChanged ;
86
+ [ NonSerialized ] private bool userDataHasChanged ;
87
87
88
88
[ SerializeField ] private string newGitName ;
89
89
[ SerializeField ] private string newGitEmail ;
90
90
[ SerializeField ] private string newRepositoryRemoteUrl ;
91
+ [ SerializeField ] private User cachedUser ;
91
92
92
93
public override void OnEnable ( )
93
94
{
@@ -113,13 +114,16 @@ public override void OnRepositoryChanged(IRepository oldRepository)
113
114
114
115
DetachHandlers ( oldRepository ) ;
115
116
AttachHandlers ( Repository ) ;
117
+ activeRemote = Repository . CurrentRemote ;
118
+ remoteHasChanged = true ;
116
119
Refresh ( ) ;
117
120
}
118
121
119
122
public override void Refresh ( )
120
123
{
121
124
base . Refresh ( ) ;
122
- Repository . ListLocks ( ) . Start ( ) ;
125
+ if ( Repository != null )
126
+ Repository . ListLocks ( ) . Start ( ) ;
123
127
}
124
128
125
129
private void AttachHandlers ( IRepository repository )
@@ -144,12 +148,12 @@ public override void OnGUI()
144
148
{
145
149
scroll = GUILayout . BeginScrollView ( scroll ) ;
146
150
{
147
- if ( Repository != null )
148
- {
149
- OnUserSettingsGUI ( ) ;
151
+ OnUserSettingsGUI ( ) ;
150
152
151
- GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
153
+ GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
152
154
155
+ if ( Repository != null )
156
+ {
153
157
OnRepositorySettingsGUI ( ) ;
154
158
155
159
GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
@@ -173,34 +177,62 @@ private void MaybeUpdateData()
173
177
lockedFiles = new List < GitLock > ( ) ;
174
178
175
179
if ( Repository == null )
180
+ {
181
+ if ( cachedUser == null || String . IsNullOrEmpty ( cachedUser . Name ) )
182
+ {
183
+ var user = new User ( ) ;
184
+ GitClient . GetConfig ( "user.name" , GitConfigSource . User )
185
+ . Then ( ( success , value ) => user . Name = value ) . Then (
186
+ GitClient . GetConfig ( "user.email" , GitConfigSource . User )
187
+ . Then ( ( success , value ) => user . Email = value ) )
188
+ . FinallyInUI ( ( success , ex ) =>
189
+ {
190
+ if ( success && ! String . IsNullOrEmpty ( user . Name ) )
191
+ {
192
+ cachedUser = user ;
193
+ userDataHasChanged = true ;
194
+ Redraw ( ) ;
195
+ }
196
+ } )
197
+ . Start ( ) ;
198
+ }
199
+
200
+ if ( userDataHasChanged )
201
+ {
202
+ newGitName = gitName = cachedUser . Name ;
203
+ newGitEmail = gitEmail = cachedUser . Email ;
204
+ userDataHasChanged = false ;
205
+ }
176
206
return ;
207
+ }
177
208
178
- userDataHasChanged = ! ( Repository . User . Name == gitName && Repository . User . Email == gitEmail ) ;
209
+ userDataHasChanged = Repository . User . Name != gitName || Repository . User . Email != gitEmail ;
179
210
180
211
if ( ! remoteHasChanged && ! userDataHasChanged )
181
212
return ;
182
213
214
+ if ( userDataHasChanged )
215
+ {
216
+ userDataHasChanged = false ;
217
+ newGitName = gitName = Repository . User . Name ;
218
+ newGitEmail = gitEmail = Repository . User . Email ;
219
+ }
220
+
183
221
if ( remoteHasChanged )
184
222
{
185
223
remoteHasChanged = false ;
186
224
hasRemote = activeRemote . HasValue && ! String . IsNullOrEmpty ( activeRemote . Value . Url ) ;
187
225
if ( ! hasRemote )
188
226
{
189
227
repositoryRemoteName = DefaultRepositoryRemoteName ;
190
- repositoryRemoteUrl = string . Empty ;
228
+ newRepositoryRemoteUrl = repositoryRemoteUrl = string . Empty ;
191
229
}
192
230
else
193
231
{
194
232
repositoryRemoteName = activeRemote . Value . Name ;
195
- repositoryRemoteUrl = activeRemote . Value . Url ;
233
+ newRepositoryRemoteUrl = repositoryRemoteUrl = activeRemote . Value . Url ;
196
234
}
197
235
}
198
-
199
- if ( userDataHasChanged )
200
- {
201
- gitName = Repository . User . Name ;
202
- gitEmail = Repository . User . Email ;
203
- }
204
236
}
205
237
206
238
private void ResetToDefaults ( )
@@ -243,42 +275,80 @@ private void OnUserSettingsGUI()
243
275
244
276
EditorGUI . BeginDisabledGroup ( isBusy ) ;
245
277
{
246
- newGitName = EditorGUILayout . TextField ( GitConfigNameLabel , gitName ) ;
247
- newGitEmail = EditorGUILayout . TextField ( GitConfigEmailLabel , gitEmail ) ;
278
+ newGitName = EditorGUILayout . TextField ( GitConfigNameLabel , newGitName ) ;
279
+ newGitEmail = EditorGUILayout . TextField ( GitConfigEmailLabel , newGitEmail ) ;
248
280
249
281
var needsSaving = newGitName != gitName || newGitEmail != gitEmail ;
250
- EditorGUI . BeginDisabledGroup ( needsSaving ) ;
282
+ EditorGUI . BeginDisabledGroup ( ! needsSaving ) ;
251
283
{
252
284
if ( GUILayout . Button ( GitConfigUserSave , GUILayout . ExpandWidth ( false ) ) )
253
285
{
254
286
GitClient . SetConfig ( "user.name" , newGitName , GitConfigSource . User )
255
- . Then ( ( success , value ) => { if ( success ) Repository . User . Name = value ; } )
287
+ . Then ( ( success , value ) =>
288
+ {
289
+ if ( success )
290
+ {
291
+ if ( Repository != null )
292
+ {
293
+ Repository . User . Name = value ;
294
+ }
295
+ else
296
+ {
297
+ if ( cachedUser == null )
298
+ {
299
+ cachedUser = new User ( ) ;
300
+ }
301
+ cachedUser . Name = value ;
302
+ }
303
+ }
304
+ } )
256
305
. Then (
257
306
GitClient . SetConfig ( "user.email" , newGitEmail , GitConfigSource . User )
258
- . Then ( ( success , value ) => { if ( success ) Repository . User . Email = value ; } ) )
259
- . FinallyInUI ( ( _ , __ ) => isBusy = false )
307
+ . Then ( ( success , value ) =>
308
+ {
309
+ if ( success )
310
+ {
311
+ if ( Repository != null )
312
+ {
313
+ Repository . User . Email = value ;
314
+ }
315
+ else
316
+ {
317
+ cachedUser . Email = value ;
318
+ userDataHasChanged = true ;
319
+ }
320
+ }
321
+ } ) )
322
+ . FinallyInUI ( ( _ , __ ) =>
323
+ {
324
+ isBusy = false ;
325
+ Redraw ( ) ;
326
+ } )
260
327
. Start ( ) ;
261
328
isBusy = true ;
262
329
}
263
330
}
331
+ EditorGUI . EndDisabledGroup ( ) ;
264
332
}
333
+ EditorGUI . EndDisabledGroup ( ) ;
265
334
}
266
335
267
336
private void OnRepositorySettingsGUI ( )
268
337
{
269
338
GUILayout . Label ( GitRepositoryTitle , EditorStyles . boldLabel ) ;
339
+
270
340
EditorGUI . BeginDisabledGroup ( isBusy ) ;
271
341
{
272
342
newRepositoryRemoteUrl = EditorGUILayout . TextField ( GitRepositoryRemoteLabel + ": " + repositoryRemoteName , newRepositoryRemoteUrl ) ;
273
- var needsSaving = newRepositoryRemoteUrl != repositoryRemoteUrl ;
274
- EditorGUI . BeginDisabledGroup ( needsSaving ) ;
343
+ var needsSaving = newRepositoryRemoteUrl != repositoryRemoteUrl && ! String . IsNullOrEmpty ( newRepositoryRemoteUrl ) ;
344
+ EditorGUI . BeginDisabledGroup ( ! needsSaving ) ;
275
345
{
276
346
if ( GUILayout . Button ( GitRepositorySave , GUILayout . ExpandWidth ( false ) ) )
277
347
{
278
348
try
279
349
{
280
350
isBusy = true ;
281
- Repository . SetupRemote ( repositoryRemoteName , repositoryRemoteUrl )
351
+ Repository . SetupRemote ( repositoryRemoteName , newRepositoryRemoteUrl )
282
352
. FinallyInUI ( ( _ , __ ) =>
283
353
{
284
354
isBusy = false ;
@@ -292,7 +362,9 @@ private void OnRepositorySettingsGUI()
292
362
}
293
363
}
294
364
}
365
+ EditorGUI . EndDisabledGroup ( ) ;
295
366
}
367
+ EditorGUI . EndDisabledGroup ( ) ;
296
368
}
297
369
298
370
private bool ValidateGitInstall ( string path )
0 commit comments