EditorHierarchyWindow.as 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. // Urho3D editor hierarchy window handling
  2. const int ITEM_NONE = 0;
  3. const int ITEM_NODE = 1;
  4. const int ITEM_COMPONENT = 2;
  5. const int ITEM_UI_ELEMENT = 3;
  6. const uint NO_ITEM = M_MAX_UNSIGNED;
  7. const ShortStringHash SCENE_TYPE("Scene");
  8. const ShortStringHash NODE_TYPE("Node");
  9. const ShortStringHash STATICMODELGROUP_TYPE("StaticModelGroup");
  10. const ShortStringHash CONSTRAINT_TYPE("Constraint");
  11. const String NO_CHANGE(uint8(0));
  12. const ShortStringHash TYPE_VAR("Type");
  13. const ShortStringHash NODE_ID_VAR("NodeID");
  14. const ShortStringHash COMPONENT_ID_VAR("ComponentID");
  15. const ShortStringHash UI_ELEMENT_ID_VAR("UIElementID");
  16. const ShortStringHash[] ID_VARS = { ShortStringHash(""), NODE_ID_VAR, COMPONENT_ID_VAR, UI_ELEMENT_ID_VAR };
  17. Color nodeTextColor(1.0f, 1.0f, 1.0f);
  18. Color componentTextColor(0.7f, 1.0f, 0.7f);
  19. Window@ hierarchyWindow;
  20. ListView@ hierarchyList;
  21. // UIElement does not have unique ID, so use a running number to generate a new ID each time an item is inserted into hierarchy list
  22. const uint UI_ELEMENT_BASE_ID = 1;
  23. uint uiElementNextID = UI_ELEMENT_BASE_ID;
  24. bool showInternalUIElement = false;
  25. bool showTemporaryObject = false;
  26. Array<uint> hierarchyUpdateSelections;
  27. Variant GetUIElementID(UIElement@ element)
  28. {
  29. Variant elementID = element.GetVar(UI_ELEMENT_ID_VAR);
  30. if (elementID.empty)
  31. {
  32. // Generate new ID
  33. elementID = uiElementNextID++;
  34. // Store the generated ID
  35. element.vars[UI_ELEMENT_ID_VAR] = elementID;
  36. }
  37. return elementID;
  38. }
  39. UIElement@ GetUIElementByID(const Variant&in id)
  40. {
  41. return id == UI_ELEMENT_BASE_ID ? editorUIElement : editorUIElement.GetChild(UI_ELEMENT_ID_VAR, id, true);
  42. }
  43. void CreateHierarchyWindow()
  44. {
  45. if (hierarchyWindow !is null)
  46. return;
  47. hierarchyWindow = ui.LoadLayout(cache.GetResource("XMLFile", "UI/EditorHierarchyWindow.xml"));
  48. hierarchyList = hierarchyWindow.GetChild("HierarchyList");
  49. ui.root.AddChild(hierarchyWindow);
  50. int height = Min(ui.root.height - 60, 500);
  51. hierarchyWindow.SetSize(300, height);
  52. hierarchyWindow.SetPosition(35, 100);
  53. hierarchyWindow.opacity = uiMaxOpacity;
  54. hierarchyWindow.BringToFront();
  55. UpdateHierarchyItem(editorScene);
  56. // Set drag & drop target mode on the node list background, which is used to parent nodes back to the root node
  57. hierarchyList.contentElement.dragDropMode = DD_TARGET;
  58. hierarchyList.scrollPanel.dragDropMode = DD_TARGET;
  59. SubscribeToEvent(hierarchyWindow.GetChild("CloseButton", true), "Released", "HideHierarchyWindow");
  60. SubscribeToEvent(hierarchyWindow.GetChild("ExpandButton", true), "Released", "ExpandCollapseHierarchy");
  61. SubscribeToEvent(hierarchyWindow.GetChild("CollapseButton", true), "Released", "ExpandCollapseHierarchy");
  62. SubscribeToEvent(hierarchyList, "SelectionChanged", "HandleHierarchyListSelectionChange");
  63. SubscribeToEvent("DragDropTest", "HandleDragDropTest");
  64. SubscribeToEvent("DragDropFinish", "HandleDragDropFinish");
  65. SubscribeToEvent(editorScene, "NodeAdded", "HandleNodeAdded");
  66. SubscribeToEvent(editorScene, "NodeRemoved", "HandleNodeRemoved");
  67. SubscribeToEvent(editorScene, "ComponentAdded", "HandleComponentAdded");
  68. SubscribeToEvent(editorScene, "ComponentRemoved", "HandleComponentRemoved");
  69. SubscribeToEvent(editorScene, "NodeNameChanged", "HandleNodeNameChanged");
  70. SubscribeToEvent(editorScene, "NodeEnabledChanged", "HandleNodeEnabledChanged");
  71. SubscribeToEvent(editorScene, "ComponentEnabledChanged", "HandleComponentEnabledChanged");
  72. SubscribeToEvent("TemporaryChanged", "HandleTemporaryChanged");
  73. }
  74. bool ShowHierarchyWindow()
  75. {
  76. hierarchyWindow.visible = true;
  77. hierarchyWindow.BringToFront();
  78. return true;
  79. }
  80. void HideHierarchyWindow()
  81. {
  82. hierarchyWindow.visible = false;
  83. }
  84. void ExpandCollapseHierarchy(StringHash eventType, VariantMap& eventData)
  85. {
  86. Button@ button = eventData["Element"].GetPtr();
  87. bool enable = button.name == "ExpandButton";
  88. CheckBox@ checkBox = hierarchyWindow.GetChild("AllCheckBox", true);
  89. bool all = checkBox.checked;
  90. checkBox.checked = false; // Auto-reset
  91. Array<uint> selections = hierarchyList.selections;
  92. for (uint i = 0; i < selections.length; ++i)
  93. hierarchyList.Expand(selections[i], enable, all);
  94. }
  95. void EnableExpandCollapseButtons(bool enable)
  96. {
  97. String[] buttons = { "ExpandButton", "CollapseButton", "AllCheckBox" };
  98. for (uint i = 0; i < buttons.length; ++i)
  99. {
  100. UIElement@ element = hierarchyWindow.GetChild(buttons[i], true);
  101. element.enabled = enable;
  102. element.children[0].color = enable ? normalTextColor : nonEditableTextColor;
  103. }
  104. }
  105. void UpdateHierarchyItem(Serializable@ serializable, bool clear = false)
  106. {
  107. if (clear)
  108. {
  109. // Remove the current selection before updating the list item (in turn trigger an update on the attribute editor)
  110. hierarchyList.ClearSelection();
  111. // Clear copybuffer when whole window refreshed
  112. sceneCopyBuffer.Clear();
  113. uiElementCopyBuffer.Clear();
  114. }
  115. // In case of item's parent is not found in the hierarchy list then the item will be inserted at the list root level
  116. Serializable@ parent;
  117. switch (GetType(serializable))
  118. {
  119. case ITEM_NODE:
  120. parent = cast<Node>(serializable).parent;
  121. break;
  122. case ITEM_COMPONENT:
  123. parent = cast<Component>(serializable).node;
  124. break;
  125. case ITEM_UI_ELEMENT:
  126. parent = cast<UIElement>(serializable).parent;
  127. break;
  128. default:
  129. break;
  130. }
  131. UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
  132. UpdateHierarchyItem(GetListIndex(serializable), serializable, parentItem);
  133. }
  134. uint UpdateHierarchyItem(uint itemIndex, Serializable@ serializable, UIElement@ parentItem)
  135. {
  136. // Whenever we're updating, disable layout update to optimize speed
  137. hierarchyList.contentElement.DisableLayoutUpdate();
  138. if (serializable is null)
  139. {
  140. hierarchyList.RemoveItem(itemIndex);
  141. hierarchyList.contentElement.EnableLayoutUpdate();
  142. hierarchyList.contentElement.UpdateLayout();
  143. return itemIndex;
  144. }
  145. int itemType = GetType(serializable);
  146. Variant id = GetID(serializable, itemType);
  147. // Remove old item if exists
  148. if (itemIndex < hierarchyList.numItems && MatchID(hierarchyList.items[itemIndex], id, itemType))
  149. hierarchyList.RemoveItem(itemIndex);
  150. Text@ text = Text();
  151. hierarchyList.InsertItem(itemIndex, text, parentItem);
  152. text.style = "FileSelectorListText";
  153. if (serializable.type == SCENE_TYPE || serializable is editorUIElement)
  154. // The root node (scene) and editor's root UIElement cannot be moved by drag and drop
  155. text.dragDropMode = DD_TARGET;
  156. else
  157. // Internal UIElement is not able to participate in drag and drop action
  158. text.dragDropMode = itemType == ITEM_UI_ELEMENT && cast<UIElement>(serializable).internal ? DD_DISABLED : DD_SOURCE_AND_TARGET;
  159. // Advance the index for the child items
  160. if (itemIndex == M_MAX_UNSIGNED)
  161. itemIndex = hierarchyList.numItems;
  162. else
  163. ++itemIndex;
  164. String iconType = serializable.typeName;
  165. if (serializable is editorUIElement)
  166. iconType = "Root" + iconType;
  167. IconizeUIElement(text, iconType);
  168. SetID(text, serializable, itemType);
  169. switch (itemType)
  170. {
  171. case ITEM_NODE:
  172. {
  173. Node@ node = cast<Node>(serializable);
  174. text.text = GetNodeTitle(node);
  175. text.color = nodeTextColor;
  176. SetIconEnabledColor(text, node.enabled);
  177. // Update components first
  178. for (uint i = 0; i < node.numComponents; ++i)
  179. {
  180. Component@ component = node.components[i];
  181. if (showTemporaryObject || !component.temporary)
  182. AddComponentItem(itemIndex++, component, text);
  183. }
  184. // Then update child nodes recursively
  185. for (uint i = 0; i < node.numChildren; ++i)
  186. {
  187. Node@ childNode = node.children[i];
  188. if (showTemporaryObject || !childNode.temporary)
  189. itemIndex = UpdateHierarchyItem(itemIndex, childNode, text);
  190. }
  191. break;
  192. }
  193. case ITEM_COMPONENT:
  194. {
  195. Component@ component = cast<Component>(serializable);
  196. text.text = GetComponentTitle(component);
  197. text.color = componentTextColor;
  198. SetIconEnabledColor(text, component.enabledEffective);
  199. break;
  200. }
  201. case ITEM_UI_ELEMENT:
  202. {
  203. UIElement@ element = cast<UIElement>(serializable);
  204. text.text = GetUIElementTitle(element);
  205. SetIconEnabledColor(text, element.visible);
  206. // Update child elements recursively
  207. for (uint i = 0; i < element.numChildren; ++i)
  208. {
  209. UIElement@ childElement = element.children[i];
  210. if ((showInternalUIElement || !childElement.internal) && (showTemporaryObject || !childElement.temporary))
  211. itemIndex = UpdateHierarchyItem(itemIndex, childElement, text);
  212. }
  213. break;
  214. }
  215. default:
  216. break;
  217. }
  218. // Re-enable layout update (and do manual layout) now
  219. hierarchyList.contentElement.EnableLayoutUpdate();
  220. hierarchyList.contentElement.UpdateLayout();
  221. return itemIndex;
  222. }
  223. void UpdateHierarchyItemText(uint itemIndex, bool iconEnabled, const String&in textTitle = NO_CHANGE)
  224. {
  225. Text@ text = hierarchyList.items[itemIndex];
  226. if (text is null)
  227. return;
  228. SetIconEnabledColor(text, iconEnabled);
  229. if (textTitle != NO_CHANGE)
  230. text.text = textTitle;
  231. }
  232. void AddComponentItem(uint compItemIndex, Component@ component, UIElement@ parentItem)
  233. {
  234. Text@ text = Text();
  235. hierarchyList.InsertItem(compItemIndex, text, parentItem);
  236. text.style = "FileSelectorListText";
  237. text.vars[TYPE_VAR] = ITEM_COMPONENT;
  238. text.vars[NODE_ID_VAR] = component.node.id;
  239. text.vars[COMPONENT_ID_VAR] = component.id;
  240. text.text = GetComponentTitle(component);
  241. text.color = componentTextColor;
  242. text.dragDropMode = DD_SOURCE_AND_TARGET;
  243. IconizeUIElement(text, component.typeName);
  244. SetIconEnabledColor(text, component.enabledEffective);
  245. }
  246. int GetType(Serializable@ serializable)
  247. {
  248. if (cast<Node>(serializable) !is null)
  249. return ITEM_NODE;
  250. else if (cast<Component>(serializable) !is null)
  251. return ITEM_COMPONENT;
  252. else if (cast<UIElement>(serializable) !is null)
  253. return ITEM_UI_ELEMENT;
  254. else
  255. return ITEM_NONE;
  256. }
  257. void SetID(Text@ text, Serializable@ serializable, int itemType = ITEM_NONE)
  258. {
  259. // If item type is not provided, auto detect it
  260. if (itemType == ITEM_NONE)
  261. itemType = GetType(serializable);
  262. text.vars[TYPE_VAR] = itemType;
  263. text.vars[ID_VARS[itemType]] = GetID(serializable, itemType);
  264. switch (itemType)
  265. {
  266. case ITEM_COMPONENT:
  267. text.vars[NODE_ID_VAR] = cast<Component>(serializable).node.id;
  268. break;
  269. case ITEM_UI_ELEMENT:
  270. // Subscribe to UI-element events
  271. SubscribeToEvent(serializable, "NameChanged", "HandleElementNameChanged");
  272. SubscribeToEvent(serializable, "VisibleChanged", "HandleElementVisibilityChanged");
  273. SubscribeToEvent(serializable, "Resized", "HandleElementAttributeChanged");
  274. SubscribeToEvent(serializable, "Positioned", "HandleElementAttributeChanged");
  275. break;
  276. default:
  277. break;
  278. }
  279. }
  280. uint GetID(Serializable@ serializable, int itemType = ITEM_NONE)
  281. {
  282. // If item type is not provided, auto detect it
  283. if (itemType == ITEM_NONE)
  284. itemType = GetType(serializable);
  285. switch (itemType)
  286. {
  287. case ITEM_NODE:
  288. return cast<Node>(serializable).id;
  289. case ITEM_COMPONENT:
  290. return cast<Component>(serializable).id;
  291. case ITEM_UI_ELEMENT:
  292. return GetUIElementID(cast<UIElement>(serializable)).GetUInt();
  293. }
  294. return M_MAX_UNSIGNED;
  295. }
  296. bool MatchID(UIElement@ element, const Variant&in id, int itemType)
  297. {
  298. return element.GetVar(TYPE_VAR).GetInt() == itemType && element.GetVar(ID_VARS[itemType]) == id;
  299. }
  300. uint GetListIndex(Serializable@ serializable)
  301. {
  302. if (serializable is null)
  303. return NO_ITEM;
  304. int itemType = GetType(serializable);
  305. Variant id = GetID(serializable, itemType);
  306. uint numItems = hierarchyList.numItems;
  307. for (uint i = 0; i < numItems; ++i)
  308. {
  309. if (MatchID(hierarchyList.items[i], id, itemType))
  310. return i;
  311. }
  312. return NO_ITEM;
  313. }
  314. UIElement@ GetListUIElement(uint index)
  315. {
  316. UIElement@ item = hierarchyList.items[index];
  317. if (item is null)
  318. return null;
  319. // Get the text item's ID and use it to retrieve the actual UIElement the text item is associated to
  320. return GetUIElementByID(GetUIElementID(item));
  321. }
  322. Node@ GetListNode(uint index)
  323. {
  324. UIElement@ item = hierarchyList.items[index];
  325. if (item is null)
  326. return null;
  327. return editorScene.GetNode(item.vars[NODE_ID_VAR].GetUInt());
  328. }
  329. Component@ GetListComponent(uint index)
  330. {
  331. UIElement@ item = hierarchyList.items[index];
  332. return GetListComponent(item);
  333. }
  334. Component@ GetListComponent(UIElement@ item)
  335. {
  336. if (item is null)
  337. return null;
  338. if (item.vars[TYPE_VAR].GetInt() != ITEM_COMPONENT)
  339. return null;
  340. return editorScene.GetComponent(item.vars[COMPONENT_ID_VAR].GetUInt());
  341. }
  342. uint GetComponentListIndex(Component@ component)
  343. {
  344. if (component is null)
  345. return NO_ITEM;
  346. uint numItems = hierarchyList.numItems;
  347. for (uint i = 0; i < numItems; ++i)
  348. {
  349. UIElement@ item = hierarchyList.items[i];
  350. if (item.vars[TYPE_VAR].GetInt() == ITEM_COMPONENT && item.vars[COMPONENT_ID_VAR].GetUInt() == component.id)
  351. return i;
  352. }
  353. return NO_ITEM;
  354. }
  355. String GetUIElementTitle(UIElement@ element)
  356. {
  357. String ret;
  358. // Only top level UI-element has this variable
  359. String modifiedStr = element.GetVar(MODIFIED_VAR).GetBool() ? "*" : "";
  360. ret = (element.name.empty ? element.typeName : element.name) + modifiedStr + " [" + GetUIElementID(element).ToString() + "]";
  361. if (element.temporary)
  362. ret += " (Temp)";
  363. return ret;
  364. }
  365. String GetNodeTitle(Node@ node)
  366. {
  367. String ret;
  368. if (node.name.empty)
  369. ret = node.typeName;
  370. else
  371. ret = node.name;
  372. if (node.id >= FIRST_LOCAL_ID)
  373. ret += " (Local " + String(node.id - FIRST_LOCAL_ID) + ")";
  374. else
  375. ret += " (" + String(node.id) + ")";
  376. if (node.temporary)
  377. ret += " (Temp)";
  378. return ret;
  379. }
  380. String GetComponentTitle(Component@ component)
  381. {
  382. String ret = component.typeName;
  383. if (component.id >= FIRST_LOCAL_ID)
  384. ret += " (Local)";
  385. if (component.temporary)
  386. ret += " (Temp)";
  387. return ret;
  388. }
  389. void SelectNode(Node@ node, bool multiselect)
  390. {
  391. if (node is null && !multiselect)
  392. {
  393. hierarchyList.ClearSelection();
  394. return;
  395. }
  396. uint index = GetListIndex(node);
  397. uint numItems = hierarchyList.numItems;
  398. if (index < numItems)
  399. {
  400. // Expand the node chain now
  401. if (!multiselect || !hierarchyList.IsSelected(index))
  402. {
  403. // Go in the parent chain up to make sure the chain is expanded
  404. Node@ current = node;
  405. do
  406. {
  407. hierarchyList.Expand(GetListIndex(current), true);
  408. current = current.parent;
  409. }
  410. while (current !is null);
  411. }
  412. // This causes an event to be sent, in response we set the node/component selections, and refresh editors
  413. if (!multiselect)
  414. hierarchyList.selection = index;
  415. else
  416. hierarchyList.ToggleSelection(index);
  417. }
  418. else if (!multiselect)
  419. hierarchyList.ClearSelection();
  420. }
  421. void SelectComponent(Component@ component, bool multiselect)
  422. {
  423. if (component is null && !multiselect)
  424. {
  425. hierarchyList.ClearSelection();
  426. return;
  427. }
  428. Node@ node = component.node;
  429. if (node is null && !multiselect)
  430. {
  431. hierarchyList.ClearSelection();
  432. return;
  433. }
  434. uint nodeIndex = GetListIndex(node);
  435. uint componentIndex = GetComponentListIndex(component);
  436. uint numItems = hierarchyList.numItems;
  437. if (nodeIndex < numItems && componentIndex < numItems)
  438. {
  439. // Expand the node chain now
  440. if (!multiselect || !hierarchyList.IsSelected(componentIndex))
  441. {
  442. // Go in the parent chain up to make sure the chain is expanded
  443. Node@ current = node;
  444. do
  445. {
  446. hierarchyList.Expand(GetListIndex(current), true);
  447. current = current.parent;
  448. }
  449. while (current !is null);
  450. }
  451. // This causes an event to be sent, in response we set the node/component selections, and refresh editors
  452. if (!multiselect)
  453. hierarchyList.selection = componentIndex;
  454. else
  455. hierarchyList.ToggleSelection(componentIndex);
  456. }
  457. else if (!multiselect)
  458. hierarchyList.ClearSelection();
  459. }
  460. void SelectUIElement(UIElement@ element, bool multiselect)
  461. {
  462. uint index = GetListIndex(element);
  463. uint numItems = hierarchyList.numItems;
  464. if (index < numItems)
  465. {
  466. // Expand the node chain now
  467. if (!multiselect || !hierarchyList.IsSelected(index))
  468. {
  469. // Go in the parent chain up to make sure the chain is expanded
  470. UIElement@ current = element;
  471. do
  472. {
  473. hierarchyList.Expand(GetListIndex(current), true);
  474. current = current.parent;
  475. }
  476. while (current !is null);
  477. }
  478. if (!multiselect)
  479. hierarchyList.selection = index;
  480. else
  481. hierarchyList.ToggleSelection(index);
  482. }
  483. else if (!multiselect)
  484. hierarchyList.ClearSelection();
  485. }
  486. void HandleHierarchyListSelectionChange()
  487. {
  488. if (inSelectionModify)
  489. return;
  490. ClearSceneSelection();
  491. ClearUIElementSelection();
  492. Array<uint> indices = hierarchyList.selections;
  493. // Enable Expand/Collapse button when there is selection
  494. EnableExpandCollapseButtons(indices.length > 0);
  495. for (uint i = 0; i < indices.length; ++i)
  496. {
  497. uint index = indices[i];
  498. UIElement@ item = hierarchyList.items[index];
  499. int type = item.vars[TYPE_VAR].GetInt();
  500. if (type == ITEM_COMPONENT)
  501. {
  502. Component@ comp = GetListComponent(index);
  503. if (comp !is null)
  504. selectedComponents.Push(comp);
  505. }
  506. else if (type == ITEM_NODE)
  507. {
  508. Node@ node = GetListNode(index);
  509. if (node !is null)
  510. selectedNodes.Push(node);
  511. }
  512. else if (type == ITEM_UI_ELEMENT)
  513. {
  514. UIElement@ element = GetListUIElement(index);
  515. if (element !is null && element !is editorUIElement)
  516. selectedUIElements.Push(element);
  517. }
  518. }
  519. // If only one node/UIElement selected, use it for editing
  520. if (selectedNodes.length == 1)
  521. editNode = selectedNodes[0];
  522. if (selectedUIElements.length == 1)
  523. editUIElement = selectedUIElements[0];
  524. // If selection contains only components, and they have a common node, use it for editing
  525. if (selectedNodes.empty && !selectedComponents.empty)
  526. {
  527. Node@ commonNode;
  528. for (uint i = 0; i < selectedComponents.length; ++i)
  529. {
  530. if (i == 0)
  531. commonNode = selectedComponents[i].node;
  532. else
  533. {
  534. if (selectedComponents[i].node !is commonNode)
  535. commonNode = null;
  536. }
  537. }
  538. editNode = commonNode;
  539. }
  540. // Now check if the component(s) can be edited. If many selected, must have same type or have same edit node
  541. if (!selectedComponents.empty)
  542. {
  543. if (editNode is null)
  544. {
  545. ShortStringHash compType = selectedComponents[0].type;
  546. bool sameType = true;
  547. for (uint i = 1; i < selectedComponents.length; ++i)
  548. {
  549. if (selectedComponents[i].type != compType)
  550. {
  551. sameType = false;
  552. break;
  553. }
  554. }
  555. if (sameType)
  556. editComponents = selectedComponents;
  557. }
  558. else
  559. {
  560. editComponents = selectedComponents;
  561. numEditableComponentsPerNode = selectedComponents.length;
  562. }
  563. }
  564. // If just nodes selected, and no components, show as many matching components for editing as possible
  565. if (!selectedNodes.empty && selectedComponents.empty && selectedNodes[0].numComponents > 0)
  566. {
  567. uint count = 0;
  568. for (uint j = 0; j < selectedNodes[0].numComponents; ++j)
  569. {
  570. ShortStringHash compType = selectedNodes[0].components[j].type;
  571. bool sameType = true;
  572. for (uint i = 1; i < selectedNodes.length; ++i)
  573. {
  574. if (selectedNodes[i].numComponents <= j || selectedNodes[i].components[j].type != compType)
  575. {
  576. sameType = false;
  577. break;
  578. }
  579. }
  580. if (sameType)
  581. {
  582. ++count;
  583. for (uint i = 0; i < selectedNodes.length; ++i)
  584. editComponents.Push(selectedNodes[i].components[j]);
  585. }
  586. }
  587. if (count > 1)
  588. numEditableComponentsPerNode = count;
  589. }
  590. if (selectedNodes.empty && editNode !is null)
  591. editNodes.Push(editNode);
  592. else
  593. {
  594. editNodes = selectedNodes;
  595. // Cannot multi-edit on scene and node(s) together as scene and node do not share identical attributes,
  596. // editing via gizmo does not make too much sense either
  597. if (editNodes.length > 1 && editNodes[0] is editorScene)
  598. editNodes.Erase(0);
  599. }
  600. if (selectedUIElements.empty && editUIElement !is null)
  601. editUIElements.Push(editUIElement);
  602. else
  603. editUIElements = selectedUIElements;
  604. PositionGizmo();
  605. UpdateAttributeInspector();
  606. UpdateCameraPreview();
  607. }
  608. void HandleDragDropTest(StringHash eventType, VariantMap& eventData)
  609. {
  610. UIElement@ source = eventData["Source"].GetPtr();
  611. UIElement@ target = eventData["Target"].GetPtr();
  612. int itemType;
  613. eventData["Accept"] = TestDragDrop(source, target, itemType);
  614. }
  615. void HandleDragDropFinish(StringHash eventType, VariantMap& eventData)
  616. {
  617. UIElement@ source = eventData["Source"].GetPtr();
  618. UIElement@ target = eventData["Target"].GetPtr();
  619. int itemType = ITEM_NONE;
  620. bool accept = TestDragDrop(source, target, itemType);
  621. eventData["Accept"] = accept;
  622. if (!accept)
  623. return;
  624. if (itemType == ITEM_NODE)
  625. {
  626. Node@ targetNode = editorScene.GetNode(target.vars[NODE_ID_VAR].GetUInt());
  627. // If target is null, parent to scene
  628. if (targetNode is null)
  629. targetNode = editorScene;
  630. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  631. if (sourceNodes.length > 0)
  632. {
  633. if (sourceNodes.length > 1)
  634. SceneChangeParent(sourceNodes[0], sourceNodes, targetNode);
  635. else
  636. SceneChangeParent(sourceNodes[0], targetNode);
  637. // Focus the node at its new position in the list which in turn should trigger a refresh in attribute inspector
  638. FocusNode(sourceNodes[0]);
  639. }
  640. }
  641. else if (itemType == ITEM_UI_ELEMENT)
  642. {
  643. UIElement@ sourceElement = GetUIElementByID(source.vars[UI_ELEMENT_ID_VAR].GetUInt());
  644. UIElement@ targetElement = GetUIElementByID(target.vars[UI_ELEMENT_ID_VAR].GetUInt());
  645. // If target is null, cannot proceed
  646. if (targetElement is null)
  647. return;
  648. // Perform the reparenting
  649. if (!UIElementChangeParent(sourceElement, targetElement))
  650. return;
  651. // Focus the element at its new position in the list which in turn should trigger a refresh in attribute inspector
  652. FocusUIElement(sourceElement);
  653. }
  654. else if (itemType == ITEM_COMPONENT)
  655. {
  656. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  657. Component@ targetComponent = editorScene.GetComponent(target.vars[COMPONENT_ID_VAR].GetUInt());
  658. if (targetComponent !is null && sourceNodes.length > 0)
  659. {
  660. // Drag node to StaticModelGroup to make it an instance
  661. StaticModelGroup@ smg = cast<StaticModelGroup>(targetComponent);
  662. if (smg !is null)
  663. {
  664. // Save undo action
  665. EditAttributeAction action;
  666. uint attrIndex = GetAttributeIndex(smg, "Instance Nodes");
  667. Variant oldIDs = smg.attributes[attrIndex];
  668. for (uint i = 0; i < sourceNodes.length; ++i)
  669. smg.AddInstanceNode(sourceNodes[i]);
  670. action.Define(smg, attrIndex, oldIDs);
  671. SaveEditAction(action);
  672. SetSceneModified();
  673. }
  674. // Drag a node to Constraint to make it the remote end of the constraint
  675. Constraint@ constraint = cast<Constraint>(targetComponent);
  676. RigidBody@ rigidBody = sourceNodes[0].GetComponent("RigidBody");
  677. if (constraint !is null && rigidBody !is null)
  678. {
  679. // Save undo action
  680. EditAttributeAction action;
  681. uint attrIndex = GetAttributeIndex(constraint, "Other Body NodeID");
  682. Variant oldID = constraint.attributes[attrIndex];
  683. constraint.otherBody = rigidBody;
  684. action.Define(constraint, attrIndex, oldID);
  685. SaveEditAction(action);
  686. SetSceneModified();
  687. }
  688. }
  689. }
  690. }
  691. Array<Node@> GetMultipleSourceNodes(UIElement@ source)
  692. {
  693. Array<Node@> nodeList;
  694. // Handle multiple selected children from a ListView
  695. if (source.parent !is null && source.parent.typeName == "HierarchyContainer")
  696. {
  697. ListView@ listView_ = cast<ListView>(source.parent.parent.parent);
  698. if (listView_ is null)
  699. return nodeList;
  700. for (uint i = 0; i < listView_.selectedItems.length; i++)
  701. {
  702. UIElement@ item_ = listView_.selectedItems[i];
  703. if (item_.vars[TYPE_VAR] == ITEM_NODE)
  704. {
  705. Node@ node = editorScene.GetNode(item_.vars[NODE_ID_VAR].GetUInt());
  706. if (node !is null)
  707. nodeList.Push(node);
  708. }
  709. }
  710. }
  711. else
  712. {
  713. Node@ node = editorScene.GetNode(source.vars[NODE_ID_VAR].GetUInt());
  714. if (node !is null)
  715. nodeList.Push(node);
  716. }
  717. return nodeList;
  718. }
  719. bool TestDragDrop(UIElement@ source, UIElement@ target, int& itemType)
  720. {
  721. int targetItemType = target.GetVar(TYPE_VAR).GetInt();
  722. if (targetItemType == ITEM_NODE)
  723. {
  724. Node@ sourceNode;
  725. Node@ targetNode;
  726. Variant variant = source.GetVar(NODE_ID_VAR);
  727. if (!variant.empty)
  728. sourceNode = editorScene.GetNode(variant.GetUInt());
  729. variant = target.GetVar(NODE_ID_VAR);
  730. if (!variant.empty)
  731. targetNode = editorScene.GetNode(variant.GetUInt());
  732. if (sourceNode !is null && targetNode !is null)
  733. {
  734. itemType = ITEM_NODE;
  735. if (sourceNode.parent is targetNode)
  736. return false;
  737. if (targetNode.parent is sourceNode)
  738. return false;
  739. }
  740. return true;
  741. }
  742. else if (targetItemType == ITEM_UI_ELEMENT)
  743. {
  744. UIElement@ sourceElement;
  745. UIElement@ targetElement;
  746. Variant variant = source.GetVar(UI_ELEMENT_ID_VAR);
  747. if (!variant.empty)
  748. sourceElement = GetUIElementByID(variant.GetUInt());
  749. variant = target.GetVar(UI_ELEMENT_ID_VAR);
  750. if (!variant.empty)
  751. targetElement = GetUIElementByID(variant.GetUInt());
  752. if (sourceElement !is null && targetElement !is null)
  753. {
  754. itemType = ITEM_UI_ELEMENT;
  755. if (sourceElement.parent is targetElement)
  756. return false;
  757. if (targetElement.parent is sourceElement)
  758. return false;
  759. }
  760. return true;
  761. }
  762. else if (targetItemType == ITEM_COMPONENT)
  763. {
  764. // Now only support dragging of nodes to StaticModelGroup or Constraint. Can be expanded to support others
  765. Node@ sourceNode;
  766. Component@ targetComponent;
  767. Variant variant = source.GetVar(NODE_ID_VAR);
  768. if (!variant.empty)
  769. sourceNode = editorScene.GetNode(variant.GetUInt());
  770. variant = target.GetVar(COMPONENT_ID_VAR);
  771. if (!variant.empty)
  772. targetComponent = editorScene.GetComponent(variant.GetUInt());
  773. itemType = ITEM_COMPONENT;
  774. if (sourceNode !is null && targetComponent !is null && (targetComponent.type == STATICMODELGROUP_TYPE || targetComponent.type == CONSTRAINT_TYPE))
  775. return true;
  776. else
  777. return false;
  778. }
  779. return true;
  780. }
  781. void FocusNode(Node@ node)
  782. {
  783. uint index = GetListIndex(node);
  784. hierarchyList.selection = index;
  785. }
  786. void FocusComponent(Component@ component)
  787. {
  788. uint index = GetComponentListIndex(component);
  789. hierarchyList.selection = index;
  790. }
  791. void FocusUIElement(UIElement@ element)
  792. {
  793. uint index = GetListIndex(element);
  794. hierarchyList.selection = index;
  795. }
  796. void CreateBuiltinObject(const String& name)
  797. {
  798. Node@ newNode = editorScene.CreateChild(name, REPLICATED);
  799. // Set the new node a certain distance from the camera
  800. newNode.position = GetNewNodePosition();
  801. StaticModel@ object = newNode.CreateComponent("StaticModel");
  802. object.model = cache.GetResource("Model", "Models/" + name + ".mdl");
  803. // Create an undo action for the create
  804. CreateNodeAction action;
  805. action.Define(newNode);
  806. SaveEditAction(action);
  807. SetSceneModified();
  808. FocusNode(newNode);
  809. }
  810. bool CheckHierarchyWindowFocus()
  811. {
  812. // When we do edit operations based on key shortcuts, make sure the hierarchy list is focused
  813. return ui.focusElement is hierarchyList || ui.focusElement is null;
  814. }
  815. bool CheckForExistingGlobalComponent(Node@ node, const String&in typeName)
  816. {
  817. if (typeName != "Octree" && typeName != "PhysicsWorld" && typeName != "DebugRenderer")
  818. return false;
  819. else
  820. return node.HasComponent(typeName);
  821. }
  822. void HandleNodeAdded(StringHash eventType, VariantMap& eventData)
  823. {
  824. if (suppressSceneChanges)
  825. return;
  826. Node@ node = eventData["Node"].GetPtr();
  827. if (showTemporaryObject || !node.temporary)
  828. UpdateHierarchyItem(node);
  829. }
  830. void HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
  831. {
  832. if (suppressSceneChanges)
  833. return;
  834. Node@ node = eventData["Node"].GetPtr();
  835. uint index = GetListIndex(node);
  836. UpdateHierarchyItem(index, null, null);
  837. }
  838. void HandleComponentAdded(StringHash eventType, VariantMap& eventData)
  839. {
  840. if (suppressSceneChanges)
  841. return;
  842. // Insert the newly added component at last component position but before the first child node position of the parent node
  843. Node@ node = eventData["Node"].GetPtr();
  844. Component@ component = eventData["Component"].GetPtr();
  845. if (showTemporaryObject || !component.temporary)
  846. {
  847. uint nodeIndex = GetListIndex(node);
  848. if (nodeIndex != NO_ITEM)
  849. {
  850. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  851. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  852. }
  853. }
  854. }
  855. void HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
  856. {
  857. if (suppressSceneChanges)
  858. return;
  859. Component@ component = eventData["Component"].GetPtr();
  860. uint index = GetComponentListIndex(component);
  861. if (index != NO_ITEM)
  862. hierarchyList.RemoveItem(index);
  863. }
  864. void HandleNodeNameChanged(StringHash eventType, VariantMap& eventData)
  865. {
  866. if (suppressSceneChanges)
  867. return;
  868. Node@ node = eventData["Node"].GetPtr();
  869. UpdateHierarchyItemText(GetListIndex(node), node.enabled, GetNodeTitle(node));
  870. }
  871. void HandleNodeEnabledChanged(StringHash eventType, VariantMap& eventData)
  872. {
  873. if (suppressSceneChanges)
  874. return;
  875. Node@ node = eventData["Node"].GetPtr();
  876. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  877. attributesDirty = true;
  878. }
  879. void HandleComponentEnabledChanged(StringHash eventType, VariantMap& eventData)
  880. {
  881. if (suppressSceneChanges)
  882. return;
  883. Component@ component = eventData["Component"].GetPtr();
  884. UpdateHierarchyItemText(GetComponentListIndex(component), component.enabledEffective);
  885. attributesDirty = true;
  886. }
  887. void HandleUIElementAdded(StringHash eventType, VariantMap& eventData)
  888. {
  889. if (suppressUIElementChanges)
  890. return;
  891. UIElement@ element = eventData["Element"].GetPtr();
  892. if ((showInternalUIElement || !element.internal) && (showTemporaryObject || !element.temporary))
  893. UpdateHierarchyItem(element);
  894. }
  895. void HandleUIElementRemoved(StringHash eventType, VariantMap& eventData)
  896. {
  897. if (suppressUIElementChanges)
  898. return;
  899. UIElement@ element = eventData["Element"].GetPtr();
  900. UpdateHierarchyItem(GetListIndex(element), null, null);
  901. }
  902. void HandleElementNameChanged(StringHash eventType, VariantMap& eventData)
  903. {
  904. if (suppressUIElementChanges)
  905. return;
  906. UIElement@ element = eventData["Element"].GetPtr();
  907. UpdateHierarchyItemText(GetListIndex(element), element.visible, GetUIElementTitle(element));
  908. }
  909. void HandleElementVisibilityChanged(StringHash eventType, VariantMap& eventData)
  910. {
  911. if (suppressUIElementChanges)
  912. return;
  913. UIElement@ element = eventData["Element"].GetPtr();
  914. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  915. }
  916. void HandleElementAttributeChanged(StringHash eventType, VariantMap& eventData)
  917. {
  918. // Do not refresh the attribute inspector while the attribute is being edited via the attribute-editors
  919. if (suppressUIElementChanges || inEditAttribute)
  920. return;
  921. UIElement@ element = eventData["Element"].GetPtr();
  922. for (uint i = 0; i < editUIElements.length; ++i)
  923. {
  924. if (editUIElements[i] is element)
  925. attributesDirty = true;
  926. }
  927. }
  928. void HandleTemporaryChanged(StringHash eventType, VariantMap& eventData)
  929. {
  930. if (suppressSceneChanges || suppressUIElementChanges)
  931. return;
  932. Serializable@ serializable = cast<Serializable>(GetEventSender());
  933. Node@ node = cast<Node>(serializable);
  934. if (node !is null && node.scene is editorScene)
  935. {
  936. if (showTemporaryObject)
  937. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  938. else if (!node.temporary && GetListIndex(node) == NO_ITEM)
  939. UpdateHierarchyItem(node);
  940. else if (node.temporary)
  941. UpdateHierarchyItem(GetListIndex(node), null, null);
  942. return;
  943. }
  944. Component@ component = cast<Component>(serializable);
  945. if (component !is null && component.node !is null && component.node.scene is editorScene)
  946. {
  947. if (showTemporaryObject)
  948. UpdateHierarchyItemText(GetComponentListIndex(component), node.enabled);
  949. else if (!component.temporary && GetComponentListIndex(component) == NO_ITEM)
  950. {
  951. uint nodeIndex = GetListIndex(node);
  952. if (nodeIndex != NO_ITEM)
  953. {
  954. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  955. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  956. }
  957. }
  958. else if (component.temporary)
  959. {
  960. uint index = GetComponentListIndex(component);
  961. if (index != NO_ITEM)
  962. hierarchyList.RemoveItem(index);
  963. }
  964. return;
  965. }
  966. UIElement@ element = cast<UIElement>(serializable);
  967. if (element !is null)
  968. {
  969. if (showTemporaryObject)
  970. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  971. else if (!element.temporary && GetListIndex(element) == NO_ITEM)
  972. UpdateHierarchyItem(element);
  973. else if (element.temporary)
  974. UpdateHierarchyItem(GetListIndex(element), null, null);
  975. return;
  976. }
  977. }
  978. // Hierarchy window edit functions
  979. bool Undo()
  980. {
  981. if (undoStackPos > 0)
  982. {
  983. --undoStackPos;
  984. // Undo commands in reverse order
  985. for (int i = int(undoStack[undoStackPos].actions.length - 1); i >= 0; --i)
  986. undoStack[undoStackPos].actions[i].Undo();
  987. }
  988. return true;
  989. }
  990. bool Redo()
  991. {
  992. if (undoStackPos < undoStack.length)
  993. {
  994. // Redo commands in same order as stored
  995. for (uint i = 0; i < undoStack[undoStackPos].actions.length; ++i)
  996. undoStack[undoStackPos].actions[i].Redo();
  997. ++undoStackPos;
  998. }
  999. return true;
  1000. }
  1001. bool Cut()
  1002. {
  1003. if (CheckHierarchyWindowFocus())
  1004. {
  1005. bool ret = true;
  1006. if (!selectedNodes.empty || !selectedComponents.empty)
  1007. ret = ret && SceneCut();
  1008. // Not mutually exclusive
  1009. if (!selectedUIElements.empty)
  1010. ret = ret && UIElementCut();
  1011. return ret;
  1012. }
  1013. return false;
  1014. }
  1015. bool Copy()
  1016. {
  1017. if (CheckHierarchyWindowFocus())
  1018. {
  1019. bool ret = true;
  1020. if (!selectedNodes.empty || !selectedComponents.empty)
  1021. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneCopy() : false); // Node and component is mutually exclusive for copy action
  1022. // Not mutually exclusive
  1023. if (!selectedUIElements.empty)
  1024. ret = ret && UIElementCopy();
  1025. return ret;
  1026. }
  1027. return false;
  1028. }
  1029. bool Paste()
  1030. {
  1031. if (CheckHierarchyWindowFocus())
  1032. {
  1033. bool ret = true;
  1034. if (editNode !is null && !sceneCopyBuffer.empty)
  1035. ret = ret && ScenePaste();
  1036. // Not mutually exclusive
  1037. if (editUIElement !is null && !uiElementCopyBuffer.empty)
  1038. ret = ret && UIElementPaste();
  1039. return ret;
  1040. }
  1041. return false;
  1042. }
  1043. bool Delete()
  1044. {
  1045. if (CheckHierarchyWindowFocus())
  1046. {
  1047. bool ret = true;
  1048. if (!selectedNodes.empty || !selectedComponents.empty)
  1049. ret = ret && SceneDelete();
  1050. // Not mutually exclusive
  1051. if (!selectedUIElements.empty)
  1052. ret = ret && UIElementDelete();
  1053. return ret;
  1054. }
  1055. return false;
  1056. }
  1057. bool SelectAll()
  1058. {
  1059. if (CheckHierarchyWindowFocus())
  1060. {
  1061. if (!selectedNodes.empty || !selectedComponents.empty)
  1062. return SceneSelectAll();
  1063. else if (!selectedUIElements.empty || hierarchyList.items[GetListIndex(editorUIElement)].selected)
  1064. return UIElementSelectAll();
  1065. else
  1066. return SceneSelectAll(); // If nothing is selected yet, fall back to scene select all
  1067. }
  1068. return false;
  1069. }
  1070. bool ResetToDefault()
  1071. {
  1072. if (CheckHierarchyWindowFocus())
  1073. {
  1074. bool ret = true;
  1075. if (!selectedNodes.empty || !selectedComponents.empty)
  1076. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneResetToDefault() : false); // Node and component is mutually exclusive for reset-to-default action
  1077. // Not mutually exclusive
  1078. if (!selectedUIElements.empty)
  1079. ret = ret && UIElementResetToDefault();
  1080. return ret;
  1081. }
  1082. return false;
  1083. }
  1084. void ClearEditActions()
  1085. {
  1086. undoStack.Clear();
  1087. undoStackPos = 0;
  1088. }
  1089. void SaveEditAction(EditAction@ action)
  1090. {
  1091. // Create a group with 1 action
  1092. EditActionGroup group;
  1093. group.actions.Push(action);
  1094. SaveEditActionGroup(group);
  1095. }
  1096. void SaveEditActionGroup(EditActionGroup@ group)
  1097. {
  1098. if (group.actions.empty)
  1099. return;
  1100. // Truncate the stack first to current pos
  1101. undoStack.Resize(undoStackPos);
  1102. undoStack.Push(group);
  1103. ++undoStackPos;
  1104. // Limit maximum undo steps
  1105. if (undoStack.length > MAX_UNDOSTACK_SIZE)
  1106. {
  1107. undoStack.Erase(0);
  1108. --undoStackPos;
  1109. }
  1110. }
  1111. void BeginSelectionModify()
  1112. {
  1113. // A large operation on selected nodes is about to begin. Disable intermediate selection updates
  1114. inSelectionModify = true;
  1115. // Cursor shape reverts back to normal automatically after the large operation is completed
  1116. ui.cursor.shape = CS_BUSY;
  1117. }
  1118. void EndSelectionModify()
  1119. {
  1120. // The large operation on selected nodes has ended. Update node/component selection now
  1121. inSelectionModify = false;
  1122. HandleHierarchyListSelectionChange();
  1123. }