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

Commit 78c7249

Browse files
Making a dedicated GitPathView
1 parent c9b9bbb commit 78c7249

File tree

3 files changed

+120
-87
lines changed

3 files changed

+120
-87
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="UI\HistoryView.cs" />
103103
<Compile Include="UI\IView.cs" />
104104
<Compile Include="UI\PublishView.cs" />
105+
<Compile Include="UI\GitPathView.cs" />
105106
<Compile Include="UI\SettingsView.cs" />
106107
<Compile Include="UI\Subview.cs" />
107108
<Compile Include="UI\Window.cs" />
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace GitHub.Unity
10+
{
11+
[Serializable]
12+
class GitPathView : Subview
13+
{
14+
private const string GitInstallTitle = "Git installation";
15+
private const string GitInstallBrowseTitle = "Select git binary";
16+
private const string GitInstallPickInvalidTitle = "Invalid Git install";
17+
private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}";
18+
private const string GitInstallFindButton = "Find install";
19+
private const string GitInstallPickInvalidOK = "OK";
20+
21+
public override void OnGUI()
22+
{
23+
string gitExecPath = null;
24+
string extension = null;
25+
string gitInstallPath = null;
26+
if (Environment != null)
27+
{
28+
extension = Environment.ExecutableExtension;
29+
if (Environment.IsWindows)
30+
{
31+
extension = extension.TrimStart('.');
32+
}
33+
34+
gitInstallPath = Environment.GitInstallPath;
35+
36+
if (Environment.GitExecutablePath != null)
37+
gitExecPath = Environment.GitExecutablePath.ToString();
38+
}
39+
40+
// Install path
41+
GUILayout.Label(GitInstallTitle, EditorStyles.boldLabel);
42+
43+
EditorGUI.BeginDisabledGroup(gitExecPath == null);
44+
{
45+
// Install path field
46+
EditorGUI.BeginChangeCheck();
47+
{
48+
//TODO: Verify necessary value for a non Windows OS
49+
Styles.PathField(ref gitExecPath,
50+
() => EditorUtility.OpenFilePanel(GitInstallBrowseTitle,
51+
gitInstallPath,
52+
extension), ValidateGitInstall);
53+
}
54+
if (EditorGUI.EndChangeCheck())
55+
{
56+
Logger.Trace("Setting GitExecPath: " + gitExecPath);
57+
58+
Manager.SystemSettings.Set(Constants.GitInstallPathKey, gitExecPath);
59+
Environment.GitExecutablePath = gitExecPath.ToNPath();
60+
}
61+
62+
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
63+
64+
GUILayout.BeginHorizontal();
65+
{
66+
// Find button - for attempting to locate a new install
67+
if (GUILayout.Button(GitInstallFindButton, GUILayout.ExpandWidth(false)))
68+
{
69+
var task = new ProcessTask<NPath>(Manager.CancellationToken, new FirstLineIsPathOutputProcessor())
70+
.Configure(Manager.ProcessManager, Environment.IsWindows ? "where" : "which", "git")
71+
.FinallyInUI((success, ex, path) =>
72+
{
73+
if (success && !string.IsNullOrEmpty(path))
74+
{
75+
Environment.GitExecutablePath = path;
76+
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
77+
}
78+
});
79+
}
80+
}
81+
GUILayout.EndHorizontal();
82+
}
83+
EditorGUI.EndDisabledGroup();
84+
}
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+
}
100+
}

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

Lines changed: 19 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ class SettingsView : Subview
3939
private const string GitInstallTitle = "Git installation";
4040
private const string GitInstallMissingMessage =
4141
"GitHub was unable to locate a valid Git install. Please specify install location or install git.";
42-
private const string GitInstallBrowseTitle = "Select git binary";
43-
private const string GitInstallPickInvalidTitle = "Invalid Git install";
44-
private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}";
45-
private const string GitInstallPickInvalidOK = "OK";
46-
private const string GitInstallFindButton = "Find install";
47-
private const string GitInstallURL = "http://desktop.github.com";
4842
private const string GitIgnoreRulesTitle = "gitignore rules";
4943
private const string GitIgnoreRulesEffect = "Effect";
5044
private const string GitIgnoreRulesFile = "File";
@@ -88,10 +82,19 @@ class SettingsView : Subview
8882
[SerializeField] private string newGitEmail;
8983
[SerializeField] private string newRepositoryRemoteUrl;
9084
[SerializeField] private User cachedUser;
85+
[SerializeField] private GitPathView gitPathView = new GitPathView();
86+
87+
public override void InitializeView(IView parent)
88+
{
89+
base.InitializeView(parent);
90+
gitPathView.InitializeView(this);
91+
}
92+
9193

