EditorHierarchyWindow.as 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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"].GetUIElement();
  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. }
  607. void HandleDragDropTest(StringHash eventType, VariantMap& eventData)
  608. {
  609. UIElement@ source = eventData["Source"].GetUIElement();
  610. UIElement@ target = eventData["Target"].GetUIElement();
  611. int itemType;
  612. eventData["Accept"] = TestDragDrop(source, target, itemType);
  613. }
  614. void HandleDragDropFinish(StringHash eventType, VariantMap& eventData)
  615. {
  616. UIElement@ source = eventData["Source"].GetUIElement();
  617. UIElement@ target = eventData["Target"].GetUIElement();
  618. int itemType = ITEM_NONE;
  619. bool accept = TestDragDrop(source, target, itemType);
  620. eventData["Accept"] = accept;
  621. if (!accept)
  622. return;
  623. if (itemType == ITEM_NODE)
  624. {
  625. Node@ targetNode = editorScene.GetNode(target.vars[NODE_ID_VAR].GetUInt());
  626. // If target is null, parent to scene
  627. if (targetNode is null)
  628. targetNode = editorScene;
  629. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  630. if (sourceNodes.length > 0)
  631. {
  632. if (sourceNodes.length > 1)
  633. SceneChangeParent(sourceNodes[0], sourceNodes, targetNode);
  634. else
  635. SceneChangeParent(sourceNodes[0], targetNode);
  636. // Focus the node at its new position in the list which in turn should trigger a refresh in attribute inspector
  637. FocusNode(sourceNodes[0]);
  638. }
  639. }
  640. else if (itemType == ITEM_UI_ELEMENT)
  641. {
  642. UIElement@ sourceElement = GetUIElementByID(source.vars[UI_ELEMENT_ID_VAR].GetUInt());
  643. UIElement@ targetElement = GetUIElementByID(target.vars[UI_ELEMENT_ID_VAR].GetUInt());
  644. // If target is null, cannot proceed
  645. if (targetElement is null)
  646. return;
  647. // Perform the reparenting
  648. if (!UIElementChangeParent(sourceElement, targetElement))
  649. return;
  650. // Focus the element at its new position in the list which in turn should trigger a refresh in attribute inspector
  651. FocusUIElement(sourceElement);
  652. }
  653. else if (itemType == ITEM_COMPONENT)
  654. {
  655. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  656. Component@ targetComponent = editorScene.GetComponent(target.vars[COMPONENT_ID_VAR].GetUInt());
  657. if (targetComponent !is null && sourceNodes.length > 0)
  658. {
  659. // Drag node to StaticModelGroup to make it an instance
  660. StaticModelGroup@ smg = cast<StaticModelGroup>(targetComponent);
  661. if (smg !is null)
  662. {
  663. // Save undo action
  664. EditAttributeAction action;
  665. uint attrIndex = GetAttributeIndex(smg, "Instance Nodes");
  666. Variant oldIDs = smg.attributes[attrIndex];
  667. for (uint i = 0; i < sourceNodes.length; ++i)
  668. smg.AddInstanceNode(sourceNodes[i]);
  669. action.Define(smg, attrIndex, oldIDs);
  670. SaveEditAction(action);
  671. SetSceneModified();
  672. }
  673. // Drag a node to Constraint to make it the remote end of the constraint
  674. Constraint@ constraint = cast<Constraint>(targetComponent);
  675. RigidBody@ rigidBody = sourceNodes[0].GetComponent("RigidBody");
  676. if (constraint !is null && rigidBody !is null)
  677. {
  678. // Save undo action
  679. EditAttributeAction action;
  680. uint attrIndex = GetAttributeIndex(constraint, "Other Body NodeID");
  681. Variant oldID = constraint.attributes[attrIndex];
  682. constraint.otherBody = rigidBody;
  683. action.Define(constraint, attrIndex, oldID);
  684. SaveEditAction(action);
  685. SetSceneModified();
  686. }
  687. }
  688. }
  689. }
  690. Array<Node@> GetMultipleSourceNodes(UIElement@ source)
  691. {
  692. Array<Node@> nodeList;
  693. // Handle multiple selected children from a ListView
  694. if (source.parent !is null && source.parent.typeName == "HierarchyContainer")
  695. {
  696. ListView@ listView_ = cast<ListView>(source.parent.parent.parent);
  697. if (listView_ is null)
  698. return nodeList;
  699. for (uint i = 0; i < listView_.selectedItems.length; i++)
  700. {
  701. UIElement@ item_ = listView_.selectedItems[i];
  702. if (item_.vars[TYPE_VAR] == ITEM_NODE)
  703. {
  704. Node@ node = editorScene.GetNode(item_.vars[NODE_ID_VAR].GetUInt());
  705. if (node !is null)
  706. nodeList.Push(node);
  707. }
  708. }
  709. }
  710. else
  711. {
  712. Node@ node = editorScene.GetNode(source.vars[NODE_ID_VAR].GetUInt());
  713. if (node !is null)
  714. nodeList.Push(node);
  715. }
  716. return nodeList;
  717. }
  718. bool TestDragDrop(UIElement@ source, UIElement@ target, int& itemType)
  719. {
  720. int targetItemType = target.GetVar(TYPE_VAR).GetInt();
  721. if (targetItemType == ITEM_NODE)
  722. {
  723. Node@ sourceNode;
  724. Node@ targetNode;
  725. Variant variant = source.GetVar(NODE_ID_VAR);
  726. if (!variant.empty)
  727. sourceNode = editorScene.GetNode(variant.GetUInt());
  728. variant = target.GetVar(NODE_ID_VAR);
  729. if (!variant.empty)
  730. targetNode = editorScene.GetNode(variant.GetUInt());
  731. if (sourceNode !is null && targetNode !is null)
  732. {
  733. itemType = ITEM_NODE;
  734. if (sourceNode.parent is targetNode)
  735. return false;
  736. if (targetNode.parent is sourceNode)
  737. return false;
  738. }
  739. return true;
  740. }
  741. else if (targetItemType == ITEM_UI_ELEMENT)
  742. {
  743. UIElement@ sourceElement;
  744. UIElement@ targetElement;
  745. Variant variant = source.GetVar(UI_ELEMENT_ID_VAR);
  746. if (!variant.empty)
  747. sourceElement = GetUIElementByID(variant.GetUInt());
  748. variant = target.GetVar(UI_ELEMENT_ID_VAR);
  749. if (!variant.empty)
  750. targetElement = GetUIElementByID(variant.GetUInt());
  751. if (sourceElement !is null && targetElement !is null)
  752. {
  753. itemType = ITEM_UI_ELEMENT;
  754. if (sourceElement.parent is targetElement)
  755. return false;
  756. if (targetElement.parent is sourceElement)
  757. return false;
  758. }
  759. return true;
  760. }
  761. else if (targetItemType == ITEM_COMPONENT)
  762. {
  763. // Now only support dragging of nodes to StaticModelGroup or Constraint. Can be expanded to support others
  764. Node@ sourceNode;
  765. Component@ targetComponent;
  766. Variant variant = source.GetVar(NODE_ID_VAR);
  767. if (!variant.empty)
  768. sourceNode = editorScene.GetNode(variant.GetUInt());
  769. variant = target.GetVar(COMPONENT_ID_VAR);
  770. if (!variant.empty)
  771. targetComponent = editorScene.GetComponent(variant.GetUInt());
  772. itemType = ITEM_COMPONENT;
  773. if (sourceNode !is null && targetComponent !is null && (targetComponent.type == STATICMODELGROUP_TYPE || targetComponent.type == CONSTRAINT_TYPE))
  774. return true;
  775. else
  776. return false;
  777. }
  778. return true;
  779. }
  780. void FocusNode(Node@ node)
  781. {
  782. uint index = GetListIndex(node);
  783. hierarchyList.selection = index;
  784. }
  785. void FocusComponent(Component@ component)
  786. {
  787. uint index = GetComponentListIndex(component);
  788. hierarchyList.selection = index;
  789. }
  790. void FocusUIElement(UIElement@ element)
  791. {
  792. uint index = GetListIndex(element);
  793. hierarchyList.selection = index;
  794. }
  795. void CreateBuiltinObject(const String& name)
  796. {
  797. Node@ newNode = editorScene.CreateChild(name, REPLICATED);
  798. // Set the new node a certain distance from the camera
  799. newNode.position = GetNewNodePosition();
  800. StaticModel@ object = newNode.CreateComponent("StaticModel");
  801. object.model = cache.GetResource("Model", "Models/" + name + ".mdl");
  802. // Create an undo action for the create
  803. CreateNodeAction action;
  804. action.Define(newNode);
  805. SaveEditAction(action);
  806. SetSceneModified();
  807. FocusNode(newNode);
  808. }
  809. bool CheckHierarchyWindowFocus()
  810. {
  811. // When we do edit operations based on key shortcuts, make sure the hierarchy list is focused
  812. return ui.focusElement is hierarchyList || ui.focusElement is null;
  813. }
  814. bool CheckForExistingGlobalComponent(Node@ node, const String&in typeName)
  815. {
  816. if (typeName != "Octree" && typeName != "PhysicsWorld" && typeName != "DebugRenderer")
  817. return false;
  818. else
  819. return node.HasComponent(typeName);
  820. }
  821. void HandleNodeAdded(StringHash eventType, VariantMap& eventData)
  822. {
  823. if (suppressSceneChanges)
  824. return;
  825. Node@ node = eventData["Node"].GetNode();
  826. if (showTemporaryObject || !node.temporary)
  827. UpdateHierarchyItem(node);
  828. }
  829. void HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
  830. {
  831. if (suppressSceneChanges)
  832. return;
  833. Node@ node = eventData["Node"].GetNode();
  834. uint index = GetListIndex(node);
  835. UpdateHierarchyItem(index, null, null);
  836. }
  837. void HandleComponentAdded(StringHash eventType, VariantMap& eventData)
  838. {
  839. if (suppressSceneChanges)
  840. return;
  841. // Insert the newly added component at last component position but before the first child node position of the parent node
  842. Node@ node = eventData["Node"].GetNode();
  843. Component@ component = eventData["Component"].GetComponent();
  844. if (showTemporaryObject || !component.temporary)
  845. {
  846. uint nodeIndex = GetListIndex(node);
  847. if (nodeIndex != NO_ITEM)
  848. {
  849. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  850. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  851. }
  852. }
  853. }
  854. void HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
  855. {
  856. if (suppressSceneChanges)
  857. return;
  858. Component@ component = eventData["Component"].GetComponent();
  859. uint index = GetComponentListIndex(component);
  860. if (index != NO_ITEM)
  861. hierarchyList.RemoveItem(index);
  862. }
  863. void HandleNodeNameChanged(StringHash eventType, VariantMap& eventData)
  864. {
  865. if (suppressSceneChanges)
  866. return;
  867. Node@ node = eventData["Node"].GetNode();
  868. UpdateHierarchyItemText(GetListIndex(node), node.enabled, GetNodeTitle(node));
  869. }
  870. void HandleNodeEnabledChanged(StringHash eventType, VariantMap& eventData)
  871. {
  872. if (suppressSceneChanges)
  873. return;
  874. Node@ node = eventData["Node"].GetNode();
  875. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  876. attributesDirty = true;
  877. }
  878. void HandleComponentEnabledChanged(StringHash eventType, VariantMap& eventData)
  879. {
  880. if (suppressSceneChanges)
  881. return;
  882. Component@ component = eventData["Component"].GetComponent();
  883. UpdateHierarchyItemText(GetComponentListIndex(component), component.enabledEffective);
  884. attributesDirty = true;
  885. }
  886. void HandleUIElementAdded(StringHash eventType, VariantMap& eventData)
  887. {
  888. if (suppressUIElementChanges)
  889. return;
  890. UIElement@ element = eventData["Element"].GetUIElement();
  891. if ((showInternalUIElement || !element.internal) && (showTemporaryObject || !element.temporary))
  892. UpdateHierarchyItem(element);
  893. }
  894. void HandleUIElementRemoved(StringHash eventType, VariantMap& eventData)
  895. {
  896. if (suppressUIElementChanges)
  897. return;
  898. UIElement@ element = eventData["Element"].GetUIElement();
  899. UpdateHierarchyItem(GetListIndex(element), null, null);
  900. }
  901. void HandleElementNameChanged(StringHash eventType, VariantMap& eventData)
  902. {
  903. if (suppressUIElementChanges)
  904. return;
  905. UIElement@ element = eventData["Element"].GetUIElement();
  906. UpdateHierarchyItemText(GetListIndex(element), element.visible, GetUIElementTitle(element));
  907. }
  908. void HandleElementVisibilityChanged(StringHash eventType, VariantMap& eventData)
  909. {
  910. if (suppressUIElementChanges)
  911. return;
  912. UIElement@ element = eventData["Element"].GetUIElement();
  913. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  914. }
  915. void HandleElementAttributeChanged(StringHash eventType, VariantMap& eventData)
  916. {
  917. // Do not refresh the attribute inspector while the attribute is being edited via the attribute-editors
  918. if (suppressUIElementChanges || inEditAttribute)
  919. return;
  920. UIElement@ element = eventData["Element"].GetUIElement();
  921. for (uint i = 0; i < editUIElements.length; ++i)
  922. {
  923. if (editUIElements[i] is element)
  924. attributesDirty = true;
  925. }
  926. }
  927. void HandleTemporaryChanged(StringHash eventType, VariantMap& eventData)
  928. {
  929. if (suppressSceneChanges || suppressUIElementChanges)
  930. return;
  931. Serializable@ serializable = cast<Serializable>(GetEventSender());
  932. Node@ node = cast<Node>(serializable);
  933. if (node !is null && node.scene is editorScene)
  934. {
  935. if (showTemporaryObject)
  936. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  937. else if (!node.temporary && GetListIndex(node) == NO_ITEM)
  938. UpdateHierarchyItem(node);
  939. else if (node.temporary)
  940. UpdateHierarchyItem(GetListIndex(node), null, null);
  941. return;
  942. }
  943. Component@ component = cast<Component>(serializable);
  944. if (component !is null && component.node !is null && component.node.scene is editorScene)
  945. {
  946. if (showTemporaryObject)
  947. UpdateHierarchyItemText(GetComponentListIndex(component), node.enabled);
  948. else if (!component.temporary && GetComponentListIndex(component) == NO_ITEM)
  949. {
  950. uint nodeIndex = GetListIndex(node);
  951. if (nodeIndex != NO_ITEM)
  952. {
  953. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  954. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  955. }
  956. }
  957. else if (component.temporary)
  958. {
  959. uint index = GetComponentListIndex(component);
  960. if (index != NO_ITEM)
  961. hierarchyList.RemoveItem(index);
  962. }
  963. return;
  964. }
  965. UIElement@ element = cast<UIElement>(serializable);
  966. if (element !is null)
  967. {
  968. if (showTemporaryObject)
  969. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  970. else if (!element.temporary && GetListIndex(element) == NO_ITEM)
  971. UpdateHierarchyItem(element);
  972. else if (element.temporary)
  973. UpdateHierarchyItem(GetListIndex(element), null, null);
  974. return;
  975. }
  976. }
  977. // Hierarchy window edit functions
  978. bool Undo()
  979. {
  980. if (undoStackPos > 0)
  981. {
  982. --undoStackPos;
  983. // Undo commands in reverse order
  984. for (int i = int(undoStack[undoStackPos].actions.length - 1); i >= 0; --i)
  985. undoStack[undoStackPos].actions[i].Undo();
  986. }
  987. return true;
  988. }
  989. bool Redo()
  990. {
  991. if (undoStackPos < undoStack.length)
  992. {
  993. // Redo commands in same order as stored
  994. for (uint i = 0; i < undoStack[undoStackPos].actions.length; ++i)
  995. undoStack[undoStackPos].actions[i].Redo();
  996. ++undoStackPos;
  997. }
  998. return true;
  999. }
  1000. bool Cut()
  1001. {
  1002. if (CheckHierarchyWindowFocus())
  1003. {
  1004. bool ret = true;
  1005. if (!selectedNodes.empty || !selectedComponents.empty)
  1006. ret = ret && SceneCut();
  1007. // Not mutually exclusive
  1008. if (!selectedUIElements.empty)
  1009. ret = ret && UIElementCut();
  1010. return ret;
  1011. }
  1012. return false;
  1013. }
  1014. bool Copy()
  1015. {
  1016. if (CheckHierarchyWindowFocus())
  1017. {
  1018. bool ret = true;
  1019. if (!selectedNodes.empty || !selectedComponents.empty)
  1020. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneCopy() : false); // Node and component is mutually exclusive for copy action
  1021. // Not mutually exclusive
  1022. if (!selectedUIElements.empty)
  1023. ret = ret && UIElementCopy();
  1024. return ret;
  1025. }
  1026. return false;
  1027. }
  1028. bool Paste()
  1029. {
  1030. if (CheckHierarchyWindowFocus())
  1031. {
  1032. bool ret = true;
  1033. if (editNode !is null && !sceneCopyBuffer.empty)
  1034. ret = ret && ScenePaste();
  1035. // Not mutually exclusive
  1036. if (editUIElement !is null && !uiElementCopyBuffer.empty)
  1037. ret = ret && UIElementPaste();
  1038. return ret;
  1039. }
  1040. return false;
  1041. }
  1042. bool Delete()
  1043. {
  1044. if (CheckHierarchyWindowFocus())
  1045. {
  1046. bool ret = true;
  1047. if (!selectedNodes.empty || !selectedComponents.empty)
  1048. ret = ret && SceneDelete();
  1049. // Not mutually exclusive
  1050. if (!selectedUIElements.empty)
  1051. ret = ret && UIElementDelete();
  1052. return ret;
  1053. }
  1054. return false;
  1055. }
  1056. bool SelectAll()
  1057. {
  1058. if (CheckHierarchyWindowFocus())
  1059. {
  1060. if (!selectedNodes.empty || !selectedComponents.empty)
  1061. return SceneSelectAll();
  1062. else if (!selectedUIElements.empty || hierarchyList.items[GetListIndex(editorUIElement)].selected)
  1063. return UIElementSelectAll();
  1064. else
  1065. return SceneSelectAll(); // If nothing is selected yet, fall back to scene select all
  1066. }
  1067. return false;
  1068. }
  1069. bool ResetToDefault()
  1070. {
  1071. if (CheckHierarchyWindowFocus())
  1072. {
  1073. bool ret = true;
  1074. if (!selectedNodes.empty || !selectedComponents.empty)
  1075. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneResetToDefault() : false); // Node and component is mutually exclusive for reset-to-default action
  1076. // Not mutually exclusive
  1077. if (!selectedUIElements.empty)
  1078. ret = ret && UIElementResetToDefault();
  1079. return ret;
  1080. }
  1081. return false;
  1082. }
  1083. void ClearEditActions()
  1084. {
  1085. undoStack.Clear();
  1086. undoStackPos = 0;
  1087. }
  1088. void SaveEditAction(EditAction@ action)
  1089. {
  1090. // Create a group with 1 action
  1091. EditActionGroup group;
  1092. group.actions.Push(action);
  1093. SaveEditActionGroup(group);
  1094. }
  1095. void SaveEditActionGroup(EditActionGroup@ group)
  1096. {
  1097. if (group.actions.empty)
  1098. return;
  1099. // Truncate the stack first to current pos
  1100. undoStack.Resize(undoStackPos);
  1101. undoStack.Push(group);
  1102. ++undoStackPos;
  1103. // Limit maximum undo steps
  1104. if (undoStack.length > MAX_UNDOSTACK_SIZE)
  1105. {
  1106. undoStack.Erase(0);
  1107. --undoStackPos;
  1108. }
  1109. }
  1110. void BeginSelectionModify()
  1111. {
  1112. // A large operation on selected nodes is about to begin. Disable intermediate selection updates
  1113. inSelectionModify = true;
  1114. // Cursor shape reverts back to normal automatically after the large operation is completed
  1115. ui.cursor.shape = CS_BUSY;
  1116. }
  1117. void EndSelectionModify()
  1118. {
  1119. // The large operation on selected nodes has ended. Update node/component selection now
  1120. inSelectionModify = false;
  1121. HandleHierarchyListSelectionChange();
  1122. }