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

Commit 41de08f

Browse files
Merge branch 'fixes/base-classes-with-serailized-fields' into fixes/changes-view-tree-focus
# Conflicts: # src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs
2 parents ac4970c + ff89b1b commit 41de08f

File tree

2 files changed

+104
-64
lines changed

2 files changed

+104
-64
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,56 @@ public class ChangesTree : Tree<ChangesTreeNode, GitStatusEntryTreeData>
3535
[SerializeField] public ChangesTreeNodeDictionary checkedFileNodes = new ChangesTreeNodeDictionary();
3636

3737
[NonSerialized] public Texture2D FolderIcon;
38+
[SerializeField] public string title = string.Empty;
39+
[SerializeField] public string pathSeparator = "/";
40+
[SerializeField] public bool displayRootNode = true;
41+
[SerializeField] public bool isCheckable = false;
42+
[SerializeField] private List<ChangesTreeNode> nodes = new List<ChangesTreeNode>();
43+
[SerializeField] private ChangesTreeNode selectedNode = null;
44+
45+
public override string Title
46+
{
47+
get { return title; }
48+
set { title = value; }
49+
}
50+
51+
public override bool DisplayRootNode
52+
{
53+
get { return displayRootNode; }
54+
set { displayRootNode = value; }
55+
}
56+
57+
public override bool IsCheckable
58+
{
59+
get { return isCheckable; }
60+
set { isCheckable = value; }
61+
}
62+
63+
public override string PathSeparator
64+
{
65+
get { return pathSeparator; }
66+
set { pathSeparator = value; }
67+
}
68+
69+
public override ChangesTreeNode SelectedNode
70+
{
71+
get
72+
{
73+
if (selectedNode != null && String.IsNullOrEmpty(selectedNode.Path))
74+
selectedNode = null;
75+
76+
return selectedNode;
77+
}
78+
set
79+
{
80+
selectedNode = value;
81+
}
82+
}
83+
84+
protected override List<ChangesTreeNode> Nodes
85+
{
86+
get { return nodes; }
87+
}
3888

