Exemplo n.º 1
0
        private static TreeListView.Node CreateNodeForPath(string path, bool directory)
        {
            var node = new TreeListView.Node {
                Label = Path.GetFileName(path)
            };

            if (directory)
            {
                node.Tag = new DirectoryInfo(path);
            }
            else
            {
                node.Tag = new FileInfo(path);
            }

            node.ImageIndex =
                directory
                    ? s_folderImageIndex
                    : s_dataImageIndex;

            // Whether the item has children. If it
            // has children the expander/collapser
            // icon will be drawn next to the item.
            node.IsLeaf =
                !directory
                    ? true
                    : (GetDirectoriesWrapper(path, "*.*", SearchOption.TopDirectoryOnly).Length <= 0) &&
                (GetFilesWrapper(path, "*.*", SearchOption.TopDirectoryOnly).Length <= 0);

            return(node);
        }
Exemplo n.º 2
0
        private static void EnumerateDirectory(TreeListView.Node node)
        {
            if (!(node.Tag is DirectoryInfo))
            {
                return;
            }

            var di = (DirectoryInfo)node.Tag;

            var directories =
                GetDirectoriesWrapper(
                    di.FullName,
                    "*.*",
                    SearchOption.TopDirectoryOnly);

            foreach (var directory in directories)
            {
                node.Nodes.Add(CreateNodeForPath(directory, true));
            }

            var files =
                GetFilesWrapper(
                    di.FullName,
                    "*.*",
                    SearchOption.TopDirectoryOnly);

            foreach (var file in files)
            {
                node.Nodes.Add(CreateNodeForPath(file, false));
            }
        }
Exemplo n.º 3
0
        private static void AddChildrenToItemRecursively(
            object item,
            TreeListView.Node node,
            ITreeListView view,
            IItemView itemView,
            ImageList imageList,
            ImageList stateImageList,
            IDictionary <object, TreeListView.Node> dictNodes)
        {
            if (view == null)
            {
                return;
            }

            IEnumerable <object> children = view.GetChildren(item);

            foreach (object child in children)
            {
                TreeListView.Node nodeChild = CreateNodeForObject(child, itemView, imageList, stateImageList, dictNodes);

                if (dictNodes != null)
                {
                    dictNodes.Add(child, nodeChild);
                }

                node.Nodes.Add(nodeChild);

                AddChildrenToItemRecursively(child, nodeChild, view, itemView, imageList, stateImageList, dictNodes);
            }
        }
Exemplo n.º 4
0
        private static TreeListView.Node CreateNodeForObject(
            object item,
            IItemView itemView,
            ImageList imageList,
            ImageList stateImageList,
            IDictionary <object, TreeListView.Node> dictNodes)
        {
            // Check for existing
            TreeListView.Node node;
            if (dictNodes.TryGetValue(item, out node))
            {
                return(node);
            }

            // Create new
            node = new TreeListView.Node();

            ItemInfo info =
                GetItemInfo(
                    item,
                    itemView,
                    imageList,
                    stateImageList);

            UpdateNodeFromItemInfo(node, item, info);

            return(node);
        }
Exemplo n.º 5
0
        private void AddItem(object item, object parent)
        {
            if (m_dictNodes.ContainsKey(item))
            {
                return;
            }

            TreeListView.Node nodeParent = null;
            if (parent != null)
            {
                m_dictNodes.TryGetValue(parent, out nodeParent);
            }

            TreeListView.Node node =
                CreateNodeForObject(
                    item,
                    m_itemView,
                    m_treeListView.ImageList,
                    m_treeListView.StateImageList,
                    m_dictNodes);

            bool expand = nodeParent != null && m_ExpandWhenNewChildAdded;

            m_dictNodes.Add(item, node);

            // Recursively add any children
            AddChildrenToItemRecursively(
                item,
                node,
                m_view,
                m_itemView,
                m_treeListView.ImageList,
                m_treeListView.StateImageList,
                m_dictNodes);

            TreeListView.NodeCollection collection =
                nodeParent == null
                    ? m_treeListView.Nodes
                    : nodeParent.Nodes;

            // Make sure collection can support having children
            if (collection.IsReadOnly && (collection.Owner != null))
            {
                collection.Owner.IsLeaf = false;
            }

            if (collection.IsReadOnly)
            {
                return;
            }

            // Add to tree
            collection.Add(node);

            if (expand)
            {
                nodeParent.Expanded = true;
            }
        }
