private void InsertOrdered(ProjectItem parent, ProjectItem item) { parent.AddChild(item); m_treeView.RemoveChild(parent, item, parent.Children.Count == 1); VirtualizingTreeViewItem treeViewItem = m_treeView.GetTreeViewItem(item); if (treeViewItem == null) { m_treeView.AddChild(parent, item); } ProjectItem[] orderedChildren = parent.Children.OrderBy(projectItem => projectItem.NameExt).ToArray(); int index = Array.IndexOf(orderedChildren, item); item.SetSiblingIndex(index); if (item.IsFolder) { if (index > 0) { object prevSibling = parent.Children[index - 1]; m_treeView.SetNextSibling(prevSibling, item); } else { if (parent.Children.Count > 1) { object nextSibling = parent.Children[1]; m_treeView.SetPrevSibling(nextSibling, item); } } } }
protected virtual void AddItem(ProjectItem parentFolder, ProjectItem folder, string[] existingNames, bool select, bool expand) { m_treeView.AddChild(parentFolder, folder); if (existingNames.Length > 0) { int index = Array.IndexOf(existingNames.Union(new[] { folder.Name }).OrderBy(n => n).ToArray(), folder.Name); if (index > 0) { m_treeView.SetNextSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index - 1), folder); } else { m_treeView.SetPrevSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index + 1), folder); } } if (expand) { ProjectItem projectItem = parentFolder; Expand(parentFolder); } if (select) { if (m_treeView.GetTreeViewItem(folder) != null) { m_treeView.ScrollIntoView(folder); } m_treeView.SelectedItem = folder; } }
private void AddItem(ProjectItem parentFolder, ProjectItem folder, string[] existingNames) { m_treeView.AddChild(parentFolder, folder); if (existingNames.Length > 0) { int index = Array.IndexOf(existingNames.Union(new[] { folder.Name }).OrderBy(n => n).ToArray(), folder.Name); if (index > 0) { m_treeView.SetNextSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index - 1), folder); } else { m_treeView.SetPrevSibling(parentFolder.Children.Where(c => c.IsFolder).OrderBy(c => c.Name).ElementAt(index + 1), folder); } } ProjectItem projectItem = parentFolder; Expand(parentFolder); m_treeView.ScrollIntoView(folder); m_treeView.SelectedItem = folder; VirtualizingTreeViewItem treeViewItem = m_treeView.GetTreeViewItem(folder); treeViewItem.IsEditing = true; }
private void AddSortedByName(ExposeToEditor obj) { string[] names = m_treeView.Items.OfType <ExposeToEditor>().Select(go => go.name).Union(new[] { obj.name }).OrderBy(k => k).ToArray(); int index = System.Array.IndexOf(names, obj.name); ExposeToEditor sibling; if (index == 0) { sibling = m_treeView.Items.OfType <ExposeToEditor>().FirstOrDefault(); m_treeView.Add(obj); if (sibling != null) { m_treeView.SetPrevSibling(sibling, obj); } } else { sibling = m_treeView.Items.OfType <ExposeToEditor>().ElementAt(index - 1); m_treeView.Add(obj); m_treeView.SetNextSibling(sibling, obj); } }