@@ -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