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

Commit c0d6e62

Browse files
Merge branch 'enhancements/git-path-save-button' into enhancements/git-path-view
# Conflicts: # src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs
2 parents 1c441ba + 5ef958b commit c0d6e62

File tree

2 files changed

+95
-66
lines changed

2 files changed

+95
-66
lines changed

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

Lines changed: 91 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,33 @@ class GitPathView : Subview
1818
private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}";
1919
private const string GitInstallFindButton = "Find install";
2020
private const string GitInstallPickInvalidOK = "OK";
21+
private const string PathToGit = "Path to Git";
22+
private const string GitPathSaveButton = "Save Path";
23+
24+
[SerializeField] private string gitExec;
25+
[SerializeField] private string gitExecParent;
26+
[SerializeField] private string gitExecExtension;
27+
[SerializeField] private string newGitExec;
28+
[NonSerialized] private bool gitExecHasChanged;
2129

2230
[NonSerialized] private bool isBusy;
31+
public override void OnEnable()
32+
{
33+
base.OnEnable();
34+
35+
gitExecHasChanged = true;
36+
}
37+
38+
public override void OnDisable()
39+
{
40+
base.OnDisable();
41+
}
42+
43+
public override void OnDataUpdate()
44+
{
45+
base.OnDataUpdate();
46+
MaybeUpdateData();
47+
}
2348

