public void ExpandAllParents(BaseTreeNode treeNode) { while (treeNode.Parent != null) { ListView.Expand(treeNode.Parent); treeNode = treeNode.Parent; } }
public static void onCreateFolder(Object sender, ClickEventArgs e) { NlmTreeListView listView = e.ListView; // Calculate unique name in current level. IEnumerable <FolderTreeNode> folderNodes = listView.NodeControl.Query.FolderNodes; String folderName = "Folder"; Int32 index = 1; while (folderNodes.Any(x => x.Name == folderName + index.ToString("000"))) { index += 1; } folderName += index.ToString("000"); // Create folder node. FolderTreeNode folderTreeNode = new FolderTreeNode(folderName); // Get parent node. BaseTreeNode parentTreeNode = null; if (listView.SelectedObjects.Count > 0) { BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode; if (treeNode is FolderTreeNode) { parentTreeNode = treeNode; } if (treeNode is LayerTreeNode) { parentTreeNode = treeNode.Parent; } } // Add folder to listview, ensure is visible by expanding parents. listView.AddObject(folderTreeNode, parentTreeNode); if (parentTreeNode != null) { listView.Expand(parentTreeNode); } // Scroll to new item. Int32 parentIndex = listView.IndexOf(folderTreeNode); if (parentIndex != -1) { listView.EnsureVisible(parentIndex); } // Sort, select, and begin edit. listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending); listView.SelectedObjects = new List <Object> { folderTreeNode }; listView.EditModel(folderTreeNode); }
private static void onCreateLayer(Object sender, ClickEventArgs e, Boolean addSelection) { NlmTreeListView listView = e.ListView; listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.UnregisterNotification(); IILayer layer = MaxLayers.CreateLayer(true, addSelection); UIntPtr handle = MaxAnimatable.GetHandleByAnim(layer); LayerTreeNode layerTreeNode = new LayerTreeNode(handle, listView.NodeControl.HandleMap); // Get parent node. BaseTreeNode parentTreeNode = null; if (listView.SelectedObjects.Count > 0) { BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode; if (treeNode is FolderTreeNode) { parentTreeNode = treeNode; } if (treeNode is LayerTreeNode) { parentTreeNode = treeNode.Parent; } } // Add folder to listview, ensure is visible by expanding parents. listView.AddObject(layerTreeNode, parentTreeNode); if (parentTreeNode != null) { listView.Expand(parentTreeNode); } // Scroll to new item. Int32 parentIndex = listView.IndexOf(layerTreeNode); if (parentIndex != -1) { listView.EnsureVisible(parentIndex); } // Sort, select listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending); listView.SelectedObjects = new List <Object> { layerTreeNode }; // Focus on the listview to ensure text entry goes to the edit box, and begin edit. listView.Focus(); listView.EditModel(layerTreeNode); // Register notification. listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.RegisterNotification(); }
// Filtering does not take into consideration nodes that are not currently visible. // This ensures that all nodes are visible that match the search string. private void ExpandParentsOfMatchedChildren(String text) { HashSet <BaseTreeNode> NodesToExpand = new HashSet <BaseTreeNode>(); foreach (BaseTreeNode treeNode in ListView.Roots) { SearchChildrenAndExpandByName(treeNode, text, NodesToExpand); } if (NodesToExpand.Count > 0) { foreach (BaseTreeNode nodeToExpand in NodesToExpand.ToList <BaseTreeNode>()) { if (!ListView.IsExpanded(nodeToExpand)) { ListView.Expand(nodeToExpand); } } } }
// Move nodes to new parent after a drag drop operation. private void DragDropMoveNodes(BaseTreeNode target, IList dragNodes) { IList selection = ListView.SelectedObjects; ListView.BeginUpdate(); MaxEvents.NodeEvents.Unregister(); IEnumerable <BaseTreeNode> dragNodesEnum = dragNodes.Cast <BaseTreeNode>(); // Are layers or folders being dropped on layers? // If so, make the target the parent of the target. if (dragNodesEnum.All(x => x is LayerTreeNode) && target is LayerTreeNode || dragNodesEnum.All(x => x is FolderTreeNode) && target is LayerTreeNode) { target = target.Parent; } // Are objects being dropped on objects? // If so, make the target the parent of the target. if (dragNodesEnum.All(x => x is ObjectTreeNode) && target is ObjectTreeNode) { target = target.Parent; } // Do we move to the root or move under a treeNode? // If the target is null, we have to move to root. if (target != null && target is LayerTreeNode) { // Move the treenodes in the listView. NodeParentEngine.MoveTreeNodes(dragNodes.Cast <BaseTreeNode>().ToList(), target); //TODO: //IEnumerable<UIntPtr> handles = dragNodes.Cast<IEnumerable<BaseTreeNode>>() // .Where(x => x is ObjectTreeNode) // .Cast<ObjectTreeNode>() // .Select(x => x.Handle); // Move nodes to new layer in max. List <UIntPtr> handles = new List <UIntPtr>(); foreach (BaseTreeNode child in dragNodes) { ObjectTreeNode objectChild = child as ObjectTreeNode; if (objectChild != null) { handles.Add(objectChild.Handle); } } IILayer layer = MaxAnimatable.GetAnimByHandle(((LayerTreeNode)target).Handle) as IILayer; if (layer != null) { MaxNodes.MoveNodesToLayer(handles, layer); } } else { NodeParentEngine.MoveTreeNodes(dragNodes.Cast <BaseTreeNode>().ToList(), target); } MaxEvents.NodeEvents.Register(); // Default after drop behaviour tries to select nodes based on itemIndex. As nodes have moved this does not work. // Instead, return saved selection to SelectedObjects property, and make sure dropped Objects are visible. if (!ListView.IsExpanded(target)) { ListView.Expand(target); } ListView.Sort(ListView.NlmColumns.NameColumn, SortOrder.Ascending); ListView.SelectedObjects = selection; ListView.EndUpdate(); }