@@ -66,13 +66,9 @@ class SettingsView : Subview
66
66
private const string MetricsOptInLabel = "Help us improve by sending anonymous usage data" ;
67
67
private const string DefaultRepositoryRemoteName = "origin" ;
68
68
69
- [ NonSerialized ] private bool busy = false ;
70
- [ NonSerialized ] private int lockedFileSelection = - 1 ;
71
69
[ NonSerialized ] private int newGitIgnoreRulesSelection = - 1 ;
72
- [ NonSerialized ] private bool hasRemote ;
73
70
[ NonSerialized ] private ConfigRemote ? activeRemote ;
74
71
75
- // TODO: Replace me with the real values
76
72
[ SerializeField ] private string gitName ;
77
73
[ SerializeField ] private string gitEmail ;
78
74
@@ -83,58 +79,65 @@ class SettingsView : Subview
83
79
[ SerializeField ] private string repositoryRemoteName ;
84
80
[ SerializeField ] private string repositoryRemoteUrl ;
85
81
[ SerializeField ] private Vector2 scroll ;
82
+ [ SerializeField ] private bool isBusy ;
83
+ [ SerializeField ] private int lockedFileSelection = - 1 ;
84
+ [ SerializeField ] private bool hasRemote ;
86
85
[ SerializeField ] private bool remoteHasChanged ;
86
+ [ SerializeField ] private bool userDataHasChanged ;
87
+
88
+ [ SerializeField ] private string newGitName ;
89
+ [ SerializeField ] private string newGitEmail ;
90
+ [ SerializeField ] private string newRepositoryRemoteUrl ;
87
91
88
92
public override void OnEnable ( )
89
93
{
90
94
base . OnEnable ( ) ;
91
- if ( lockedFiles == null )
92
- lockedFiles = new List < GitLock > ( ) ;
93
-
94
- if ( Repository != null )
95
- Repository . OnActiveRemoteChanged += Repository_OnActiveRemoteChanged ;
95
+ AttachHandlers ( Repository ) ;
96
96
}
97
97
98
98
public override void OnDisable ( )
99
99
{
100
100
base . OnDisable ( ) ;
101
-
102
- if ( Repository != null )
103
- {
104
- Repository . OnActiveRemoteChanged -= Repository_OnActiveRemoteChanged ;
105
- Repository . OnLocksUpdated -= RunLocksUpdateOnMainThread ;
106
- }
101
+ DetachHandlers ( Repository ) ;
107
102
}
108
103
109
104
public override void OnDataUpdate ( )
110
105
{
111
106
base . OnDataUpdate ( ) ;
112
-
113
- if ( Repository == null )
114
- return ;
115
-
116
- MaybeUpdateRemote ( ) ;
107
+ MaybeUpdateData ( ) ;
117
108
}
118
109
119
110
public override void OnRepositoryChanged ( IRepository oldRepository )
120
111
{
121
112
base . OnRepositoryChanged ( oldRepository ) ;
122
113
123
- if ( oldRepository != null )
124
- {
125
- oldRepository . OnActiveRemoteChanged -= Repository_OnActiveRemoteChanged ;
126
- oldRepository . OnLocksUpdated -= RunLocksUpdateOnMainThread ;
127
- }
114
+ DetachHandlers ( oldRepository ) ;
115
+ AttachHandlers ( Repository ) ;
116
+ Refresh ( ) ;
117
+ }
128
118
129
- if ( Repository != null )
130
- {
131
- gitName = Repository . User . Name ;
132
- gitEmail = Repository . User . Email ;
119
+ public override void Refresh ( )
120
+ {
121
+ base . Refresh ( ) ;
122
+ Repository . ListLocks ( ) . Start ( ) ;
123
+ }
133
124
134
- Repository . OnActiveRemoteChanged += Repository_OnActiveRemoteChanged ;
135
- Repository . OnLocksUpdated += RunLocksUpdateOnMainThread ;
136
- Repository . ListLocks ( ) . Start ( ) ;
137
- }
125
+ private void AttachHandlers ( IRepository repository )
126
+ {
127
+ if ( repository == null )
128
+ return ;
129
+
130
+ repository . OnActiveRemoteChanged += Repository_OnActiveRemoteChanged ;
131
+ repository . OnLocksUpdated += RunLocksUpdateOnMainThread ;
132
+ }
133
+
134
+ private void DetachHandlers ( IRepository repository )
135
+ {
136
+ if ( repository == null )
137
+ return ;
138
+
139
+ repository . OnActiveRemoteChanged -= Repository_OnActiveRemoteChanged ;
140
+ repository . OnLocksUpdated -= RunLocksUpdateOnMainThread ;
138
141
}
139
142
140
143
public override void OnGUI ( )
@@ -164,28 +167,46 @@ public override void OnGUI()
164
167
GUILayout . EndScrollView ( ) ;
165
168
}
166
169
167
- private void MaybeUpdateRemote ( )
170
+ private void MaybeUpdateData ( )
168
171
{
169
- if ( ! remoteHasChanged )
172
+ if ( lockedFiles == null )
173
+ lockedFiles = new List < GitLock > ( ) ;
174
+
175
+ userDataHasChanged = Repository == null || ( Repository . User . Name == gitName && Repository . User . Email == gitEmail ) ;
176
+
177
+ if ( Repository == null )
178
+ return ;
179
+
180
+ if ( ! remoteHasChanged && ! userDataHasChanged )
170
181
return ;
171
182
172
- remoteHasChanged = false ;
173
- hasRemote = activeRemote . HasValue && ! String . IsNullOrEmpty ( activeRemote . Value . Url ) ;
174
- if ( ! hasRemote )
183
+ if ( remoteHasChanged )
175
184
{
176
- ResetToDefaults ( ) ;
185
+ remoteHasChanged = false ;
186
+ hasRemote = activeRemote . HasValue && ! String . IsNullOrEmpty ( activeRemote . Value . Url ) ;
187
+ if ( ! hasRemote )
188
+ {
189
+ repositoryRemoteName = DefaultRepositoryRemoteName ;
190
+ repositoryRemoteUrl = string . Empty ;
191
+ }
192
+ else
193
+ {
194
+ repositoryRemoteName = activeRemote . Value . Name ;
195
+ repositoryRemoteUrl = activeRemote . Value . Url ;
196
+ }
177
197
}
178
- else
198
+
199
+ if ( userDataHasChanged && Repository != null )
179
200
{
180
- repositoryRemoteName = activeRemote . Value . Name ;
181
- repositoryRemoteUrl = activeRemote . Value . Url ;
201
+ gitName = Repository . User . Name ;
202
+ gitEmail = Repository . User . Email ;
182
203
}
183
204
}
184
205
185
206
private void ResetToDefaults ( )
186
207
{
187
- gitName = String . Empty ;
188
- gitEmail = String . Empty ;
208
+ gitName = Repository != null ? Repository . User . Name : String . Empty ;
209
+ gitEmail = Repository != null ? Repository . User . Email : String . Empty ;
189
210
repositoryRemoteName = DefaultRepositoryRemoteName ;
190
211
repositoryRemoteUrl = string . Empty ;
191
212
}
@@ -219,62 +240,59 @@ private void OnLocksUpdate(IEnumerable<GitLock> update)
219
240
private void OnUserSettingsGUI ( )
220
241
{
221
242
GUILayout . Label ( GitConfigTitle , EditorStyles . boldLabel ) ;
222
- GUI . enabled = ! busy && Repository != null ;
223
-
224
- gitName = EditorGUILayout . TextField ( GitConfigNameLabel , gitName ) ;
225
- gitEmail = EditorGUILayout . TextField ( GitConfigEmailLabel , gitEmail ) ;
226
243
227
- GUI . enabled = ! busy ;
228
- if ( GUILayout . Button ( GitConfigUserSave , GUILayout . ExpandWidth ( false ) ) )
244
+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
229
245
{
230
- var needsSaving = gitName != Repository . User . Name || gitEmail != Repository . User . Email ;
231
- if ( needsSaving )
246
+ newGitName = EditorGUILayout . TextField ( GitConfigNameLabel , newGitName ) ;
247
+ newGitEmail = EditorGUILayout . TextField ( GitConfigEmailLabel , newGitEmail ) ;
248
+
249
+ var needsSaving = newGitName != gitName || newGitEmail != gitEmail ;
250
+ EditorGUI . BeginDisabledGroup ( needsSaving ) ;
232
251
{
233
- GitClient . SetConfig ( "user.name" , gitName , GitConfigSource . User )
234
- . Then ( ( success , value ) => { if ( success ) Repository . User . Name = value ; } )
235
- . Then (
236
- GitClient . SetConfig ( "user.email" , gitEmail , GitConfigSource . User )
237
- . Then ( ( success , value ) => { if ( success ) Repository . User . Email = value ; } ) )
238
- . FinallyInUI ( ( _ , __ ) => busy = false ) ;
239
- busy = true ;
252
+ if ( GUILayout . Button ( GitConfigUserSave , GUILayout . ExpandWidth ( false ) ) )
253
+ {
254
+ GitClient . SetConfig ( "user.name" , newGitName , GitConfigSource . User )
255
+ . Then ( ( success , value ) => { if ( success ) Repository . User . Name = value ; } )
256
+ . Then (
257
+ GitClient . SetConfig ( "user.email" , newGitEmail , GitConfigSource . User )
258
+ . Then ( ( success , value ) => { if ( success ) Repository . User . Email = value ; } ) )
259
+ . FinallyInUI ( ( _ , __ ) => isBusy = false )
260
+ . Start ( ) ;
261
+ isBusy = true ;
262
+ }
240
263
}
241
264
}
242
- GUI . enabled = true ;
243
265
}
244
266
245
267
private void OnRepositorySettingsGUI ( )
246
268
{
247
269
GUILayout . Label ( GitRepositoryTitle , EditorStyles . boldLabel ) ;
248
- GUI . enabled = ! busy && Repository != null && ! String . IsNullOrEmpty ( repositoryRemoteName ) ;
249
-
250
- repositoryRemoteUrl = EditorGUILayout . TextField ( GitRepositoryRemoteLabel + ": " + repositoryRemoteName , repositoryRemoteUrl ) ;
251
-
252
- if ( GUILayout . Button ( GitRepositorySave , GUILayout . ExpandWidth ( false ) ) )
270
+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
253
271
{
254
- try
272
+ newRepositoryRemoteUrl = EditorGUILayout . TextField ( GitRepositoryRemoteLabel + ": " + repositoryRemoteName , newRepositoryRemoteUrl ) ;
273
+ var needsSaving = newRepositoryRemoteUrl != repositoryRemoteUrl ;
274
+ EditorGUI . BeginDisabledGroup ( needsSaving ) ;
255
275
{
256
- busy = true ;
257
- var needsSaving = ! Repository . CurrentRemote . HasValue ||
258
- ( ! String . IsNullOrEmpty ( repositoryRemoteUrl ) && repositoryRemoteUrl != Repository . CurrentRemote . Value . Name ) ;
259
- if ( needsSaving )
276
+ if ( GUILayout . Button ( GitRepositorySave , GUILayout . ExpandWidth ( false ) ) )
260
277
{
261
- Repository . SetupRemote ( repositoryRemoteName , repositoryRemoteUrl )
262
- . FinallyInUI ( ( _ , __ ) =>
263
- {
264
- busy = false ;
265
- Redraw ( ) ;
266
- } )
267
- . Start ( ) ;
278
+ try
279
+ {
280
+ isBusy = true ;
281
+ Repository . SetupRemote ( repositoryRemoteName , repositoryRemoteUrl )
282
+ . FinallyInUI ( ( _ , __ ) =>
283
+ {
284
+ isBusy = false ;
285
+ Redraw ( ) ;
286
+ } )
287
+ . Start ( ) ;
288
+ }
289
+ catch ( Exception ex )
290
+ {
291
+ Logger . Error ( ex ) ;
292
+ }
268
293
}
269
- else
270
- busy = false ;
271
- }
272
- catch ( Exception ex )
273
- {
274
- Logger . Error ( ex ) ;
275
294
}
276
295
}
277
- GUI . enabled = true ;
278
296
}
279
297
280
298
private bool ValidateGitInstall ( string path )
@@ -524,7 +542,7 @@ private void OnGitIgnoreRulesGUI()
524
542
525
543
private void OnGitLfsLocksGUI ( )
526
544
{
527
- GUI . enabled = ! busy && Repository != null ;
545
+ GUI . enabled = ! isBusy && Repository != null ;
528
546
GUILayout . BeginVertical ( ) ;
529
547
{
530
548
GUILayout . Label ( "Locked files" , EditorStyles . boldLabel ) ;
@@ -610,7 +628,7 @@ private void OnInstallPathGUI()
610
628
// Install path
611
629
GUILayout . Label ( GitInstallTitle , EditorStyles . boldLabel ) ;
612
630
613
- GUI . enabled = ! busy && gitExecPath != null ;
631
+ GUI . enabled = ! isBusy && gitExecPath != null ;
614
632
615
633
// Install path field
616
634
EditorGUI . BeginChangeCheck ( ) ;
@@ -659,7 +677,7 @@ private void OnPrivacyGui()
659
677
660
678
GUILayout . Label ( PrivacyTitle , EditorStyles . boldLabel ) ;
661
679
662
- GUI . enabled = ! busy && service != null ;
680
+ GUI . enabled = ! isBusy && service != null ;
663
681
664
682
var metricsEnabled = service != null ? service . Enabled : false ;
665
683
EditorGUI . BeginChangeCheck ( ) ;
@@ -678,7 +696,7 @@ private void OnLoggingSettingsGui()
678
696
{
679
697
GUILayout . Label ( DebugSettingsTitle , EditorStyles . boldLabel ) ;
680
698
681
- GUI . enabled = ! busy ;
699
+ GUI . enabled = ! isBusy ;
682
700
683
701
var traceLogging = Logging . TracingEnabled ;
684
702
0 commit comments