2449
public override bool IsBusy
2550
{
@@ -28,111 +53,113 @@ public override bool IsBusy
2853

2954
public override void OnGUI()
3055
{
31-
string gitExecPath = null;
32-
string gitExecParentPath = null;
33-
34-
string extension = null;
35-
36-
if (Environment != null)
37-
{
38-
extension = Environment.ExecutableExtension;
39-
40-
if (Environment.IsWindows)
41-
{
42-
extension = extension.TrimStart('.');
43-
}
44-
45-
if (Environment.GitExecutablePath != null)
46-
{
47-
gitExecPath = Environment.GitExecutablePath.ToString();
48-
gitExecParentPath = Environment.GitExecutablePath.Parent.ToString();
49-
}
50-
51-
if (gitExecParentPath == null)
52-
{
53-
gitExecParentPath = Environment.GitInstallPath;
54-
}
55-
}
56-
5756
// Install path
5857
GUILayout.Label(GitInstallTitle, EditorStyles.boldLabel);
5958

60-
EditorGUI.BeginDisabledGroup(IsBusy || Parent.IsBusy || gitExecPath == null);
59+
EditorGUI.BeginDisabledGroup(IsBusy || Parent.IsBusy);
6160
{
6261
// Install path field
63-
EditorGUI.BeginChangeCheck();
62+
//EditorGUI.BeginChangeCheck();
6463
{
6564
GUILayout.BeginHorizontal();
66-
gitExecPath = EditorGUILayout.TextField("Path to Git", gitExecPath);
67-
if (GUILayout.Button(BrowseButton, EditorStyles.miniButton, GUILayout.Width(25)))
6865
{
69-
var newValue = EditorUtility.OpenFilePanel(GitInstallBrowseTitle, gitExecParentPath, extension);
66+
newGitExec = EditorGUILayout.TextField(PathToGit, newGitExec);
7067

71-
if (!string.IsNullOrEmpty(newValue))
68+
if (GUILayout.Button(BrowseButton, EditorStyles.miniButton, GUILayout.Width(25)))
7269
{
73-
isBusy = true;
70+
GUI.FocusControl(null);
7471

75-
var validateGitInstall = !string.IsNullOrEmpty(newValue);
76-
if (validateGitInstall)
77-
{
78-
var nPath = newValue.ToNPath();
79-
if (!nPath.FileExists())
80-
{
81-
EditorUtility.DisplayDialog(GitInstallPickInvalidTitle,
82-
String.Format(GitInstallPickInvalidMessage, newValue),
83-
GitInstallPickInvalidOK);
72+
var newValue = EditorUtility.OpenFilePanel(GitInstallBrowseTitle,
73+
gitExecParent,
74+
gitExecExtension);
8475

85-
validateGitInstall = false;
86-
}
87-
}
88-
89-
if (validateGitInstall)
76+
if (!string.IsNullOrEmpty(newValue))
9077
{
91-
gitExecPath = newValue;
92-
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
93-
GUI.changed = true;
78+
newGitExec = newValue;
9479
}
9580
}
9681
}
9782
GUILayout.EndHorizontal();
9883
}
9984

100-
if (EditorGUI.EndChangeCheck())
85+
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
86+
87+
GUILayout.BeginHorizontal();
10188
{
102-
Logger.Trace("Setting GitExecPath: " + gitExecPath);
89+
var needsSaving = !string.IsNullOrEmpty(newGitExec)
90+
&& newGitExec != gitExec
91+
&& newGitExec.ToNPath().FileExists();
10392

104-
Manager.SystemSettings.Set(Constants.GitInstallPathKey, gitExecPath);
105-
Environment.GitExecutablePath = gitExecPath.ToNPath();
93+
EditorGUI.BeginDisabledGroup(!needsSaving);
94+
{
95+
if (GUILayout.Button(GitPathSaveButton, GUILayout.ExpandWidth(false)))
96+
{
97+
Logger.Trace("Saving Git Path:{0}", newGitExec);
10698

107-
isBusy = false;
108-
}
99+
GUI.FocusControl(null);
109100

110-
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
101+
Manager.SystemSettings.Set(Constants.GitInstallPathKey, newGitExec);
102+
Environment.GitExecutablePath = newGitExec.ToNPath();
103+
gitExecHasChanged = true;
104+
}
105+
}
106+
EditorGUI.EndDisabledGroup();
111107

112-
GUILayout.BeginHorizontal();
113-
{
114-
// Find button - for attempting to locate a new install
108+
//Find button - for attempting to locate a new install
115109
if (GUILayout.Button(GitInstallFindButton, GUILayout.ExpandWidth(false)))
116110
{
117-
isBusy = true;
111+
GUI.FocusControl(null);
118112

119113
var task = new ProcessTask<NPath>(Manager.CancellationToken, new FirstLineIsPathOutputProcessor())
120114
.Configure(Manager.ProcessManager, Environment.IsWindows ? "where" : "which", "git")
121115
.FinallyInUI((success, ex, path) =>
122116
{
117+
Logger.Trace("Find Git Completed Success:{0} Path:{1}", success, path);
118+
123119
if (success && !string.IsNullOrEmpty(path))
124120
{
121+
Manager.SystemSettings.Set(Constants.GitInstallPathKey, path);
125122
Environment.GitExecutablePath = path;
126-
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
123+
gitExecHasChanged = true;
127124
}
128-
129-
isBusy = false;
130125
});
131126
}
132127
}
133128
GUILayout.EndHorizontal();
134129
}
135130
EditorGUI.EndDisabledGroup();
136131
}
132+
133+
private void MaybeUpdateData()
134+
{
135+
if (gitExecHasChanged)
136+
{
137+
if (Environment != null)
138+
{
139+
if (gitExecExtension == null)
140+
{
141+
gitExecExtension = Environment.ExecutableExtension;
142+
143+
if (Environment.IsWindows)
144+
{
145+
gitExecExtension = gitExecExtension.TrimStart('.');
146+
}
147+
}
148+
149+
if (Environment.GitExecutablePath != null)
150+
{
151+
newGitExec = gitExec = Environment.GitExecutablePath.ToString();
152+
gitExecParent = Environment.GitExecutablePath.Parent.ToString();
153+
}
154+
155+
if (gitExecParent == null)
156+
{
157+
gitExecParent = Environment.GitInstallPath;
158+
}
159+
}
160+
161+
gitExecHasChanged = false;
162+
}
163+
}
137164
}
138165
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class SettingsView : Subview
5959
private const string EnableTraceLoggingLabel = "Enable Trace Logging";
6060
private const string MetricsOptInLabel = "Help us improve by sending anonymous usage data";
6161
private const string DefaultRepositoryRemoteName = "origin";
62+
private const string BrowseButton = "...";
63+
private const string PathToGit = "Path to Git";
64+
private const string GitPathSaveButton = "Save Path";
6265

6366
[NonSerialized] private int newGitIgnoreRulesSelection = -1;
6467
[NonSerialized] private bool isBusy;
@@ -223,6 +226,7 @@ private void MaybeUpdateData()
223226
newGitEmail = gitEmail = cachedUser.Email;
224227
userDataHasChanged = false;
225228
}
229+
226230
return;
227231
}
228232

@@ -433,8 +437,6 @@ private bool OnIssuesGUI()
433437
{
434438
Styles.BeginInitialStateArea(GitInstallTitle, GitInstallMissingMessage);
435439
{
436-
//TODO: This is removed in another branch anyway
437-
//OnInstallPathGUI();
438440
}
439441
Styles.EndInitialStateArea();
440442

0 commit comments

Comments
 (0)