@@ -19,81 +19,23 @@ public abstract class Tree<TNode, TData>: TreeBase<TNode, TData>
19
19
public static float ItemHeight { get { return EditorGUIUtility . singleLineHeight ; } }
20
20
public static float ItemSpacing { get { return EditorGUIUtility . standardVerticalSpacing ; } }
21
21
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
-
30
22
[ NonSerialized ] public GUIStyle FolderStyle ;
31
23
[ NonSerialized ] public GUIStyle TreeNodeStyle ;
32
24
[ NonSerialized ] public GUIStyle ActiveTreeNodeStyle ;
33
25
[ NonSerialized ] public GUIStyle FocusedTreeNodeStyle ;
34
26
[ NonSerialized ] public GUIStyle FocusedActiveTreeNodeStyle ;
35
27
36
- [ SerializeField ] private List < TNode > nodes = new List < TNode > ( ) ;
37
- [ SerializeField ] private TNode selectedNode = null ;
38
28
39
29
[ NonSerialized ] private Stack < bool > indents = new Stack < bool > ( ) ;
40
30
[ NonSerialized ] private Action < TNode > rightClickNextRender ;
41
31
[ NonSerialized ] private TNode rightClickNextRenderNode ;
42
- [ NonSerialized ] private int controlId ;
43
32
33
+ [ NonSerialized ] private int controlId ;
44
34
[ NonSerialized ] private TreeSelection selectionObject ;
45
35
46
36
public bool IsInitialized { get { return Nodes != null && Nodes . Count > 0 && ! String . IsNullOrEmpty ( Nodes [ 0 ] . Path ) ; } }
47
37
public bool RequiresRepaint { get ; private set ; }
48
38
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
-
97
39
public Rect Render ( Rect containingRect , Rect rect , Vector2 scroll , Action < TNode > singleClick = null , Action < TNode > doubleClick = null , Action < TNode > rightClick = null )
98
40
{
99
41
controlId = GUIUtility . GetControlID ( FocusType . Keyboard ) ;
@@ -137,8 +79,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
137
79
var titleDisplay = ! ( rect . y > endDisplay || rect . yMax < startDisplay ) ;
138
80
if ( titleDisplay )
139
81
{
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 ) ;
142
83
}
143
84
144
85
if ( renderResult == TreeNodeRenderResult . VisibilityChange )
@@ -171,8 +112,7 @@ public Rect Render(Rect containingRect, Rect rect, Vector2 scroll, Action<TNode>
171
112
var display = ! ( rect . y > endDisplay || rect . yMax < startDisplay ) ;
172
113
if ( display )
173
114
{
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 ) ;
176
116
}
177
117
178
118
if ( renderResult == TreeNodeRenderResult . VisibilityChange )
@@ -266,7 +206,7 @@ private bool HandleInput(Rect rect, TNode currentNode, int index, Action<TNode>
266
206
}
267
207
268
208
// 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 )
270
210
{
271
211
int directionY = Event . current . keyCode == KeyCode . UpArrow ? - 1 : Event . current . keyCode == KeyCode . DownArrow ? 1 : 0 ;
272
212
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>
580
520
[ NonSerialized ] public Texture2D BranchIcon ;
581
521
[ NonSerialized ] public Texture2D FolderIcon ;
582
522
[ 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
+ }
583
573
584
574
public void UpdateIcons ( Texture2D activeBranchIcon , Texture2D branchIcon , Texture2D folderIcon , Texture2D globeIcon )
585
575
{
0 commit comments