void AddExpandedChildrenRecursively(TreeViewItem item, ExpandedMarkerIdHierarchy expandedHierarchy) { if (item.children == null) { return; } for (var i = 0; i < item.children.Count; ++i) { var childItem = item.children[i]; // Inlining !IsChildListForACollapsedParent without childList.Count == 1 check, as we only create list if we have children if (childItem.children != null && childItem.children[0] != null) { var subHierarchy = new ExpandedMarkerIdHierarchy(); if (expandedHierarchy.expandedMarkers == null) { expandedHierarchy.expandedMarkers = new Dictionary <int, ExpandedMarkerIdHierarchy>(); } try { expandedHierarchy.expandedMarkers.Add(m_FrameDataView.GetItemMarkerID(childItem.id), subHierarchy); } catch (ArgumentException) { } AddExpandedChildrenRecursively(childItem, subHierarchy); } } }
void MigrateSelectedState(bool expandIfNecessary) { if (m_SelectedItemMarkerIdPath == null && m_LegacySelectedItemMarkerNamePath == null) { return; } // Find view id which corresponds to markerPath var newSelectedId = m_FrameDataView.GetRootItemID(); bool selectedItemsPathIsExpanded = true; if (m_SelectedItemMarkerIdPath != null) { foreach (var marker in m_SelectedItemMarkerIdPath.Value.markerIds) { var childrenId = m_FrameDataView.GetItemChildren(newSelectedId); foreach (var childId in childrenId) { if (marker == m_FrameDataView.GetItemMarkerID(childId)) { // check if the parent is expanded if (!IsExpanded(newSelectedId)) { selectedItemsPathIsExpanded = false; } newSelectedId = childId; break; } } if (newSelectedId == 0) { break; } } } else if (m_LegacySelectedItemMarkerNamePath != null) { var markerIdPath = new List <int>(); var markerNames = m_LegacySelectedItemMarkerNamePath.Split('/'); foreach (var markerName in markerNames) { var childrenId = m_FrameDataView.GetItemChildren(newSelectedId); foreach (var childId in childrenId) { if (markerName == m_FrameDataView.GetItemFunctionName(childId)) { // check if the parent is expanded if (!IsExpanded(newSelectedId)) { selectedItemsPathIsExpanded = false; } newSelectedId = childId; markerIdPath.Add(m_FrameDataView.GetItemMarkerID(childId)); break; } } if (newSelectedId == 0) { break; } } m_SelectedItemMarkerIdPath = new FrameDataView.MarkerPath(markerIdPath); m_LegacySelectedItemMarkerNamePath = null; } var newSelection = (newSelectedId == 0) ? new List <int>() : new List <int>() { newSelectedId }; state.selectedIDs = newSelection; if (newSelectedId != 0 && isInitialized && (selectedItemsPathIsExpanded || expandIfNecessary)) { FrameItem(newSelectedId); } }