Beispiel #1
0
        /// <summary>
        /// 可选择项选中后,
        /// 判断是否需要继续选择,或者是触发事件
        /// </summary>
        /// <param name="key"></param>
        private void OnBodySelect(int key)
        {
            //最底层的选择逻辑
            if ((active.childern == null || active.childern.Length == 0) && active.ParentItem != null)
            {
                active = active.ParentItem;
            }

            var child = active.GetChildItem(key);

            if (child != null)
            {
                //激活当前节点
                active = child;

                if (child.childern != null && child.childern.Length > 0)
                {
                    //更新选择列表
                    ChargeBodyOption(active);
                }
                else
                {
                    Debug.Assert(active != null, "active :Null", gameObject);
                    OnSelectionChanged(child.FullPath);
                }

                //更新标头列表
                UpdateCurrentSelectFromActiveNode(active);
            }
        }
Beispiel #2
0
 public override void SetSelect(params string[] path)
 {
     ClearTree();
     OnHeadSelect(0);
     Tree.TreeNode node = rootNode;
     for (int i = 0; i < path.Length; i++)
     {
         if (node.childern != null)
         {
             var child = node.GetChildItem(path[i]);
             if (child != null)
             {
                 var index = System.Array.IndexOf(node.childern, (child));
                 creater.SetSelect(index, true);
                 node = node.childern[i];
             }
             else
             {
                 break;
             }
         }
         else
         {
             break;
         }
     }
 }
Beispiel #3
0
 public override void CreateTree(Tree.TreeNode nodeBase)
 {
     base.CreateTree(nodeBase);
     active = nodeBase;
     ClearTree();
     OnHeadSelect(0);
 }
Beispiel #4
0
            public static Tree.TreeNode AddToTree(Tree.TreeNode node, int val)
            {
                if (val < node.Value)
                {
                    if (node.Left == null)
                    {
                        node.Left = new Tree.TreeNode()
                        {
                            Value = val
                        }
                    }
                    ;

                    return(node.Left);
                }
                else
                {
                    node.Right = new Tree.TreeNode()
                    {
                        Value = val
                    };

                    return(node.Right);
                }
            }
Beispiel #5
0
 /// <summary>
 /// 创建当前可选择的列表
 /// </summary>
 /// <param name="node"></param>
 private void ChargeBodyOption(Tree.TreeNode node)
 {
     if (node.childern != null && node.childern.Length > 0)
     {
         string[] selectItems = node.childern.Select(x => x.name).ToArray();
         creater.options = selectItems;
     }
 }
Beispiel #6
0
 public void BackOneSelect()
 {
     if (active.ParentItem != null)
     {
         active = active.ParentItem;
         //更新选择列表
         ChargeBodyOption(active);
         UpdateCurrentSelectFromActiveNode(active);
     }
 }
 private void FillItemsTree()
 {
    this.layoutTree.Nodes.Clear();
    foreach (TreeNodeLayoutItem item in this.layout.LayoutItems)
    {
       Tree.TreeNode tn = new Tree.TreeNode(GetItemName(item));
       tn.Tag = item;
       this.layoutTree.Nodes.Add(tn);
    }
 }
Beispiel #8
0
 public override void AutoSelectFirst()
 {
     ClearTree();
     OnHeadSelect(0);
     Tree.TreeNode node = rootNode;
     while (node.childern != null && node.childern.Length > 0)
     {
         node = node.childern[0];
         creater.SetSelect(0, true);
     }
 }
Beispiel #9
0
        public void OnHeadSelect(int dp)
        {
            active = rootNode;
            for (int i = 0; i < dp; i++)
            {
                var key = currentSelection[i];
                active = System.Array.Find(active.childern, x => x.name == key);
            }

            //更新选择列表
            ChargeBodyOption(active);
            //更新view
            UpdateCurrentSelectFromActiveNode(active);
        }
   private void AddSorterToTree(NodeSorter sorter, Tree.TreeNodeCollection parentCollection)
   {
      if (sorter == null)
         return;

      Tree.TreeNode tn = new Tree.TreeNode(this.GetSorterName(sorter));
      tn.Tag = sorter;
      tn.IsExpanded = true;

      this.treeNodes.Add(sorter, tn);

      parentCollection.Add(tn);
      this.AddSorterToTree(sorter.SecondarySorter, parentCollection);
   }
