Source/Fuse/Studio/MainWindow/Hierarchy/TreeViewModel.cs
/// <summary>
/// Walks through all expanded elements of tree, adding actions to updates for pending row updates.
/// Returns index of selected element
/// </summary>
Walks through all expanded elements of tree, adding actions to updates for pending row updates.
Returns index of selected element
Walks through all expanded elements of tree adding actions to updates for pending row updates . Returns index of selected element
static void ScanElementTree(
				TreeViewModel treeModel,
				ILiveElement element,
				Dictionary<ILiveElement, Action<RowModel>> updates,
				List<ILiveElement> allExpandedElements,
				int visibleRowCount,
				int visibleRowOffset,
				int depth,
				ILiveElement[] selectionPath,
				Optional<ILiveElement> previewElement,
				bool isAncestorSelected,
				ref Optional<int> selectedElementRowOffset,
				ref Optional<int> previewElementRowOffset)
			{
				var rowOffset = allExpandedElements.Count;
				allExpandedElements.Add(element);
				var canExpand = CanExpand(element, depth);
				var expandByDefault = depth < 2;
				var isDescendantSelected = depth < (selectionPath.Length - 1) && selectionPath[depth].Equals(element);
				var isSelected = depth == (selectionPath.Length - 1) && selectionPath[depth].Equals(element);
				var isExpanded = canExpand && (isDescendantSelected || treeModel.GetElementExpanded(element, expandByDefault));
				if (previewElement.Select(pe => pe == element).Or(false))
					previewElementRowOffset = rowOffset;
				if (isSelected)
				{
					selectedElementRowOffset = rowOffset;
				}
				var children = element.Children.Value;
				if (isExpanded)
				{
					foreach (var child in children)
					{
						ScanElementTree(
							treeModel: treeModel,
							element: child,
							updates: updates,
							allExpandedElements: allExpandedElements,
							visibleRowCount: visibleRowCount,
							visibleRowOffset: visibleRowOffset,
							depth: depth + 1,
							selectionPath: selectionPath,
							previewElement: previewElement,
							isAncestorSelected: isSelected | isAncestorSelected,
							selectedElementRowOffset: ref selectedElementRowOffset,
							previewElementRowOffset: ref previewElementRowOffset);
					}
				}
				var lastDescendantRowOffset = allExpandedElements.Count - 1;
				if ((rowOffset >= visibleRowOffset && rowOffset < visibleRowOffset + visibleRowCount) ||
					(rowOffset < visibleRowOffset && lastDescendantRowOffset >= visibleRowOffset))
				{
					updates[element] = rowModel => rowModel.Update(
						element: element,
						depth: depth,
						rowOffset: rowOffset,
						expandedDescendantCount: lastDescendantRowOffset - rowOffset,
						expandToggleEnabled: depth > 0 && canExpand, 
						isExpanded: isExpanded,
						isSelected: isSelected,
						isAncestorSelected: isAncestorSelected,
						isDescendantSelected: isDescendantSelected);
				}
			}
static void ScanElementTree ( TreeViewModel treeModel , ILiveElement element , Dictionary < ILiveElement , Action < RowModel > > updates , List < ILiveElement > allExpandedElements , int visibleRowCount , int visibleRowOffset , int depth , ILiveElement [ ] selectionPath , Optional < ILiveElement > previewElement , bool isAncestorSelected , ref Optional < int > selectedElementRowOffset , ref Optional < int > previewElementRowOffset ) { var rowOffset = allExpandedElements . Count ; allExpandedElements . Add ( element ) ; var canExpand = CanExpand ( element , depth ) ; var expandByDefault = depth < 2 ; var isDescendantSelected = depth < ( selectionPath . Length - 1 ) && selectionPath [ depth ] . Equals ( element ) ; var isSelected = depth == ( selectionPath . Length - 1 ) && selectionPath [ depth ] . Equals ( element ) ; var isExpanded = canExpand && ( isDescendantSelected || treeModel . GetElementExpanded ( element , expandByDefault ) ) ; if ( previewElement . Select ( pe => pe == element ) . Or ( false ) ) previewElementRowOffset = rowOffset ; if ( isSelected ) { selectedElementRowOffset = rowOffset ; } var children = element . Children . Value ; if ( isExpanded ) { foreach ( var child in children ) { ScanElementTree ( treeModel : treeModel , element : child , updates : updates , allExpandedElements : allExpandedElements , visibleRowCount : visibleRowCount , visibleRowOffset : visibleRowOffset , depth : depth + 1 , selectionPath : selectionPath , previewElement : previewElement , isAncestorSelected : isSelected | isAncestorSelected , selectedElementRowOffset : ref selectedElementRowOffset , previewElementRowOffset : ref previewElementRowOffset ) ; } } var lastDescendantRowOffset = allExpandedElements . Count - 1 ; if ( ( rowOffset >= visibleRowOffset && rowOffset < visibleRowOffset + visibleRowCount ) || ( rowOffset < visibleRowOffset && lastDescendantRowOffset >= visibleRowOffset ) ) { updates [ element ] = rowModel => rowModel . Update ( element : element , depth : depth , rowOffset : rowOffset , expandedDescendantCount : lastDescendantRowOffset - rowOffset , expandToggleEnabled : depth > 0 && canExpand , isExpanded : isExpanded , isSelected : isSelected , isAncestorSelected : isAncestorSelected , isDescendantSelected : isDescendantSelected ) ; } }
Walks through all expanded elements of tree, adding actions to updates for pending row updates.
Walks through all expanded elements of tree adding actions to updates for pending row updates .
// A node with children can expand, unless it has a "ux:Class" attribute // We expand up to 2 levels by default // Check if this element is an ancestor of selection // This is the selected element when we're at the end of the selection path // Don't allow collapse of root
treeModel
TreeViewModel
element
ILiveElement
updates
Dictionary<ILiveElement, Action<RowModel>>
allExpandedElements
List<ILiveElement>
visibleRowCount
int
visibleRowOffset
int
depth
int
selectionPath
ILiveElement[]
previewElement
Optional<ILiveElement>
isAncestorSelected
bool
Optional<int>
ref