@@ -65,6 +65,9 @@ class SettingsView : Subview
65
65
private const string EnableTraceLoggingLabel = "Enable Trace Logging" ;
66
66
private const string MetricsOptInLabel = "Help us improve by sending anonymous usage data" ;
67
67
private const string DefaultRepositoryRemoteName = "origin" ;
68
+ private const string BrowseButton = "..." ;
69
+ private const string PathToGit = "Path to Git" ;
70
+ private const string GitPathSaveButton = "Save Path" ;
68
71
69
72
[ NonSerialized ] private int newGitIgnoreRulesSelection = - 1 ;
70
73
@@ -89,12 +92,19 @@ class SettingsView : Subview
89
92
[ SerializeField ] private string newRepositoryRemoteUrl ;
90
93
[ SerializeField ] private User cachedUser ;
91
94
95
+ [ SerializeField ] private string gitExec ;
96
+ [ SerializeField ] private string gitExecParent ;
97
+ [ SerializeField ] private string gitExecExtension ;
98
+ [ SerializeField ] private string newGitExec ;
99
+ [ NonSerialized ] private bool gitExecHasChanged ;
100
+
92
101
public override void OnEnable ( )
93
102
{
94
103
base . OnEnable ( ) ;
95
104
AttachHandlers ( Repository ) ;
96
105
97
106
remoteHasChanged = true ;
107
+ gitExecHasChanged = true ;
98
108
}
99
109
100
110
public override void OnDisable ( )
@@ -180,6 +190,35 @@ private void MaybeUpdateData()
180
190
if ( lockedFiles == null )
181
191
lockedFiles = new List < GitLock > ( ) ;
182
192
193
+ if ( gitExecHasChanged )
194
+ {
195
+ if ( Environment != null )
196
+ {
197
+ if ( gitExecExtension == null )
198
+ {
199
+ gitExecExtension = Environment . ExecutableExtension ;
200
+
201
+ if ( Environment . IsWindows )
202
+ {
203
+ gitExecExtension = gitExecExtension . TrimStart ( '.' ) ;
204
+ }
205
+ }
206
+
207
+ if ( Environment . GitExecutablePath != null )
208
+ {
209
+ newGitExec = gitExec = Environment . GitExecutablePath . ToString ( ) ;
210
+ gitExecParent = Environment . GitExecutablePath . Parent . ToString ( ) ;
211
+ }
212
+
213
+ if ( gitExecParent == null )
214
+ {
215
+ gitExecParent = Environment . GitInstallPath ;
216
+ }
217
+ }
218
+
219
+ gitExecHasChanged = false ;
220
+ }
221
+
183
222
if ( Repository == null )
184
223
{
185
224
if ( ( cachedUser == null || String . IsNullOrEmpty ( cachedUser . Name ) ) && GitClient != null )
@@ -207,6 +246,7 @@ private void MaybeUpdateData()
207
246
newGitEmail = gitEmail = cachedUser . Email ;
208
247
userDataHasChanged = false ;
209
248
}
249
+
210
250
return ;
211
251
}
212
252
@@ -371,20 +411,6 @@ private void OnRepositorySettingsGUI()
371
411
EditorGUI . EndDisabledGroup ( ) ;
372
412
}
373
413
374
- private bool ValidateGitInstall ( string path )
375
- {
376
- if ( String . IsNullOrEmpty ( path ) )
377
- return false ;
378
- if ( ! GitClient . ValidateGitInstall ( path . ToNPath ( ) ) )
379
- {
380
- EditorUtility . DisplayDialog ( GitInstallPickInvalidTitle , String . Format ( GitInstallPickInvalidMessage , path ) ,
381
- GitInstallPickInvalidOK ) ;
382
- return false ;
383
- }
384
-
385
- return true ;
386
- }
387
-
388
414
private bool OnIssuesGUI ( )
389
415
{
390
416
IList < ProjectConfigurationIssue > projectConfigurationIssues ;
@@ -660,69 +686,74 @@ private void OnGitLfsLocksGUI()
660
686
661
687
private void OnInstallPathGUI ( )
662
688
{
663
- string gitExecPath = null ;
664
- string gitExecParentPath = null ;
665
-
666
- string extension = null ;
667
-
668
- if ( Environment != null )
669
- {
670
- extension = Environment . ExecutableExtension ;
671
-
672
- if ( Environment . IsWindows )
673
- {
674
- extension = extension . TrimStart ( '.' ) ;
675
- }
676
-
677
- if ( Environment . GitExecutablePath != null )
678
- {
679
- gitExecPath = Environment . GitExecutablePath . ToString ( ) ;
680
- gitExecParentPath = Environment . GitExecutablePath . Parent . ToString ( ) ;
681
- }
682
-
683
- if ( gitExecParentPath == null )
684
- {
685
- gitExecParentPath = Environment . GitInstallPath ;
686
- }
687
- }
688
-
689
689
// Install path
690
690
GUILayout . Label ( GitInstallTitle , EditorStyles . boldLabel ) ;
691
691
692
- EditorGUI . BeginDisabledGroup ( isBusy || gitExecPath == null ) ;
692
+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
693
693
{
694
694
// Install path field
695
- EditorGUI . BeginChangeCheck ( ) ;
696
- {
697
- //TODO: Verify necessary value for a non Windows OS
698
- Styles . PathField ( ref gitExecPath ,
699
- ( ) => EditorUtility . OpenFilePanel ( GitInstallBrowseTitle ,
700
- gitExecParentPath ,
701
- extension ) , ValidateGitInstall ) ;
702
- }
703
- if ( EditorGUI . EndChangeCheck ( ) )
695
+ //EditorGUI.BeginChangeCheck();
704
696
{
705
- Logger . Trace ( "Setting GitExecPath: " + gitExecPath ) ;
697
+ GUILayout . BeginHorizontal ( ) ;
698
+ {
699
+ newGitExec = EditorGUILayout . TextField ( PathToGit , newGitExec ) ;
700
+
701
+ if ( GUILayout . Button ( BrowseButton , EditorStyles . miniButton , GUILayout . Width ( 25 ) ) )
702
+ {
703
+ GUI . FocusControl ( null ) ;
704
+
705
+ var newValue = EditorUtility . OpenFilePanel ( GitInstallBrowseTitle ,
706
+ gitExecParent ,
707
+ gitExecExtension ) ;
706
708
707
- Manager . SystemSettings . Set ( Constants . GitInstallPathKey , gitExecPath ) ;
708
- Environment . GitExecutablePath = gitExecPath . ToNPath ( ) ;
709
+ if ( ! string . IsNullOrEmpty ( newValue ) )
710
+ {
711
+ newGitExec = newValue ;
712
+ }
713
+ }
714
+ }
715
+ GUILayout . EndHorizontal ( ) ;
709
716
}
710
717
711
718
GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
712
719
713
720
GUILayout . BeginHorizontal ( ) ;
714
721
{
715
- // Find button - for attempting to locate a new install
722
+ var needsSaving = ! string . IsNullOrEmpty ( newGitExec )
723
+ && newGitExec != gitExec
724
+ && newGitExec . ToNPath ( ) . FileExists ( ) ;
725
+
726
+ EditorGUI . BeginDisabledGroup ( ! needsSaving ) ;
727
+ {
728
+ if ( GUILayout . Button ( GitPathSaveButton , GUILayout . ExpandWidth ( false ) ) )
729
+ {
730
+ Logger . Trace ( "Saving Git Path:{0}" , newGitExec ) ;
731
+
732
+ GUI . FocusControl ( null ) ;
733
+
734
+ Manager . SystemSettings . Set ( Constants . GitInstallPathKey , newGitExec ) ;
735
+ Environment . GitExecutablePath = newGitExec . ToNPath ( ) ;
736
+ gitExecHasChanged = true ;
737
+ }
738
+ }
739
+ EditorGUI . EndDisabledGroup ( ) ;
740
+
741
+ //Find button - for attempting to locate a new install
716
742
if ( GUILayout . Button ( GitInstallFindButton , GUILayout . ExpandWidth ( false ) ) )
717
743
{
744
+ GUI . FocusControl ( null ) ;
745
+
718
746
var task = new ProcessTask < NPath > ( Manager . CancellationToken , new FirstLineIsPathOutputProcessor ( ) )
719
747
. Configure ( Manager . ProcessManager , Environment . IsWindows ? "where" : "which" , "git" )
720
748
. FinallyInUI ( ( success , ex , path ) =>
721
749
{
750
+ Logger . Trace ( "Find Git Completed Success:{0} Path:{1}" , success , path ) ;
751
+
722
752
if ( success && ! string . IsNullOrEmpty ( path ) )
723
753
{
754
+ Manager . SystemSettings . Set ( Constants . GitInstallPathKey , path ) ;
724
755
Environment . GitExecutablePath = path ;
725
- GUIUtility . keyboardControl = GUIUtility . hotControl = 0 ;
756
+ gitExecHasChanged = true ;
726
757
}
727
758
} ) ;
728
759
}
0 commit comments