int GetInsertIndex(TreeNodeImpl owner, TreeNodeImpl impl, ITreeNodeGroup group) { var children = owner.Children; // At creation time, it's most likely inserted last, so check that position first. if (children.Count >= 1) { var lastData = children[children.Count - 1].Data; var lastGroup = lastData.TreeNodeGroup; if (lastGroup != null) { int x = Compare(impl.Data, lastData, group, lastGroup); if (x > 0) return children.Count; } } int lo = 0, hi = children.Count - 1; while (lo <= hi && hi != -1) { int i = (lo + hi) / 2; var otherData = children[i].Data; var otherGroup = otherData.TreeNodeGroup; int x; if (otherGroup == null) x = -1; else x = Compare(impl.Data, otherData, group, otherGroup); if (x == 0) return i; if (x < 0) hi = i - 1; else lo = i + 1; } return hi + 1; }
public TreeViewImpl(ITreeViewManager treeViewManager, IThemeManager themeManager, IImageManager imageManager, Guid guid, TreeViewOptions options) { this.guid = guid; this.treeViewManager = treeViewManager; this.imageManager = imageManager; this.treeViewListener = options.TreeViewListener; this.sharpTreeView = new SharpTreeView(); this.sharpTreeView.SelectionChanged += SharpTreeView_SelectionChanged; this.sharpTreeView.CanDragAndDrop = options.CanDragAndDrop; this.sharpTreeView.AllowDrop = options.AllowDrop; this.sharpTreeView.AllowDropOrder = options.AllowDrop; VirtualizingStackPanel.SetIsVirtualizing(this.sharpTreeView, options.IsVirtualizing); VirtualizingStackPanel.SetVirtualizationMode(this.sharpTreeView, options.VirtualizationMode); this.sharpTreeView.SelectionMode = options.SelectionMode; this.sharpTreeView.BorderThickness = new Thickness(0); this.sharpTreeView.ShowRoot = false; this.sharpTreeView.ShowLines = false; if (options.IsGridView) { this.sharpTreeView.ItemContainerStyle = (Style)Application.Current.FindResource(SharpGridView.ItemContainerStyleKey); this.sharpTreeView.Style = (Style)Application.Current.FindResource("SharpTreeViewGridViewStyle"); } else { // Clear the value set by the constructor. This is required or our style won't be used. this.sharpTreeView.ClearValue(ItemsControl.ItemContainerStyleProperty); this.sharpTreeView.Style = (Style)Application.Current.FindResource(typeof(SharpTreeView)); } this.sharpTreeView.GetPreviewInsideTextBackground = () => themeManager.Theme.GetColor(ColorType.SystemColorsHighlight).Background; this.sharpTreeView.GetPreviewInsideForeground = () => themeManager.Theme.GetColor(ColorType.SystemColorsHighlightText).Foreground; // Add the root at the end since Create() requires some stuff to have been initialized this.root = Create(options.RootNode ?? new TreeNodeDataImpl(new Guid(FileTVConstants.ROOT_NODE_GUID))); this.sharpTreeView.Root = this.root.Node; }
internal void AddSorted(TreeNodeImpl owner, TreeNodeImpl impl) { var group = impl.Data.TreeNodeGroup; if (group == null) owner.Children.Add(impl); else { int index = GetInsertIndex(owner, impl, group); owner.Children.Insert(index, impl); } }
TreeNodeImpl Create(ITreeNodeData data) { Debug.Assert(data.TreeNode == null); var impl = new TreeNodeImpl(this, data); if (treeViewListener != null) treeViewListener.OnEvent(this, new TreeViewListenerEventArgs(TreeViewListenerEvent.NodeCreated, impl)); data.Initialize(); if (!impl.LazyLoading) AddChildren(impl); return impl; }
internal void AddSorted(TreeNodeImpl owner, ITreeNode node) { if (node == null) throw new ArgumentNullException(); if (node.TreeView != this) throw new InvalidOperationException("You can only add a ITreeNode to a treeview that created it"); AddSorted(owner, (TreeNodeImpl)node); }
internal void AddChildren(TreeNodeImpl impl) { foreach (var data in impl.Data.CreateChildren()) AddSorted(impl, Create(data)); foreach (var creator in treeViewManager.GetCreators(impl.Data.Guid)) { var context = new TreeNodeDataCreatorContext(impl); foreach (var data in creator.Create(context)) AddSorted(impl, Create(data)); } }
public DnSpySharpTreeNode(TreeNodeImpl treeNodeImpl) { this.treeNodeImpl = treeNodeImpl; }
public TreeViewImpl(ITreeViewServiceImpl treeViewService, IThemeService themeService, IClassificationFormatMapService classificationFormatMapService, Guid guid, TreeViewOptions options) { Guid = guid; this.treeViewService = treeViewService; treeViewListener = options.TreeViewListener; classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(AppearanceCategoryConstants.UIMisc); classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged; foregroundBrushResourceKey = options.ForegroundBrushResourceKey ?? "TreeViewForeground"; sharpTreeView = new SharpTreeView(); sharpTreeView.SelectionChanged += SharpTreeView_SelectionChanged; sharpTreeView.CanDragAndDrop = options.CanDragAndDrop; sharpTreeView.AllowDrop = options.AllowDrop; sharpTreeView.AllowDropOrder = options.AllowDrop; VirtualizingStackPanel.SetIsVirtualizing(sharpTreeView, options.IsVirtualizing); VirtualizingStackPanel.SetVirtualizationMode(sharpTreeView, options.VirtualizationMode); sharpTreeView.SelectionMode = options.SelectionMode; sharpTreeView.BorderThickness = new Thickness(0); sharpTreeView.ShowRoot = false; sharpTreeView.ShowLines = false; if (options.IsGridView) { sharpTreeView.SetResourceReference(ItemsControl.ItemContainerStyleProperty, SharpGridView.ItemContainerStyleKey); sharpTreeView.SetResourceReference(FrameworkElement.StyleProperty, "SharpTreeViewGridViewStyle"); } else { // Clear the value set by the constructor. This is required or our style won't be used. sharpTreeView.ClearValue(ItemsControl.ItemContainerStyleProperty); sharpTreeView.SetResourceReference(FrameworkElement.StyleProperty, typeof(SharpTreeView)); } sharpTreeView.GetPreviewInsideTextBackground = () => themeService.Theme.GetColor(ColorType.SystemColorsHighlight).Background; sharpTreeView.GetPreviewInsideForeground = () => themeService.Theme.GetColor(ColorType.SystemColorsHighlightText).Foreground; // Add the root at the end since Create() requires some stuff to have been initialized root = Create(options.RootNode ?? new TreeNodeDataImpl(new Guid(DocumentTreeViewConstants.ROOT_NODE_GUID))); sharpTreeView.Root = root.Node; }
internal void AddChildren(TreeNodeImpl impl) { foreach (var data in impl.Data.CreateChildren()) AddSorted(impl, Create(data)); foreach (var provider in treeViewService.GetProviders(impl.Data.Guid)) { var context = new TreeNodeDataProviderContext(impl); foreach (var data in provider.Create(context)) AddSorted(impl, Create(data)); } }