@@ -27,10 +27,12 @@ class GitPathView : Subview
27
27
[ SerializeField ] private string gitExecParent ;
28
28
[ SerializeField ] private string gitExecExtension ;
29
29
[ SerializeField ] private string newGitExec ;
30
+ [ SerializeField ] private bool isValueChanged ;
31
+ [ SerializeField ] private bool isValueChangedAndFileExists ;
32
+ [ SerializeField ] private string gitFileErrorMessage ;
33
+ [ SerializeField ] private string gitVersionErrorMessage ;
30
34
31
35
[ NonSerialized ] private bool isBusy ;
32
- [ NonSerialized ] private string gitFileErrorMessage ;
33
- [ NonSerialized ] private string gitVersionErrorMessage ;
34
36
[ NonSerialized ] private bool gitExecHasChanged ;
35
37
36
38
public override void OnEnable ( )
@@ -61,7 +63,15 @@ public override void OnGUI()
61
63
// Install path field
62
64
GUILayout . BeginHorizontal ( ) ;
63
65
{
64
- newGitExec = EditorGUILayout . TextField ( PathToGit , newGitExec ) ;
66
+ EditorGUI . BeginChangeCheck ( ) ;
67
+ {
68
+ newGitExec = EditorGUILayout . TextField ( PathToGit , newGitExec ) ;
69
+ }
70
+
71
+ if ( EditorGUI . EndChangeCheck ( ) )
72
+ {
73
+ CheckEnteredGitPath ( ) ;
74
+ }
65
75
66
76
if ( GUILayout . Button ( BrowseButton , EditorStyles . miniButton , GUILayout . Width ( 25 ) ) )
67
77
{
@@ -89,20 +99,12 @@ public override void OnGUI()
89
99
90
100
GUILayout . BeginHorizontal ( ) ;
91
101
{
92
- var isValueChanged = ! string . IsNullOrEmpty ( newGitExec )
93
- && newGitExec != gitExec ;
94
-
95
- var isValueChangedAndFileExists = isValueChanged && newGitExec . ToNPath ( ) . FileExists ( ) ;
96
-
97
- gitFileErrorMessage = isValueChanged && ! isValueChangedAndFileExists
98
- ? ErrorInvalidPathMessage
99
- : null ;
100
-
101
102
EditorGUI . BeginDisabledGroup ( ! isValueChangedAndFileExists ) ;
102
103
{
103
104
if ( GUILayout . Button ( GitPathSaveButton , GUILayout . ExpandWidth ( false ) ) )
104
105
{
105
106
GUI . FocusControl ( null ) ;
107
+ isBusy = true ;
106
108
107
109
ValidateAndSetGitInstallPath ( newGitExec ) ;
108
110
}
@@ -115,6 +117,9 @@ public override void OnGUI()
115
117
GUI . FocusControl ( null ) ;
116
118
isBusy = true ;
117
119
120
+ newGitExec = gitExec ;
121
+ CheckEnteredGitPath ( ) ;
122
+
118
123
new ProcessTask < NPath > ( Manager . CancellationToken , new FirstLineIsPathOutputProcessor ( ) )
119
124
. Configure ( Manager . ProcessManager , Environment . IsWindows ? "where" : "which" , "git" )
120
125
. FinallyInUI ( ( success , ex , path ) =>
@@ -137,8 +142,11 @@ public override void OnGUI()
137
142
138
143
if ( success )
139
144
{
140
- ValidateAndSetGitInstallPath ( path ) ;
145
+ newGitExec = path ;
146
+ CheckEnteredGitPath ( ) ;
141
147
}
148
+
149
+ isBusy = false ;
142
150
} ) . Start ( ) ;
143
151
}
144
152
}
@@ -165,6 +173,49 @@ public override void OnGUI()
165
173
EditorGUI . EndDisabledGroup ( ) ;
166
174
}
167
175
176
+ private void MaybeUpdateData ( )
177
+ {
178
+ if ( gitExecHasChanged )
179
+ {
180
+ if ( Environment != null )
181
+ {
182
+ if ( gitExecExtension == null )
183
+ {
184
+ gitExecExtension = Environment . ExecutableExtension ;
185
+
186
+ if ( Environment . IsWindows )
187
+ {
188
+ gitExecExtension = gitExecExtension . TrimStart ( '.' ) ;
189
+ }
190
+ }
191
+
192
+ if ( Environment . GitExecutablePath != null )
193
+ {
194
+ newGitExec = gitExec = Environment . GitExecutablePath . ToString ( ) ;
195
+ gitExecParent = Environment . GitExecutablePath . Parent . ToString ( ) ;
196
+ }
197
+
198
+ if ( gitExecParent == null )
199
+ {
200
+ gitExecParent = Environment . GitInstallPath ;
201
+ }
202
+ }
203
+
204
+ gitExecHasChanged = false ;
205
+ }
206
+ }
207
+
208
+ private void CheckEnteredGitPath ( )
209
+ {
210
+ isValueChanged = ! string . IsNullOrEmpty ( newGitExec ) && newGitExec != gitExec ;
211
+
212
+ isValueChangedAndFileExists = isValueChanged && newGitExec . ToNPath ( ) . FileExists ( ) ;
213
+
214
+ gitFileErrorMessage = isValueChanged && ! isValueChangedAndFileExists ? ErrorInvalidPathMessage : null ;
215
+
216
+ gitVersionErrorMessage = null ;
217
+ }
218
+
168
219
private void ValidateAndSetGitInstallPath ( string value )
169
220
{
170
221
Logger . Trace ( "Validating Git Path:{0}" , value ) ;
@@ -225,37 +276,5 @@ private void ValidateAndSetGitInstallPath(string value)
225
276
226
277
} ) . Start ( ) ;
227
278
}
228
-
229
- private void MaybeUpdateData ( )
230
- {
231
- if ( gitExecHasChanged )
232
- {
233
- if ( Environment != null )
234
- {
235
- if ( gitExecExtension == null )
236
- {
237
- gitExecExtension = Environment . ExecutableExtension ;
238
-
239
- if ( Environment . IsWindows )
240
- {
241
- gitExecExtension = gitExecExtension . TrimStart ( '.' ) ;
242
- }
243
- }
244
-
245
- if ( Environment . GitExecutablePath != null )
246
- {
247
- newGitExec = gitExec = Environment . GitExecutablePath . ToString ( ) ;
248
- gitExecParent = Environment . GitExecutablePath . Parent . ToString ( ) ;
249
- }
250
-
251
- if ( gitExecParent == null )
252
- {
253
- gitExecParent = Environment . GitInstallPath ;
254
- }
255
- }
256
-
257
- gitExecHasChanged = false ;
258
- }
259
- }
260
279
}
261
280
}
0 commit comments