9294
public override void OnEnable()
9395
{
9496
base.OnEnable();
97+
gitPathView.OnEnable();
9598
AttachHandlers(Repository);
9699

97100
remoteHasChanged = true;
@@ -100,18 +103,25 @@ public override void OnEnable()
100103
public override void OnDisable()
101104
{
102105
base.OnDisable();
106+
gitPathView.OnDisable();
103107
DetachHandlers(Repository);
104108
}
105109

106110
public override void OnDataUpdate()
107111
{
108112
base.OnDataUpdate();
113+
114+
if (gitPathView != null)
115+
{
116+
gitPathView.OnDataUpdate();
117+
}
109118
MaybeUpdateData();
110119
}
111120

112121
public override void OnRepositoryChanged(IRepository oldRepository)
113122
{
114123
base.OnRepositoryChanged(oldRepository);
124+
gitPathView.OnRepositoryChanged(oldRepository);
115125

116126
DetachHandlers(oldRepository);
117127
AttachHandlers(Repository);
@@ -167,7 +177,7 @@ public override void OnGUI()
167177
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
168178
}
169179

170-
OnInstallPathGUI();
180+
gitPathView.OnGUI();
171181
OnPrivacyGui();
172182
OnLoggingSettingsGui();
173183
}
@@ -371,20 +381,6 @@ private void OnRepositorySettingsGUI()
371381
EditorGUI.EndDisabledGroup();
372382
}
373383

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-
388384
private bool OnIssuesGUI()
389385
{
390386
IList<ProjectConfigurationIssue> projectConfigurationIssues;
@@ -431,7 +427,8 @@ private bool OnIssuesGUI()
431427
{
432428
Styles.BeginInitialStateArea(GitInstallTitle, GitInstallMissingMessage);
433429
{
434-
OnInstallPathGUI();
430+
//TODO: This is removed in another branch anyway
431+
//OnInstallPathGUI();
435432
}
436433
Styles.EndInitialStateArea();
437434

@@ -685,71 +682,6 @@ private void OnGitLfsLocksGUI()
685682
EditorGUI.EndDisabledGroup();
686683
}
687684

688-
private void OnInstallPathGUI()
689-
{
690-
string gitExecPath = null;
691-
string extension = null;
692-
string gitInstallPath = null;
693-
if (Environment != null)
694-
{
695-
extension = Environment.ExecutableExtension;
696-
if (Environment.IsWindows)
697-
{
698-
extension = extension.TrimStart('.');
699-
}
700-
701-
gitInstallPath = Environment.GitInstallPath;
702-
703-
if (Environment.GitExecutablePath != null)
704-
gitExecPath = Environment.GitExecutablePath.ToString();
705-
}
706-
707-
// Install path
708-
GUILayout.Label(GitInstallTitle, EditorStyles.boldLabel);
709-
710-
EditorGUI.BeginDisabledGroup(isBusy || gitExecPath == null);
711-
{
712-
// Install path field
713-
EditorGUI.BeginChangeCheck();
714-
{
715-
//TODO: Verify necessary value for a non Windows OS
716-
Styles.PathField(ref gitExecPath,
717-
() => EditorUtility.OpenFilePanel(GitInstallBrowseTitle,
718-
gitInstallPath,
719-
extension), ValidateGitInstall);
720-
}
721-
if (EditorGUI.EndChangeCheck())
722-
{
723-
Logger.Trace("Setting GitExecPath: " + gitExecPath);
724-
725-
Manager.SystemSettings.Set(Constants.GitInstallPathKey, gitExecPath);
726-
Environment.GitExecutablePath = gitExecPath.ToNPath();
727-
}
728-
729-
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
730-
731-
GUILayout.BeginHorizontal();
732-
{
733-
// Find button - for attempting to locate a new install
734-
if (GUILayout.Button(GitInstallFindButton, GUILayout.ExpandWidth(false)))
735-
{
736-
var task = new ProcessTask<NPath>(Manager.CancellationToken, new FirstLineIsPathOutputProcessor())
737-
.Configure(Manager.ProcessManager, Environment.IsWindows ? "where" : "which", "git")
738-
.FinallyInUI((success, ex, path) =>
739-
{
740-
if (success && !string.IsNullOrEmpty(path))
741-
{
742-
Environment.GitExecutablePath = path;
743-
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
744-
}
745-
});
746-
}
747-
}
748-
GUILayout.EndHorizontal();
749-
}
750-
EditorGUI.EndDisabledGroup();
751-
}
752-
753685
private void OnPrivacyGui()
754686
{
755687
var service = Manager != null && Manager.UsageTracker != null ? Manager.UsageTracker : null;

0 commit comments

Comments
 (0)