Beispiel #11
0
        /// <summary>
        /// Parse the tree in Project Euler's format
        /// return tuple of Root Node and Leaf Nodes (for solving problem)
        /// </summary>
        /// <param name="treeText"></param>
        /// <returns></returns>
        public static Tuple<TreeNode<int>, List<TreeNode<int>>> Parse(string input)
        {
            var row = 0;
            var lastRow = new List<Tree.TreeNode<int>>();
            Tree.TreeNode<int> root = null;
            foreach (var line in input.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                var thisRow = new List<Tree.TreeNode<int>>();
                var numbers = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var number in numbers)
                {
                    Tree.TreeNode<int> node = new Tree.TreeNode<int>();
                    node.Value = int.Parse(number);
                    thisRow.Add(node);

                    if (root == null)
                    {
                        root = node;
                    }
                }

                // build tree structure
                for (int i = 0; i < lastRow.Count; i++)
                {
                    lastRow[i].Left = thisRow[i];
                    lastRow[i].Right = thisRow[i + 1];
                }

                lastRow = thisRow;

                row++;
            }

            #region Checking that we build tree correctly

            //var serialized = input.Replace("\r\n", "").Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            //var allNumbers = (from number in serialized
            //               select int.Parse(number)).ToList();

            //var allFromTree = root.Discover().ToArray();
            //var check = allNumbers.Zip(allFromTree, (num, node) => num == node.Value).All(b => b);
            //Assert.IsTrue(check, "Some number missing");

            #endregion

            return new Tuple<TreeNode<int>, List<TreeNode<int>>>(root, lastRow);
        }
Beispiel #12
0
        public override void SetSelect(params int[] path)
        {
            ClearTree();
            OnHeadSelect(0);

            Tree.TreeNode node = rootNode;
            for (int i = 0; i < path.Length; i++)
            {
                if (node.childern != null && node.childern.Length > path[i])
                {
                    creater.SetSelect(path[i], true);
                    node = node.childern[i];
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #13
0
            public static bool LeftCheck(Tree.TreeNode node, int max)
            {
                if (node == null)
                {
                    return(true);
                }

                if (node.Left != null && node.Left.Value > max)
                {
                    return(false);
                }

                if (node.Right != null && node.Right.Value > max)
                {
                    return(false);
                }

                var rightResult = node.Right == null ? true : LeftCheck(node.Right, node.Value);
                var leftResult  = node.Left == null ? true : LeftCheck(node.Left, node.Value);

                return(leftResult && rightResult);
            }
   private void AddFilterToTree(Filter<IMaxNode> filter, Tree.TreeNodeCollection parentCollection)
   {
      filter.FilterChanged += filterChanged;

      Tree.TreeNode tn = new Tree.TreeNode();
      tn.Text = GetTreeNodeText(filter, tn);
      tn.Tag = filter;

      this.treeNodes.Add(filter, tn);

      FilterCombinator<IMaxNode> combinator = filter as FilterCombinator<IMaxNode>;
      if (combinator != null)
      {
         foreach (Filter<IMaxNode> child in combinator.Filters)
         {
            this.AddFilterToTree(child, tn.Nodes);
         }
         combinator.Filters.FilterAdded += this.filterAdded;
         combinator.Filters.FilterRemoved += this.filterRemoved;
         tn.DragDropHandler = new FilterCombinatorDragDropHandler(combinator);
      }
      else
         tn.DragDropHandler = new FilterDragDropHandler(filter);

      parentCollection.Add(tn);
   }
Beispiel #15
0
            public static int CheckTree(Tree.TreeNode node)
            {
                var result = LeftCheck(node.Left, node.Value) && RightCheck(node.Right, node.Value) ? 1 : 0;

                return(result);
            }
   private Tree.TreeNode AddItemToTree(MenuItemModel item, Tree.TreeNodeCollection parentCollection)
   {
      String text = item.Text;
      if (String.IsNullOrEmpty(text))
         text = GetMenuItemNameTree(item.GetType());
      Tree.TreeNode tn = new Tree.TreeNode(text);
      tn.Tag = item;

      if (!(item is IncludeContextMenuModel))
      {
         foreach (MenuItemModel subitem in item.SubItems)
         {
            AddItemToTree(subitem, tn.Nodes);
         }
      }
      parentCollection.Add(tn);
      this.treeNodes.Add(item, tn);

      return tn;
   }