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

Commit 0b81ed4

Browse files
Conslidating icon update logic
1 parent 440175d commit 0b81ed4

File tree

2 files changed

+37
-54
lines changed

2 files changed

+37
-54
lines changed

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

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -156,65 +156,14 @@ private void BuildTree()
156156

157157
private void UpdateTreeIcons()
158158
{
159-
var localsLoaded = false;
160-
var remotesLoaded = false;
161-
162159
if (treeLocals != null)
163160
{
164-
if (treeLocals.ActiveNodeIcon == null)
165-
{
166-
localsLoaded = true;
167-
treeLocals.ActiveNodeIcon = Styles.ActiveBranchIcon;
168-
}
169-
170-
if (treeLocals.NodeIcon == null)
171-
{
172-
localsLoaded = true;
173-
treeLocals.NodeIcon = Styles.BranchIcon;
174-
}
175-
176-
if (treeLocals.FolderIcon == null)
177-
{
178-
localsLoaded = true;
179-
treeLocals.FolderIcon = Styles.FolderIcon;
180-
}
161+
treeLocals.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.RootFolderIcon);
181162
}
182163

183164
if (treeRemotes != null)
184165
{
185-
if (treeRemotes.ActiveNodeIcon == null)
186-
{
187-
remotesLoaded = true;
188-
treeRemotes.ActiveNodeIcon = Styles.ActiveBranchIcon;
189-
}
190-
191-
if (treeRemotes.NodeIcon == null)
192-
{
193-
remotesLoaded = true;
194-
treeRemotes.NodeIcon = Styles.BranchIcon;
195-
}
196-
197-
if (treeRemotes.RootFolderIcon == null)
198-
{
199-
remotesLoaded = true;
200-
treeRemotes.RootFolderIcon = Styles.RootFolderIcon;
201-
}
202-
203-
if (treeRemotes.FolderIcon == null)
204-
{
205-
remotesLoaded = true;
206-
treeRemotes.FolderIcon = Styles.FolderIcon;
207-
}
208-
}
209-
210-
if (localsLoaded)
211-
{
212-
treeLocals.LoadNodeIcons();
213-
}
214-
215-
if (remotesLoaded)
216-
{
217-
treeRemotes.LoadNodeIcons();
166+
treeRemotes.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.RootFolderIcon);
218167
}
219168
}
220169

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,40 @@ protected override Texture2D GetNodeIcon(TreeNode node)
3636
}
3737
return nodeIcon;
3838
}
39+
40+
public void UpdateIcons(Texture2D activeBranchIcon, Texture2D branchIcon, Texture2D folderIcon, Texture2D rootFolderIcon)
41+
{
42+
var localsLoaded = false;
43+
44+
if (ActiveNodeIcon == null)
45+
{
46+
localsLoaded = true;
47+
ActiveNodeIcon = activeBranchIcon;
48+
}
49+
50+
if (NodeIcon == null)
51+
{
52+
localsLoaded = true;
53+
NodeIcon = branchIcon;
54+
}
55+
56+
if (FolderIcon == null)
57+
{
58+
localsLoaded = true;
59+
FolderIcon = folderIcon;
60+
}
61+
62+
if (RootFolderIcon == null)
63+
{
64+
localsLoaded = true;
65+
RootFolderIcon = rootFolderIcon;
66+
}
67+
68+
if (localsLoaded)
69+
{
70+
LoadNodeIcons();
71+
}
72+
}
3973
}
4074

4175
[Serializable]
@@ -402,7 +436,7 @@ private void SetNodeIcon(TreeNode node)
402436

403437
protected abstract Texture2D GetNodeIcon(TreeNode node);
404438

405-
public void LoadNodeIcons()
439+
protected void LoadNodeIcons()
406440
{
407441
foreach (var treeNode in nodes)
408442
{

0 commit comments

Comments
 (0)