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

Commit 205da5b

Browse files
committed
Custom treeview control and cache manager
1 parent 4654cae commit 205da5b

File tree

11 files changed

+719
-466
lines changed

11 files changed

+719
-466
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ abstract class ApplicationManagerBase : IApplicationManager
1212
protected static ILogging Logger { get; } = Logging.GetLogger<IApplicationManager>();
1313

1414
private RepositoryManager repositoryManager;
15+
private IBranchCache branchCache;
1516

1617
public ApplicationManagerBase(SynchronizationContext synchronizationContext)
1718
{
@@ -21,6 +22,7 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
2122
UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
2223
ThreadingHelper.MainThreadScheduler = UIScheduler;
2324
TaskManager = new TaskManager(UIScheduler);
25+
CacheManager = new CacheManager();
2426
}
2527

2628
protected void Initialize()
@@ -80,6 +82,11 @@ private async Task SetupGit()
8082

8183
}
8284

85+
public void SetupCache(IBranchCache bcache)
86+
{
87+
branchCache = bcache;
88+
}
89+
8390
public ITask InitializeRepository()
8491
{
8592
Logger.Trace("Running Repository Initialize");
@@ -214,6 +221,7 @@ public void Dispose()
214221
public ISettings LocalSettings { get; protected set; }
215222
public ISettings SystemSettings { get; protected set; }
216223
public ISettings UserSettings { get; protected set; }
224+
public CacheManager CacheManager { get; private set; }
217225
public IUsageTracker UsageTracker { get; protected set; }
218226

219227
protected TaskScheduler UIScheduler { get; private set; }

src/GitHub.Api/Application/IApplicationManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IApplicationManager : IDisposable
1515
ISettings LocalSettings { get; }
1616
ISettings UserSettings { get; }
1717
ITaskManager TaskManager { get; }
18+
CacheManager CacheManager { get; }
1819
IGitClient GitClient { get; }
1920
IUsageTracker UsageTracker { get; }
2021

src/GitHub.Api/Cache/CacheManager.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace GitHub.Unity
5+
{
6+
public class CacheManager
7+
{
8+
private IBranchCache branchCache;
9+
public IBranchCache BranchCache
10+
{
11+
get { return branchCache; }
12+
set
13+
{
14+
if (branchCache == null)
15+
branchCache = value;
16+
}
17+
}
18+
19+
private Action onLocalBranchListChanged;
20+
21+
public void SetupCache(IBranchCache branchCache, IRepository repository)
22+
{
23+
if (repository == null)
24+
return;
25+
26+
BranchCache = branchCache;
27+
UpdateCache(repository);
28+
if (onLocalBranchListChanged != null)
29+
repository.OnLocalBranchListChanged -= onLocalBranchListChanged;
30+
onLocalBranchListChanged = () =>
31+
{
32+
if (!ThreadingHelper.InUIThread)
33+
new ActionTask(TaskManager.Instance.Token, () => UpdateCache(repository)) { Affinity = TaskAffinity.UI }.Start();
34+
else
35+
UpdateCache(repository);
36+
};
37+
repository.OnLocalBranchListChanged += onLocalBranchListChanged;
38+
}
39+
40+
private void UpdateCache(IRepository repository)
41+
{
42+
BranchCache.LocalBranches = repository.LocalBranches.ToList();
43+
BranchCache.RemoteBranches = repository.RemoteBranches.ToList();
44+
}
45+
}
46+
}

src/GitHub.Api/Cache/IBranchCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GitHub.Unity
44
{
5-
interface IBranchCache
5+
public interface IBranchCache
66
{
77
List<GitBranch> LocalBranches { get; set; }
88
List<GitBranch> RemoteBranches { get; set; }

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="Authentication\ILoginManager.cs" />
111111
<Compile Include="Application\ApplicationManagerBase.cs" />
112112
<Compile Include="Helpers\Constants.cs" />
113+
<Compile Include="Cache\CacheManager.cs" />
113114
<Compile Include="Cache\IBranchCache.cs" />
114115
<Compile Include="Helpers\Validation.cs" />
115116
<Compile Include="OutputProcessors\LfsVersionOutputProcessor.cs" />
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: 77 additions & 2 deletions
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,
@@ -195,7 +196,7 @@ public static GUIStyle Label
195196
label = new GUIStyle(GUI.skin.label);
196197
label.name = "CustomLabel";
197198

198-
var hierarchyStyle = GUI.skin.FindStyle("PR Label");
199+
GUIStyle hierarchyStyle = GUI.skin.FindStyle("PR Label");
199200
label.onNormal.background = hierarchyStyle.onNormal.background;
200201
label.onNormal.textColor = hierarchyStyle.onNormal.textColor;
201202
label.onFocused.background = hierarchyStyle.onFocused.background;
@@ -798,5 +799,79 @@ public static Texture2D DropdownListIcon
798799
return dropdownListIcon;
799800
}
800801
}
802+
803+
private static Texture2D rootFolderIcon;
804+
public static Texture2D RootFolderIcon
805+
{
806+
get
807+
{
808+
if (rootFolderIcon == null)
809+
{
810+
rootFolderIcon = Utility.GetIcon("globe.png", "[email protected]");
811+
}
812+
return rootFolderIcon;
813+
}
814+
}
815+
816+
private static GUIStyle foldout;
817+
public static GUIStyle Foldout
818+
{
819+
get
820+
{
821+
if (foldout == null)
822+
{
823+
foldout = new GUIStyle(EditorStyles.foldout);
824+
foldout.name = "CustomFoldout";
825+
826+
foldout.focused.textColor = Color.white;
827+
foldout.onFocused.textColor = Color.white;
828+
foldout.focused.background = foldout.active.background;
829+
foldout.onFocused.background = foldout.onActive.background;
830+
}
831+
832+
return foldout;
833+
}
834+
}
835+
836+
private static GUIStyle treeNode;
837+
public static GUIStyle TreeNode
838+
{
839+
get
840+
{
841+
if (treeNode == null)
842+
{
843+
treeNode = new GUIStyle(GUI.skin.label);
844+
treeNode.name = "Custom TreeNode";
845+
846+
var color = new Color(62f / 255f, 125f / 255f, 231f / 255f);
847+
var texture = Utility.GetTextureFromColor(color);
848+
treeNode.focused.background = texture;
849+
treeNode.onFocused.background = texture;
850+
treeNode.focused.textColor = Color.white;
851+
treeNode.onFocused.textColor = Color.white;
852+
}
853+
854+
return treeNode;
855+
}
856+
}
857+
858+
private static GUIStyle treeNodeActive;
859+
public static GUIStyle TreeNodeActive
860+
{
861+
get
862+
{
863+
if (treeNodeActive == null)
864+
{
865+
treeNodeActive = new GUIStyle(TreeNode);
866+
treeNodeActive.name = "Custom TreeNode Active";
867+
treeNodeActive.fontStyle = FontStyle.Bold;
868+
treeNodeActive.focused.textColor = Color.white;
869+
treeNodeActive.active.textColor = Color.white;
870+
}
871+
872+
return treeNodeActive;
873+
}
874+
}
875+
801876
}
802877
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ public static Texture2D GetIcon(string filename, string filename2x = "")
2323
var iconPath = EntryPoint.Environment.ExtensionInstallPath.Combine("IconsAndLogos", filename).ToString(SlashMode.Forward);
2424
return AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
2525
}
26+
27+
public static Texture2D GetTextureFromColor(Color color)
28+
{
29+
Color[] pix = new Color[1];
30+
pix[0] = color;
31+
32+
Texture2D result = new Texture2D(1, 1);
33+
result.SetPixels(pix);
34+
result.Apply();
35+
36+
return result;
37+
}
2638
}
2739

2840
static class StreamExtensions

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)