@@ -27,10 +27,12 @@ class GitPathView : Subview
2727 [ SerializeField ] private string gitExecParent ;
2828 [ SerializeField ] private string gitExecExtension ;
2929 [ SerializeField ] private string newGitExec ;
30+ [ SerializeField ] private bool isValueChanged ;
31+ [ SerializeField ] private bool isValueChangedAndFileExists ;
32+ [ SerializeField ] private string gitFileErrorMessage ;
33+ [ SerializeField ] private string gitVersionErrorMessage ;
3034
3135 [ NonSerialized ] private bool isBusy ;
32- [ NonSerialized ] private string gitFileErrorMessage ;
33- [ NonSerialized ] private string gitVersionErrorMessage ;
3436 [ NonSerialized ] private bool gitExecHasChanged ;
3537
3638 public override void OnEnable ( )
@@ -61,7 +63,15 @@ public override void OnGUI()
6163 // Install path field
6264 GUILayout . BeginHorizontal ( ) ;
6365 {
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+ }
6575
6676 if ( GUILayout . Button ( BrowseButton , EditorStyles . miniButton , GUILayout . Width ( 25 ) ) )
6777 {
@@ -89,20 +99,12 @@ public override void OnGUI()
8999
90100 GUILayout . BeginHorizontal ( ) ;
91101 {
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-
101102 EditorGUI . BeginDisabledGroup ( ! isValueChangedAndFileExists ) ;
102103 {
103104 if ( GUILayout . Button ( GitPathSaveButton , GUILayout . ExpandWidth ( false ) ) )
104105 {
105106 GUI . FocusControl ( null ) ;
107+ isBusy = true ;
106108
107109 ValidateAndSetGitInstallPath ( newGitExec ) ;
108110 }
@@ -115,6 +117,9 @@ public override void OnGUI()
115117 GUI . FocusControl ( null ) ;
116118 isBusy = true ;
117119
120+ newGitExec = gitExec ;
121+ CheckEnteredGitPath ( ) ;
122+
118123 new ProcessTask < NPath > ( Manager . CancellationToken , new FirstLineIsPathOutputProcessor ( ) )
119124 . Configure ( Manager . ProcessManager , Environment . IsWindows ? "where" : "which" , "git" )
120125 . FinallyInUI ( ( success , ex , path ) =>
@@ -137,8 +142,11 @@ public override void OnGUI()
137142
138143 if ( success )
139144 {
140- ValidateAndSetGitInstallPath ( path ) ;
145+ newGitExec = path ;
146+ CheckEnteredGitPath ( ) ;
141147 }
148+
149+ isBusy = false ;
142150 } ) . Start ( ) ;
143151 }
144152 }
@@ -165,6 +173,49 @@ public override void OnGUI()
165173 EditorGUI . EndDisabledGroup ( ) ;
166174 }
167175
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+
168219 private void ValidateAndSetGitInstallPath ( string value )
169220 {
170221 Logger . Trace ( "Validating Git Path:{0}" , value ) ;
@@ -225,37 +276,5 @@ private void ValidateAndSetGitInstallPath(string value)
225276
226277 } ) . Start ( ) ;
227278 }
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- }
260279 }
261280}
0 commit comments