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

Commit ca6dc4b

Browse files
Trying to reload the icons
1 parent 1caab07 commit ca6dc4b

File tree

2 files changed

+91
-24
lines changed

2 files changed

+91
-24
lines changed

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

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public override void InitializeView(IView parent)
5959
public override void OnEnable()
6060
{
6161
base.OnEnable();
62+
UpdateTreeIcons();
6263
AttachHandlers(Repository);
6364
Repository.CheckLocalAndRemoteBranchListChangedEvent(lastLocalAndRemoteBranchListChangedEvent);
6465
}
@@ -134,25 +135,87 @@ private void Render()
134135

135136
private void BuildTree()
136137
{
138+
if (treeLocals == null)
139+
{
140+
treeLocals = new Tree();
141+
142+
treeRemotes = new Tree();
143+
144+
UpdateTreeIcons();
145+
}
146+
137147
localBranches.Sort(CompareBranches);
138148
remoteBranches.Sort(CompareBranches);
139-
treeLocals = new Tree();
140-
treeLocals.ActiveNodeIcon = Styles.ActiveBranchIcon;
141-
treeLocals.NodeIcon = Styles.BranchIcon;
142-
treeLocals.RootFolderIcon = Styles.RootFolderIcon;
143-
treeLocals.FolderIcon = Styles.FolderIcon;
144-
145-
treeRemotes = new Tree();
146-
treeRemotes.ActiveNodeIcon = Styles.ActiveBranchIcon;
147-
treeRemotes.NodeIcon = Styles.BranchIcon;
148-
treeRemotes.RootFolderIcon = Styles.RootFolderIcon;
149-
treeRemotes.FolderIcon = Styles.FolderIcon;
150149

151150
treeLocals.Load(localBranches.Cast<ITreeData>(), LocalTitle);
152151
treeRemotes.Load(remoteBranches.Cast<ITreeData>(), RemoteTitle);
153152
Redraw();
154153
}
155154

155+
private void UpdateTreeIcons()
156+
{
157+
var localsLoaded = false;
158+
var remotesLoaded = false;
159+
160+
if (treeLocals != null)
161+
{
162+
if (treeLocals.ActiveNodeIcon == null)
163+
{
164+
localsLoaded = true;
165+
treeLocals.ActiveNodeIcon = Styles.ActiveBranchIcon;
166+
}
167+
168+
if (treeLocals.NodeIcon == null)
169+
{
170+
localsLoaded = true;
171+
treeLocals.NodeIcon = Styles.BranchIcon;
172+
}
173+
174+
if (treeLocals.FolderIcon == null)
175+
{
176+
localsLoaded = true;
177+
treeLocals.FolderIcon = Styles.FolderIcon;
178+
}
179+
}
180+
181+
if (treeRemotes != null)
182+
{
183+
if (treeRemotes.ActiveNodeIcon == null)
184+
{
185+
remotesLoaded = true;
186+
treeRemotes.ActiveNodeIcon = Styles.ActiveBranchIcon;
187+
}
188+
189+
if (treeRemotes.NodeIcon == null)
190+
{
191+
remotesLoaded = true;
192+
treeRemotes.NodeIcon = Styles.BranchIcon;
193+
}
194+
195+
if (treeRemotes.RootFolderIcon == null)
196+
{
197+
remotesLoaded = true;
198+
treeRemotes.RootFolderIcon = Styles.RootFolderIcon;
199+
}
200+
201+
if (treeRemotes.FolderIcon == null)
202+
{
203+
remotesLoaded = true;
204+
treeRemotes.FolderIcon = Styles.FolderIcon;
205+
}
206+
}
207+
208+
if (localsLoaded)
209+
{
210+
treeLocals.LoadNodeIcons();
211+
}
212+
213+
if (remotesLoaded)
214+
{
215+
treeRemotes.LoadNodeIcons();
216+
}
217+
}
218+
156219
private void OnButtonBarGUI()
157220
{
158221
if (mode == BranchesMode.Default)

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class Tree
1717
[SerializeField] public Rect Margin = new Rect();
1818
[SerializeField] public Rect Padding = new Rect();
1919

20-
[SerializeField] public Texture2D ActiveNodeIcon;
21-
[SerializeField] public Texture2D NodeIcon;
22-
[SerializeField] public Texture2D FolderIcon;
23-
[SerializeField] public Texture2D RootFolderIcon;
20+
[NonSerialized] public Texture2D ActiveNodeIcon;
21+
[NonSerialized] public Texture2D NodeIcon;
22+
[NonSerialized] public Texture2D FolderIcon;
23+
[NonSerialized] public Texture2D RootFolderIcon;
2424

2525
[SerializeField] public GUIStyle FolderStyle;
2626
[SerializeField] public GUIStyle TreeNodeStyle;
@@ -82,7 +82,7 @@ public void Load(IEnumerable<ITreeData> data, string title)
8282
Level = 0,
8383
IsFolder = true
8484
};
85-
titleNode.Load();
85+
SetNodeIcons(titleNode);
8686
nodes.Add(titleNode);
8787

8888
foreach (var d in data)
@@ -110,9 +110,7 @@ public void Load(IEnumerable<ITreeData> data, string title)
110110
activeNode = node;
111111
}
112112

113-
ResetNodeIcons(node);
114-
115-
node.Load();
113+
SetNodeIcons(node);
116114

117115
nodes.Add(node);
118116
if (isFolder)
@@ -135,7 +133,6 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
135133
rect = new Rect(0f, rect.y, rect.width, ItemHeight);
136134

137135
var titleNode = nodes[0];
138-
ResetNodeIcons(titleNode);
139136
bool selectionChanged = titleNode.Render(rect, 0f, selectedNode == titleNode, FolderStyle, TreeNodeStyle, ActiveTreeNodeStyle);
140137

141138
if (selectionChanged)
@@ -153,8 +150,6 @@ public Rect Render(Rect rect, Vector2 scroll, Action<TreeNode> singleClick = nul
153150
for (; i < nodes.Count; i++)
154151
{
155152
var node = nodes[i];
156-
// ResetNodeIcons(node);
157-
158153
if (node.Level > level && !node.IsHidden)
159154
{
160155
Indent();
@@ -368,7 +363,7 @@ private void Unindent()
368363
indents.Pop();
369364
}
370365

371-
private void ResetNodeIcons(TreeNode node)
366+
private void SetNodeIcons(TreeNode node)
372367
{
373368
if (node.IsActive)
374369
{
@@ -385,8 +380,17 @@ private void ResetNodeIcons(TreeNode node)
385380
{
386381
node.Icon = NodeIcon;
387382
}
383+
388384
node.Load();
389385
}
386+
387+
public void LoadNodeIcons()
388+
{
389+
foreach (var treeNode in nodes)
390+
{
391+
SetNodeIcons(treeNode);
392+
}
393+
}
390394
}
391395

392396
[Serializable]
@@ -400,7 +404,7 @@ public class TreeNode
400404
public bool IsHidden;
401405
public bool IsActive;
402406
public GUIContent content;
403-
public Texture2D Icon;
407+
[NonSerialized] public Texture2D Icon;
404408

405409
public void Load()
406410
{

0 commit comments

Comments
 (0)