Example #1
0
        private static void SetNodeText(TreeNode node, object item)
        {
            var id = string.Empty;

            var asMenuItem = item as MenuItem;

            if (asMenuItem != null)
            {
                id = asMenuItem.Id;
            }

            var asWidget = item as Widget;

            if (asWidget != null)
            {
                id = asWidget.Id;
            }

            var text = item.GetType().Name;
            var i    = text.IndexOf("`");

            if (i >= 0)
            {
                text = text.Remove(i);
            }

            if (!string.IsNullOrEmpty(id))
            {
                text += " (#" + id + ")";
            }

            node.Text = text;
        }
Example #2
0
        public TreeNode AddObject(TreeNode root, object item)
        {
            if (item == null)
            {
                return(null);
            }

            var node = root.AddSubNode(string.Empty);

            SetNodeText(node, item);
            node.Tag = item;

            return(node);
        }
Example #3
0
        private void Rebuild(TreeNode node, object item)
        {
            var asMenu = item as IMenuItemsContainer;

            if (asMenu != null)
            {
                foreach (var subItem in asMenu.Items)
                {
                    var subNode = AddObject(node, subItem);
                    Rebuild(subNode, subItem);
                }
            }
            else
            {
                IEnumerable <Widget> widgets = null;
                if (item is Window)
                {
                    widgets = new Widget[] { ((Window)item).Content };
                }
                else if (item is SplitPane)
                {
                    widgets = ((SplitPane)item).Widgets;
                }
                else if (item is MultipleItemsContainer && !(item is ListBox) && !(item is ComboBox) && !(item is SpinButton))
                {
                    var container = item as MultipleItemsContainer;
                    widgets = container.Children;
                }
                else if (item is ScrollPane)
                {
                    widgets = ((ScrollPane)item).Children;
                }

                if (widgets == null)
                {
                    return;
                }

                foreach (var child in widgets)
                {
                    var subNode = AddObject(node, child);
                    Rebuild(subNode, child);
                }
            }
        }
Example #4
0
        private TreeNode FindNodeByObject(TreeNode node, object item)
        {
            if (node.Tag == item)
            {
                return(node);
            }

            for (var i = 0; i < node.ChildNodesCount; ++i)
            {
                var result = FindNodeByObject(node.GetSubNode(i), item);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }