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

Commit ac4970c

Browse files
I thought this works
1 parent fd144fa commit ac4970c

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override void InitializeView(IView parent)
6262
public override void OnEnable()
6363
{
6464
base.OnEnable();
65-
UpdateTreeIcons();
65+
TreeOnEnable();
6666
AttachHandlers(Repository);
6767
Repository.CheckLocalAndRemoteBranchListChangedEvent(lastLocalAndRemoteBranchListChangedEvent);
6868
}
@@ -164,7 +164,7 @@ private void BuildTree()
164164
treeRemotes.Title = RemoteTitle;
165165
treeRemotes.IsRemote = true;
166166

167-
UpdateTreeIcons();
167+
TreeOnEnable();
168168
}
169169

170170
localBranches.Sort(CompareBranches);
@@ -175,15 +175,17 @@ private void BuildTree()
175175
Redraw();
176176
}
177177

178-
private void UpdateTreeIcons()
178+
private void TreeOnEnable()
179179
{
180180
if (treeLocals != null)
181181
{
182+
treeLocals.OnEnable();
182183
treeLocals.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
183184
}
184185

185186
if (treeRemotes != null)
186187
{
188+
treeRemotes.OnEnable();
187189
treeRemotes.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
188190
}
189191
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ChangesView : Subview
3535
public override void OnEnable()
3636
{
3737
base.OnEnable();
38-
UpdateTreeIcons();
38+
TreeOnEnable();
3939
AttachHandlers(Repository);
4040
Repository.CheckCurrentBranchChangedEvent(lastCurrentBranchChangedEvent);
4141
Repository.CheckStatusEntriesChangedEvent(lastStatusEntriesChangedEvent);
@@ -200,17 +200,18 @@ private void BuildTree()
200200
treeChanges.IsCheckable = true;
201201
treeChanges.PathSeparator = Environment.FileSystem.DirectorySeparatorChar.ToString();
202202

203-
UpdateTreeIcons();
203+
TreeOnEnable();
204204
}
205205

206206
treeChanges.Load(gitStatusEntries.Select(entry => new GitStatusEntryTreeData(entry)));
207207
Redraw();
208208
}
209209

210-
private void UpdateTreeIcons()
210+
private void TreeOnEnable()
211211
{
212212
if (treeChanges != null)
213213
{
214+
treeChanges.OnEnable();
214215
treeChanges.UpdateIcons(Styles.FolderIcon);
215216
}
216217
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public abstract class Tree<TNode, TData>: TreeBase<TNode, TData>
4141
[NonSerialized] private TNode rightClickNextRenderNode;
4242
[NonSerialized] private int controlId;
4343

44-
[SerializeField] private TreeSelection selectionObject = ScriptableObject.CreateInstance<TreeSelection>();
44+
[NonSerialized] private TreeSelection selectionObject;
4545

4646
public bool IsInitialized { get { return Nodes != null && Nodes.Count > 0 && !String.IsNullOrEmpty(Nodes[0].Path); } }
4747
public bool RequiresRepaint { get; private set; }
@@ -52,12 +52,16 @@ public override TNode SelectedNode
5252
{
5353
if (selectedNode != null && String.IsNullOrEmpty(selectedNode.Path))
5454
selectedNode = null;
55+
5556
return selectedNode;
5657
}
5758
set
5859
{
5960
selectedNode = value;
60-
Selection.activeObject = selectionObject;
61+
if (value != null && selectionObject)
62+
{
63+
Selection.activeObject = selectionObject;
64+
}
6165
}
6266
}
6367

@@ -133,7 +137,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
133137
var titleDisplay = !(rect.y > endDisplay || rect.yMax < startDisplay);
134138
if (titleDisplay)
135139
{
136-
var isSelected = selectedNode == titleNode;
140+
var isSelected = selectedNode == titleNode && treeHasFocus;
137141
renderResult = titleNode.Render(rect, Styles.TreeIndentation, isSelected, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
138142
}
139143

@@ -167,7 +171,8 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
167171
var display = !(rect.y > endDisplay || rect.yMax < startDisplay);
168172
if (display)
169173
{
170-
renderResult = node.Render(rect, Styles.TreeIndentation, selectedNode == node, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
174+
var isSelected = selectedNode == node && treeHasFocus;
175+
renderResult = node.Render(rect, Styles.TreeIndentation, isSelected, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
171176
}
172177

173178
if (renderResult == TreeNodeRenderResult.VisibilityChange)
@@ -374,6 +379,14 @@ protected void LoadNodeIcons()
374379
SetNodeIcon(treeNode);
375380
}
376381
}
382+
383+
public void OnEnable()
384+
{
385+
if (!selectionObject)
386+
{
387+
selectionObject = ScriptableObject.CreateInstance<TreeSelection>();
388+
}
389+
}
377390
}
378391

379392
[Serializable]

0 commit comments

Comments
 (0)