Exemplo n.º 6
0
 public SledLuaWatchedCustomVariableRendererArgs(TreeListView control, TreeListView.Node node, Graphics gfx, Rectangle bounds, int column, ISledLuaVarBaseType luaVar, SledLuaWatchedCustomVariable customVar)
 {
     Control        = control;
     Node           = node;
     Graphics       = gfx;
     Bounds         = bounds;
     Column         = column;
     LuaVariable    = luaVar;
     CustomVariable = customVar;
     DrawDefault    = true;
 }
Exemplo n.º 7
0
 private static void UpdateNodeFromItemInfo(TreeListView.Node node, object item, ItemInfo info)
 {
     node.Label           = info.Label;
     node.Properties      = info.Properties;
     node.ImageIndex      = info.ImageIndex;
     node.StateImageIndex = info.StateImageIndex;
     node.CheckState      = info.GetCheckState();
     node.Tag             = item;
     node.IsLeaf          = info.IsLeaf;
     node.Expanded        = info.IsExpandedInView;
     node.FontStyle       = info.FontStyle;
     node.HoverText       = info.HoverText;
 }
Exemplo n.º 8
0
        private void TreeListViewRetrieveVirtualNode(object sender, TreeListView.RetrieveVirtualNodeEventArgs e)
        {
            var args = new RetrieveVirtualNodeAdapter(e.NodeIndex);

            RetrieveVirtualItem.Raise(this, args);

            if (args.Item == null)
            {
                return;
            }

            // Wrap user data
            TreeListView.Node node =
                CreateNodeForObject(
                    args.Item,
                    m_itemView,
                    m_treeListView.ImageList,
                    m_treeListView.StateImageList,
                    m_dictNodes);

            m_dictNodes[args.Item] = node;
            e.Node = node;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="item">The client's data</param>
 /// <param name="node">The corresponding node</param>
 public NodeAdapterEventArgs(object item, TreeListView.Node node)
 {
     Item = item;
     Node = node;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Get adapted user data at a point</summary>
 /// <param name="clientPoint">Point</param>
 /// <returns>User data or null if none</returns>
 public object GetItemAt(Point clientPoint)
 {
     TreeListView.Node node = TreeListView.GetNodeAt(clientPoint);
     return(node == null ? null : node.Tag);
 }
Exemplo n.º 11
0
        private void HandleSelectionUpdates()
        {
            if (m_selectionContext == null)
            {
                return;
            }

            object hitItem = LastHit;

            if ((hitItem == null) || (hitItem == this))
            {
                return;
            }

            TreeListView.Node hitNode;
            if (!m_dictNodes.TryGetValue(hitItem, out hitNode))
            {
                return;
            }

            HashSet <object> oldSelection = null;
            HashSet <object> newSelection = null;

            var handler = ItemSelected;

            if (handler != null)
            {
                oldSelection = new HashSet <object>(m_selectionContext.Selection);
            }

            switch (Control.ModifierKeys)
            {
            case Keys.Shift:
            {
                if (m_selectionStartItem != null)
                {
                    int idx1 = m_treeListView.GetNodeIndex(m_selectionStartItem);
                    int idx2 = m_treeListView.GetNodeIndex(hitNode);

                    int startIndex = Math.Min(idx1, idx2);
                    int endIndex   = Math.Max(idx1, idx2);

                    newSelection = new HashSet <object>();
                    for (int i = startIndex; i <= endIndex; i++)
                    {
                        TreeListView.Node item = m_treeListView.GetNodeAtIndex(i);
                        newSelection.Add(item.Tag);
                    }
                    m_selectionContext.SetRange(newSelection);
                }
                else
                {
                    m_selectionContext.Set(hitItem);
                    m_selectionStartItem = hitNode;
                }
            }
            break;

            case Keys.Control:
            {
                if (m_selectionContext.SelectionContains(hitItem))
                {
                    m_selectionContext.Remove(hitItem);
                }
                else
                {
                    m_selectionContext.Add(hitItem);
                }

                m_selectionStartItem = hitNode;
            }
            break;

            default:
            {
                m_selectionContext.Set(hitItem);
                m_selectionStartItem = hitNode;
            }
            break;
            }

            if (handler == null)
            {
                return;
            }

            if (newSelection == null)
            {
                newSelection = new HashSet <object>(m_selectionContext.Selection);
            }

            foreach (object removed in oldSelection.Except(newSelection))
            {
                TreeListView.Node node;
                if (!m_dictNodes.TryGetValue(removed, out node))
                {
                    continue;
                }

                ItemSelected.Raise(this, new NodeAdapterEventArgs(removed, node));
            }

            foreach (object added in newSelection.Except(oldSelection))
            {
                TreeListView.Node node;
                if (!m_dictNodes.TryGetValue(added, out node))
                {
                    continue;
                }

                ItemSelected.Raise(this, new NodeAdapterEventArgs(added, node));
            }
        }
Exemplo n.º 12
0
            public override void DrawLabel(TreeListView.Node node, Graphics gfx, Rectangle bounds, int column)
            {
                var text =
                    column == 0
                        ? node.Label
                        : ((node.Properties != null) &&
                           (node.Properties.Length >= column))
                            ? GetObjectString(node.Properties[column - 1])
                            : null;

                if (string.IsNullOrEmpty(text))
                {
                    text = string.Empty;
                }

                var editable = false;

                if (column == 2)
                {
                    var luaVar = node.Tag.As <ISledLuaVarBaseType>();
                    if (luaVar != null)
                    {
                        editable = SledLuaUtil.IsEditableLuaType(luaVar);
                    }
                }

                var flags = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix;

                // Add ellipsis if needed
                {
                    var textSize = TextRenderer.MeasureText(gfx, text, Owner.Control.Font);

                    if (textSize.Width > bounds.Width)
                    {
                        flags |= TextFormatFlags.EndEllipsis;
                    }
                }

                if (node.Selected && Owner.Control.Enabled)
                {
                    using (var b = new SolidBrush(Owner.HighlightBackColor))
                        gfx.FillRectangle(b, bounds);
                }

                var textColor =
                    node.Selected
                        ? Owner.HighlightTextColor
                        : Owner.TextColor;

                if (editable)
                {
                    textColor = node.Selected
                        ? Owner.ModifiableHighlightTextColor
                        : Owner.ModifiableTextColor;
                }

                if (!Owner.Control.Enabled)
                {
                    textColor = Owner.DisabledTextColor;
                }

                TextRenderer.DrawText(gfx, text, Owner.Control.Font, bounds, textColor, flags);
            }
Exemplo n.º 13
0
        private static TreeListView.Node CreateNodeForObject(
            object item,
            IItemView itemView,
            ImageList imageList,
            ImageList stateImageList,
            IDictionary<object, TreeListView.Node> dictNodes)
        {
            // Check for existing
            TreeListView.Node node;
            if (dictNodes.TryGetValue(item, out node))
                return node;

            // Create new
            node = new TreeListView.Node();

            ItemInfo info =
                GetItemInfo(
                    item,
                    itemView,
                    imageList,
                    stateImageList);

            UpdateNodeFromItemInfo(node, item, info);

            return node;
        }