3989
public void UpdateIcons(Texture2D folderIcon)
4090
{

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

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,81 +19,23 @@ public abstract class Tree<TNode, TData>: TreeBase<TNode, TData>
1919
public static float ItemHeight { get { return EditorGUIUtility.singleLineHeight; } }
2020
public static float ItemSpacing { get { return EditorGUIUtility.standardVerticalSpacing; } }
2121

22-
[SerializeField] public Rect Margin = new Rect();
23-
[SerializeField] public Rect Padding = new Rect();
24-
25-
[SerializeField] public string title = string.Empty;
26-
[SerializeField] public string pathSeparator = "/";
27-
[SerializeField] public bool displayRootNode = true;
28-
[SerializeField] public bool isCheckable = false;
29-
3022
[NonSerialized] public GUIStyle FolderStyle;
3123
[NonSerialized] public GUIStyle TreeNodeStyle;
3224
[NonSerialized] public GUIStyle ActiveTreeNodeStyle;
3325
[NonSerialized] public GUIStyle FocusedTreeNodeStyle;
3426
[NonSerialized] public GUIStyle FocusedActiveTreeNodeStyle;
3527

36-
[SerializeField] private List<TNode> nodes = new List<TNode>();
37-
[SerializeField] private TNode selectedNode = null;
3828

3929
[NonSerialized] private Stack<bool> indents = new Stack<bool>();
4030
[NonSerialized] private Action<TNode> rightClickNextRender;
4131
[NonSerialized] private TNode rightClickNextRenderNode;
42-
[NonSerialized] private int controlId;
4332

33+
[NonSerialized] private int controlId;
4434
[NonSerialized] private TreeSelection selectionObject;
4535

4636
public bool IsInitialized { get { return Nodes != null && Nodes.Count > 0 && !String.IsNullOrEmpty(Nodes[0].Path); } }
4737
public bool RequiresRepaint { get; private set; }
4838

49-
public override TNode SelectedNode
50-
{
51-
get
52-
{
53-
if (selectedNode != null && String.IsNullOrEmpty(selectedNode.Path))
54-
selectedNode = null;
55-
56-
return selectedNode;
57-
}
58-
set
59-
{
60-
selectedNode = value;
61-
if (value != null && selectionObject)
62-
{
63-
Selection.activeObject = selectionObject;
64-
}
65-
}
66-
}
67-
68-
public override string Title
69-
{
70-
get { return title; }
71-
set { title = value; }
72-
}
73-
74-
public override bool DisplayRootNode
75-
{
76-
get { return displayRootNode; }
77-
set { displayRootNode = value; }
78-
}
79-
80-
public override bool IsCheckable
81-
{
82-
get { return isCheckable; }
83-
set { isCheckable = value; }
84-
}
85-
86-
public override string PathSeparator
87-
{
88-
get { return pathSeparator; }
89-
set { pathSeparator = value; }
90-
}
91-
92-
protected override List<TNode> Nodes
93-
{
94-
get { return nodes; }
95-
}
96-
9739
public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode> singleClick = null, Action<TNode> doubleClick = null, Action<TNode> rightClick = null)
9840
{
9941
controlId = GUIUtility.GetControlID(FocusType.Keyboard);
@@ -137,8 +79,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
13779
var titleDisplay = !(rect.y > endDisplay || rect.yMax < startDisplay);
13880
if (titleDisplay)
13981
{
140-
var isSelected = selectedNode == titleNode && treeHasFocus;
141-
renderResult = titleNode.Render(rect, Styles.TreeIndentation, isSelected, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
82+
renderResult = titleNode.Render(rect, Styles.TreeIndentation, SelectedNode == titleNode, FolderStyle, TreeNodeStyle, ActiveTreeNodeStyle);
14283
}
14384

14485
if (renderResult == TreeNodeRenderResult.VisibilityChange)
@@ -171,8 +112,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
171112
var display = !(rect.y > endDisplay || rect.yMax < startDisplay);
172113
if (display)
173114
{
174-
var isSelected = selectedNode == node && treeHasFocus;
175-
renderResult = node.Render(rect, Styles.TreeIndentation, isSelected, FolderStyle, treeNodeStyle, activeTreeNodeStyle);
115+
renderResult = node.Render(rect, Styles.TreeIndentation, SelectedNode == node, FolderStyle, TreeNodeStyle, ActiveTreeNodeStyle);
176116
}
177117

178118
if (renderResult == TreeNodeRenderResult.VisibilityChange)
@@ -266,7 +206,7 @@ private bool HandleInput(Rect rect, TNode currentNode, int index, Action<TNode>
266206
}
267207

268208
// Keyboard navigation if this child is the current selection
269-
if (GUIUtility.keyboardControl == controlId && currentNode == selectedNode && Event.current.type == EventType.KeyDown)
209+
if (currentNode == SelectedNode && Event.current.type == EventType.KeyDown)
270210
{
271211
int directionY = Event.current.keyCode == KeyCode.UpArrow ? -1 : Event.current.keyCode == KeyCode.DownArrow ? 1 : 0;
272212
int directionX = Event.current.keyCode == KeyCode.LeftArrow ? -1 : Event.current.keyCode == KeyCode.RightArrow ? 1 : 0;
@@ -580,6 +520,56 @@ public class BranchesTree : Tree<TreeNode, GitBranchTreeData>
580520
[NonSerialized] public Texture2D BranchIcon;
581521
[NonSerialized] public Texture2D FolderIcon;
582522
[NonSerialized] public Texture2D GlobeIcon;
523+
[SerializeField] public string title = string.Empty;
524+
[SerializeField] public string pathSeparator = "/";
525+
[SerializeField] public bool displayRootNode = true;
526+
[SerializeField] public bool isCheckable = false;
527+
[SerializeField] private List<TreeNode> nodes = new List<TreeNode>();
528+
[SerializeField] private TreeNode selectedNode = null;
529+
530+
public override string Title
531+
{
532+
get { return title; }
533+
set { title = value; }
534+
}
535+
536+
public override bool DisplayRootNode
537+
{
538+
get { return displayRootNode; }
539+
set { displayRootNode = value; }
540+
}
541+
542+
public override bool IsCheckable
543+
{
544+
get { return isCheckable; }
545+
set { isCheckable = value; }
546+
}
547+
548+
public override string PathSeparator
549+
{
550+
get { return pathSeparator; }
551+
set { pathSeparator = value; }
552+
}
553+
554+
public override TreeNode SelectedNode
555+
{
556+
get
557+
{
558+
if (selectedNode != null && String.IsNullOrEmpty(selectedNode.Path))
559+
selectedNode = null;
560+
561+
return selectedNode;
562+
}
563+
set
564+
{
565+
selectedNode = value;
566+
}
567+
}
568+
569+
protected override List<TreeNode> Nodes
570+
{
571+
get { return nodes; }
572+
}
583573

584574
public void UpdateIcons(Texture2D activeBranchIcon, Texture2D branchIcon, Texture2D folderIcon, Texture2D globeIcon)
585575
{

0 commit comments

Comments
 (0)