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

Commit fb91f18

Browse files
Merge pull request #464 from github-for-unity/enhancements/branches-view-rollup
TreeView Control Rollup
2 parents 34451c1 + 28e156d commit fb91f18

File tree

10 files changed

+902
-403
lines changed

10 files changed

+902
-403
lines changed

src/GitHub.Api/Git/GitBranch.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GitHub.Unity
44
{
5-
interface ITreeData
5+
public interface ITreeData
66
{
77
string Name { get; }
88
bool IsActive { get; }
@@ -17,10 +17,6 @@ public struct GitBranch : ITreeData
1717
public string tracking;
1818
public bool isActive;
1919

20-
public string Name { get { return name; } }
21-
public string Tracking { get { return tracking; } }
22-
public bool IsActive { get { return isActive; } }
23-
2420
public GitBranch(string name, string tracking, bool active)
2521
{
2622
Guard.ArgumentNotNullOrWhiteSpace(name, "name");
@@ -30,6 +26,10 @@ public GitBranch(string name, string tracking, bool active)
3026
this.isActive = active;
3127
}
3228

29+
public string Name => name;
30+
public string Tracking => tracking;
31+
public bool IsActive => isActive;
32+
3333
public override string ToString()
3434
{
3535
return $"{Name} Tracking? {Tracking} Active? {IsActive}";

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="UI\LoadingView.cs" />
104104
<Compile Include="UI\PublishView.cs" />
105105
<Compile Include="UI\InitProjectView.cs" />
106+
<Compile Include="UI\TreeControl.cs" />
106107
<Compile Include="UI\UserSettingsView.cs" />
107108
<Compile Include="UI\GitPathView.cs" />
108109
<Compile Include="UI\SettingsView.cs" />
@@ -207,6 +208,10 @@
207208
</None>
208209
<None Include="packages.config" />
209210
</ItemGroup>
211+
<ItemGroup>
212+
<EmbeddedResource Include="IconsAndLogos\globe%402x.png" />
213+
<EmbeddedResource Include="IconsAndLogos\globe.png" />
214+
</ItemGroup>
210215
<Import Project="..\..\..\..\..\common\nativelibraries.props" />
211216
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
212217
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -217,4 +222,4 @@
217222
</Target>
218223
-->
219224
<Import Project="..\..\..\..\..\common\build.targets" />
220-
</Project>
225+
</Project>
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ class Styles
2727
MinCommitTreePadding = 20f,
2828
FoldoutWidth = 11f,
2929
FoldoutIndentation = -2f,
30+
TreePadding = 12f,
3031
TreeIndentation = 12f,
3132
TreeRootIndentation = -5f,
3233
TreeVerticalSpacing = 3f,
3334
CommitIconSize = 16f,
3435
CommitIconHorizontalPadding = -5f,
3536
BranchListIndentation = 20f,
36-
BranchListSeperation = 15f,
37+
BranchListSeparation = 15f,
3738
RemotesTotalHorizontalMargin = 37f,
3839
RemotesNameRatio = .2f,
3940
RemotesUserRatio = .2f,
@@ -829,5 +830,79 @@ public static Texture2D DropdownListIcon
829830
return dropdownListIcon;
830831
}
831832
}
833+
834+
private static Texture2D globeIcon;
835+
public static Texture2D GlobeIcon
836+
{
837+
get
838+
{
839+
if (globeIcon == null)
840+
{
841+
globeIcon = Utility.GetIcon("globe.png", "[email protected]");
842+
}
843+
return globeIcon;
844+
}
845+
}
846+
847+
private static GUIStyle foldout;
848+
public static GUIStyle Foldout
849+
{
850+
get
851+
{
852+
if (foldout == null)
853+
{
854+
foldout = new GUIStyle(EditorStyles.foldout);
855+
foldout.name = "CustomFoldout";
856+
857+
foldout.focused.textColor = Color.white;
858+
foldout.onFocused.textColor = Color.white;
859+
foldout.focused.background = foldout.active.background;
860+
foldout.onFocused.background = foldout.onActive.background;
861+
}
862+
863+
return foldout;
864+
}
865+
}
866+
867+
private static GUIStyle treeNode;
868+
public static GUIStyle TreeNode
869+
{
870+
get
871+
{
872+
if (treeNode == null)
873+
{
874+
treeNode = new GUIStyle(GUI.skin.label);
875+
treeNode.name = "Custom TreeNode";
876+
877+
var color = new Color(62f / 255f, 125f / 255f, 231f / 255f);
878+
var texture = Utility.GetTextureFromColor(color);
879+
treeNode.focused.background = texture;
880+
treeNode.onFocused.background = texture;
881+
treeNode.focused.textColor = Color.white;
882+
treeNode.onFocused.textColor = Color.white;
883+
}
884+
885+
return treeNode;
886+
}
887+
}
888+
889+
private static GUIStyle treeNodeActive;
890+
public static GUIStyle TreeNodeActive
891+
{
892+
get
893+
{
894+
if (treeNodeActive == null)
895+
{
896+
treeNodeActive = new GUIStyle(TreeNode);
897+
treeNodeActive.name = "Custom TreeNode Active";
898+
treeNodeActive.fontStyle = FontStyle.Bold;
899+
treeNodeActive.focused.textColor = Color.white;
900+
treeNodeActive.active.textColor = Color.white;
901+
}
902+
903+
return treeNodeActive;
904+
}
905+
}
906+
832907
}
833908
}

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,38 @@ public static Texture2D GetIcon(string filename, string filename2x = "")
1616
filename = filename2x;
1717
}
1818

19+
Texture2D texture2D = null;
20+
1921
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GitHub.Unity.IconsAndLogos." + filename);
2022
if (stream != null)
21-
return stream.ToTexture2D();
23+
{
24+
texture2D = stream.ToTexture2D();
25+
}
26+
else
27+
{
28+
var iconPath = EntryPoint.Environment.ExtensionInstallPath.Combine("IconsAndLogos", filename).ToString(SlashMode.Forward);
29+
texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
30+
}
31+
32+
if (texture2D != null)
33+
{
34+
texture2D.hideFlags = HideFlags.HideAndDontSave;
35+
}
36+
37+
return texture2D;
38+
}
39+
40+
public static Texture2D GetTextureFromColor(Color color)
41+
{
42+
Color[] pix = new Color[1];
43+
pix[0] = color;
44+
45+
Texture2D result = new Texture2D(1, 1);
46+
result.hideFlags = HideFlags.HideAndDontSave;
47+
result.SetPixels(pix);
48+
result.Apply();
2249

23-
var iconPath = EntryPoint.Environment.ExtensionInstallPath.Combine("IconsAndLogos", filename).ToString(SlashMode.Forward);
24-
return AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
50+
return result;
2551
}
2652
}
2753

src/UnityExtension/Assets/Editor/GitHub.Unity/Services/AuthenticationService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using GitHub.Unity;
32

43
namespace GitHub.Unity
54
{

0 commit comments

Comments
 (0)