@@ -11,13 +11,21 @@ namespace GitHub.Unity
11
11
[ Serializable ]
12
12
class GitPathView : Subview
13
13
{
14
+ private const string BrowseButton = "..." ;
14
15
private const string GitInstallTitle = "Git installation" ;
15
16
private const string GitInstallBrowseTitle = "Select git binary" ;
16
17
private const string GitInstallPickInvalidTitle = "Invalid Git install" ;
17
18
private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}" ;
18
19
private const string GitInstallFindButton = "Find install" ;
19
20
private const string GitInstallPickInvalidOK = "OK" ;
20
21
22
+ [ NonSerialized ] private bool isBusy ;
23
+
24
+ public override bool IsBusy
25
+ {
26
+ get { return isBusy ; }
27
+ }
28
+
21
29
public override void OnGUI ( )
22
30
{
23
31
string gitExecPath = null ;
@@ -40,23 +48,51 @@ public override void OnGUI()
40
48
// Install path
41
49
GUILayout . Label ( GitInstallTitle , EditorStyles . boldLabel ) ;
42
50
43
- EditorGUI . BeginDisabledGroup ( gitExecPath == null ) ;
51
+ EditorGUI . BeginDisabledGroup ( IsBusy || Parent . IsBusy || gitExecPath == null ) ;
44
52
{
45
53
// Install path field
46
54
EditorGUI . BeginChangeCheck ( ) ;
47
55
{
48
- //TODO: Verify necessary value for a non Windows OS
49
- Styles . PathField ( ref gitExecPath ,
50
- ( ) => EditorUtility . OpenFilePanel ( GitInstallBrowseTitle ,
51
- gitInstallPath ,
52
- extension ) , ValidateGitInstall ) ;
56
+ GUILayout . BeginHorizontal ( ) ;
57
+ gitExecPath = EditorGUILayout . TextField ( "Path to Git" , gitExecPath ) ;
58
+ if ( GUILayout . Button ( BrowseButton , EditorStyles . miniButton , GUILayout . Width ( 25 ) ) )
59
+ {
60
+ var newValue = EditorUtility . OpenFilePanel ( GitInstallBrowseTitle , gitInstallPath , extension ) ;
61
+
62
+ if ( ! string . IsNullOrEmpty ( newValue ) )
63
+ {
64
+ isBusy = true ;
65
+
66
+ var validateGitInstall = ! string . IsNullOrEmpty ( newValue ) ;
67
+
68
+ if ( validateGitInstall && ! GitClient . ValidateGitInstall ( newValue . ToNPath ( ) ) )
69
+ {
70
+ EditorUtility . DisplayDialog ( GitInstallPickInvalidTitle ,
71
+ String . Format ( GitInstallPickInvalidMessage , newValue ) ,
72
+ GitInstallPickInvalidOK ) ;
73
+
74
+ validateGitInstall = false ;
75
+ }
76
+
77
+ if ( validateGitInstall )
78
+ {
79
+ gitExecPath = newValue ;
80
+ GUIUtility . keyboardControl = GUIUtility . hotControl = 0 ;
81
+ GUI . changed = true ;
82
+ }
83
+ }
84
+ }
85
+ GUILayout . EndHorizontal ( ) ;
53
86
}
87
+
54
88
if ( EditorGUI . EndChangeCheck ( ) )
55
89
{
56
90
Logger . Trace ( "Setting GitExecPath: " + gitExecPath ) ;
57
91
58
92
Manager . SystemSettings . Set ( Constants . GitInstallPathKey , gitExecPath ) ;
59
93
Environment . GitExecutablePath = gitExecPath . ToNPath ( ) ;
94
+
95
+ isBusy = false ;
60
96
}
61
97
62
98
GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
@@ -66,6 +102,8 @@ public override void OnGUI()
66
102
// Find button - for attempting to locate a new install
67
103
if ( GUILayout . Button ( GitInstallFindButton , GUILayout . ExpandWidth ( false ) ) )
68
104
{
105
+ isBusy = true ;
106
+
69
107
var task = new ProcessTask < NPath > ( Manager . CancellationToken , new FirstLineIsPathOutputProcessor ( ) )
70
108
. Configure ( Manager . ProcessManager , Environment . IsWindows ? "where" : "which" , "git" )
71
109
. FinallyInUI ( ( success , ex , path ) =>
@@ -75,26 +113,14 @@ public override void OnGUI()
75
113
Environment . GitExecutablePath = path ;
76
114
GUIUtility . keyboardControl = GUIUtility . hotControl = 0 ;
77
115
}
116
+
117
+ isBusy = false ;
78
118
} ) ;
79
119
}
80
120
}
81
121
GUILayout . EndHorizontal ( ) ;
82
122
}
83
123
EditorGUI . EndDisabledGroup ( ) ;
84
124
}
85
-
86
- private bool ValidateGitInstall ( string path )
87
- {
88
- if ( String . IsNullOrEmpty ( path ) )
89
- return false ;
90
- if ( ! GitClient . ValidateGitInstall ( path . ToNPath ( ) ) )
91
- {
92
- EditorUtility . DisplayDialog ( GitInstallPickInvalidTitle , String . Format ( GitInstallPickInvalidMessage , path ) ,
93
- GitInstallPickInvalidOK ) ;
94
- return false ;
95
- }
96
-
97
- return true ;
98
- }
99
125
}
100
126
}
0 commit comments