Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 907e149

Browse files
Properly adding IsBusy support; Inlining GitPathView functionality
1 parent 5f324d0 commit 907e149

File tree

3 files changed

+52
-43
lines changed

3 files changed

+52
-43
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/Misc/Styles.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class Styles
4646

4747
public const int HalfSpacing = (int)(BaseSpacing / 2);
4848

49-
private const string BrowseButton = "...";
5049
private const string WarningLabel = "<b>Warning:</b> {0}";
5150

5251
private static Color headerGreyColor = new Color(0.878f, 0.878f, 0.878f, 1.0f);
@@ -170,23 +169,6 @@ public static void Warning(string message)
170169
GUILayout.EndHorizontal();
171170
}
172171

173-
public static void PathField(ref string path, Func<string> browseFunction, Func<string, bool> validationFunction)
174-
{
175-
GUILayout.BeginHorizontal();
176-
path = EditorGUILayout.TextField("Path to Git", path);
177-
if (GUILayout.Button(BrowseButton, EditorStyles.miniButton, GUILayout.Width(25)))
178-
{
179-
var newValue = browseFunction();
180-
if (!string.IsNullOrEmpty(newValue) && validationFunction(newValue))
181-
{
182-
path = newValue;
183-
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
184-
GUI.changed = true;
185-
}
186-
}
187-
GUILayout.EndHorizontal();
188-
}
189-
190172
public static GUIStyle HistoryFileTreeBoxStyle
191173
{
192174
get

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ namespace GitHub.Unity
1111
[Serializable]
1212
class GitPathView : Subview
1313
{
14+
private const string BrowseButton = "...";
1415
private const string GitInstallTitle = "Git installation";
1516
private const string GitInstallBrowseTitle = "Select git binary";
1617
private const string GitInstallPickInvalidTitle = "Invalid Git install";
1718
private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}";
1819
private const string GitInstallFindButton = "Find install";
1920
private const string GitInstallPickInvalidOK = "OK";
2021

22+
[NonSerialized] private bool isBusy;
23+
24+
public override bool IsBusy
25+
{
26+
get { return isBusy; }
27+
}
28+
2129
public override void OnGUI()
2230
{
2331
string gitExecPath = null;
@@ -40,23 +48,51 @@ public override void OnGUI()
4048
// Install path
4149
GUILayout.Label(GitInstallTitle, EditorStyles.boldLabel);
4250

43-
EditorGUI.BeginDisabledGroup(gitExecPath == null);
51+
EditorGUI.BeginDisabledGroup(IsBusy || Parent.IsBusy || gitExecPath == null);
4452
{
4553
// Install path field
4654
EditorGUI.BeginChangeCheck();
4755
{
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();
5386
}
87+
5488
if (EditorGUI.EndChangeCheck())
5589
{
5690
Logger.Trace("Setting GitExecPath: " + gitExecPath);
5791

5892
Manager.SystemSettings.Set(Constants.GitInstallPathKey, gitExecPath);
5993
Environment.GitExecutablePath = gitExecPath.ToNPath();
94+
95+
isBusy = false;
6096
}
6197

6298
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
@@ -66,6 +102,8 @@ public override void OnGUI()
66102
// Find button - for attempting to locate a new install
67103
if (GUILayout.Button(GitInstallFindButton, GUILayout.ExpandWidth(false)))
68104
{
105+
isBusy = true;
106+
69107
var task = new ProcessTask<NPath>(Manager.CancellationToken, new FirstLineIsPathOutputProcessor())
70108
.Configure(Manager.ProcessManager, Environment.IsWindows ? "where" : "which", "git")
71109
.FinallyInUI((success, ex, path) =>
@@ -75,26 +113,14 @@ public override void OnGUI()
75113
Environment.GitExecutablePath = path;
76114
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
77115
}
116+
117+
isBusy = false;
78118
});
79119
}
80120
}
81121
GUILayout.EndHorizontal();
82122
}
83123
EditorGUI.EndDisabledGroup();
84124
}
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-
}
99125
}
100126
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ public override void OnRepositoryChanged(IRepository oldRepository)
133133

134134
public override bool IsBusy
135135
{
136-
get { return isBusy; }
136+
get { return isBusy || gitPathView.IsBusy; }
137137
}
138138

139139
public override void Refresh()
140140
{
141141
base.Refresh();
142+
gitPathView.Refresh();
142143
if (Repository != null && Repository.CurrentRemote.HasValue)
143144
{
144145
Repository.ListLocks().Start();
@@ -356,7 +357,7 @@ private void OnRepositorySettingsGUI()
356357
{
357358
GUILayout.Label(GitRepositoryTitle, EditorStyles.boldLabel);
358359

359-
EditorGUI.BeginDisabledGroup(isBusy);
360+
EditorGUI.BeginDisabledGroup(IsBusy);
360361
{
361362
newRepositoryRemoteUrl = EditorGUILayout.TextField(GitRepositoryRemoteLabel + ": " + repositoryRemoteName, newRepositoryRemoteUrl);
362363
var needsSaving = newRepositoryRemoteUrl != repositoryRemoteUrl && !String.IsNullOrEmpty(newRepositoryRemoteUrl);
@@ -593,7 +594,7 @@ private void OnGitIgnoreRulesGUI()
593594

594595
private void OnGitLfsLocksGUI()
595596
{
596-
EditorGUI.BeginDisabledGroup(isBusy || Repository == null);
597+
EditorGUI.BeginDisabledGroup(IsBusy || Repository == null);
597598
{
598599
GUILayout.BeginVertical();
599600
{
@@ -666,7 +667,7 @@ private void OnPrivacyGui()
666667

667668
GUILayout.Label(PrivacyTitle, EditorStyles.boldLabel);
668669

669-
EditorGUI.BeginDisabledGroup(isBusy || service == null);
670+
EditorGUI.BeginDisabledGroup(IsBusy || service == null);
670671
{
671672
var metricsEnabled = service != null ? service.Enabled : false;
672673
EditorGUI.BeginChangeCheck();
@@ -686,7 +687,7 @@ private void OnLoggingSettingsGui()
686687
{
687688
GUILayout.Label(DebugSettingsTitle, EditorStyles.boldLabel);
688689

689-
EditorGUI.BeginDisabledGroup(isBusy);
690+
EditorGUI.BeginDisabledGroup(IsBusy);
690691
{
691692
var traceLogging = Logging.TracingEnabled;
692693

0 commit comments

Comments
 (0)