55using UnityEditor ;
66using UnityEditor . IMGUI . Controls ;
77using UnityEngine ;
8+ using System . Collections . Generic ;
89
910namespace UnityEditorInternal
1011{
@@ -14,6 +15,7 @@ internal class AddCurvesPopupHierarchyGUI : TreeViewGUI
1415 public bool showPlusButton { get ; set ; }
1516 private GUIStyle plusButtonStyle = "OL Plus" ;
1617 private GUIStyle plusButtonBackgroundStyle = "Tag MenuItem" ;
18+ private GUIContent addPropertiesContent = EditorGUIUtility . TrTextContent ( "Add Properties" ) ;
1719 private const float plusButtonWidth = 17 ;
1820
1921 public AddCurvesPopupHierarchyGUI ( TreeViewController treeView , EditorWindow owner )
@@ -25,7 +27,12 @@ public AddCurvesPopupHierarchyGUI(TreeViewController treeView, EditorWindow owne
2527 public override void OnRowGUI ( Rect rowRect , TreeViewItem node , int row , bool selected , bool focused )
2628 {
2729 base . OnRowGUI ( rowRect , node , row , selected , focused ) ;
30+ DoAddCurveButton ( rowRect , node ) ;
31+ HandleContextMenu ( rowRect , node ) ;
32+ }
2833
34+ private void DoAddCurveButton ( Rect rowRect , TreeViewItem node )
35+ {
2936 // Is it propertynode. If not, then we don't need plusButton so quit here
3037 AddCurvesPopupPropertyNode hierarchyNode = node as AddCurvesPopupPropertyNode ;
3138 if ( hierarchyNode == null || hierarchyNode . curveBindings == null || hierarchyNode . curveBindings . Length == 0 )
@@ -41,10 +48,85 @@ public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool sel
4148 if ( GUI . Button ( buttonRect , GUIContent . none , plusButtonStyle ) )
4249 {
4350 AddCurvesPopup . AddNewCurve ( hierarchyNode ) ;
44- owner . Close ( ) ;
51+
52+ // Hold shift key to add new curves and keep window opened.
53+ if ( Event . current . shift )
54+ m_TreeView . ReloadData ( ) ;
55+ else
56+ owner . Close ( ) ;
4557 }
4658 }
4759
60+ private void HandleContextMenu ( Rect rowRect , TreeViewItem node )
61+ {
62+ if ( Event . current . type != EventType . ContextClick )
63+ return ;
64+
65+ if ( rowRect . Contains ( Event . current . mousePosition ) )
66+ {
67+ // Add current node to selection
68+ var ids = new List < int > ( m_TreeView . GetSelection ( ) ) ;
69+ ids . Add ( node . id ) ;
70+ m_TreeView . SetSelection ( ids . ToArray ( ) , false , false ) ;
71+
72+ GenerateMenu ( ) . ShowAsContext ( ) ;
73+ Event . current . Use ( ) ;
74+ }
75+ }
76+
77+ private GenericMenu GenerateMenu ( )
78+ {
79+ GenericMenu menu = new GenericMenu ( ) ;
80+ menu . AddItem ( addPropertiesContent , false , AddPropertiesFromSelectedNodes ) ;
81+
82+ return menu ;
83+ }
84+
85+ private void AddPropertiesFromSelectedNodes ( )
86+ {
87+ int [ ] ids = m_TreeView . GetSelection ( ) ;
88+ for ( int i = 0 ; i < ids . Length ; ++ i )
89+ {
90+ var node = m_TreeView . FindItem ( ids [ i ] ) ;
91+ var propertyNode = node as AddCurvesPopupPropertyNode ;
92+
93+ if ( propertyNode != null )
94+ {
95+ AddCurvesPopup . AddNewCurve ( propertyNode ) ;
96+ }
97+ else if ( node . hasChildren )
98+ {
99+ foreach ( var childNode in node . children )
100+ {
101+ var childPropertyNode = childNode as AddCurvesPopupPropertyNode ;
102+ if ( childPropertyNode != null )
103+ {
104+ AddCurvesPopup . AddNewCurve ( childPropertyNode ) ;
105+ }
106+ }
107+ }
108+ }
109+
110+ m_TreeView . ReloadData ( ) ;
111+ }
112+
113+ public float GetContentWidth ( )
114+ {
115+ IList < TreeViewItem > rows = m_TreeView . data . GetRows ( ) ;
116+ List < TreeViewItem > allRows = new List < TreeViewItem > ( ) ;
117+ allRows . AddRange ( rows ) ;
118+
119+ for ( int i = 0 ; i < allRows . Count ; ++ i )
120+ {
121+ var row = allRows [ i ] ;
122+ if ( row . hasChildren )
123+ allRows . AddRange ( row . children ) ;
124+ }
125+
126+ float rowWidth = GetMaxWidth ( allRows ) ;
127+ return rowWidth + plusButtonWidth ;
128+ }
129+
48130 override protected void SyncFakeItem ( )
49131 {
50132 //base.SyncFakeItem();
0 commit comments