示例#1
0
        public void SelectRangeRegressionTest()
        {
            RunOnUIThread.Execute(() =>
            {
                var selectionModel = new SelectionModel()
                {
                    Source = CreateNestedData(1, 2, 3)
                };

                // length of start smaller than end used to cause an out of range error.
                selectionModel.SelectRange(IndexPath.CreateFrom(0), IndexPath.CreateFrom(1, 1));

                ValidateSelection(selectionModel,
                                  new List <IndexPath>()
                {
                    Path(0, 0),
                    Path(0, 1),
                    Path(0, 2),
                    Path(0),
                    Path(1, 0),
                    Path(1, 1)
                },
                                  new List <IndexPath>()
                {
                    Path(),
                    Path(1)
                },
                                  1 /* selectedInnerNodes */);

                selectionModel = new SelectionModel()
                {
                    Source = CreateNestedData(2, 2, 1)
                };

                selectionModel.SelectRange(
                    Path(1), Path(2));

                ValidateSelection(
                    selectionModel,
                    new List <IndexPath> {
                    Path(1, 0, 0),
                    Path(1), Path(2),
                    Path(1, 0), Path(1, 1),
                    Path(2, 0), Path(2, 1),
                    Path(1, 0, 1),
                    Path(1, 1, 0), Path(1, 1, 1),
                    Path(2, 0, 0), Path(2, 0, 1),
                    Path(2, 1, 0), Path(2, 1, 1),
                },
                    new List <IndexPath> {
                    IndexPath.CreateFromIndices(new List <int> {
                    })
                },
                    12);
            });
        }
示例#2
0
        private static void Traverse(object root, Action <TreeWalkNodeInfo> nodeAction)
        {
            var       pendingNodes = new Stack <TreeWalkNodeInfo>();
            IndexPath current      = Path(null);

            pendingNodes.Push(new TreeWalkNodeInfo()
            {
                Current = root, Path = current
            });

            while (pendingNodes.Count > 0)
            {
                var currentNode   = pendingNodes.Pop();
                var currentObject = currentNode.Current as IList;

                if (currentObject != null)
                {
                    for (int i = currentObject.Count - 1; i >= 0; i--)
                    {
                        var        child = currentObject[i];
                        List <int> path  = new List <int>();
                        for (int idx = 0; idx < currentNode.Path.GetSize(); idx++)
                        {
                            path.Add(currentNode.Path.GetAt(idx));
                        }

                        path.Add(i);
                        var childPath = IndexPath.CreateFromIndices(path);
                        if (child != null)
                        {
                            pendingNodes.Push(new TreeWalkNodeInfo()
                            {
                                Current = child, Path = childPath
                            });
                        }
                    }
                }

                nodeAction(currentNode);
            }
        }
示例#3
0
 public static IndexPath Path(params int[] path)
 {
     return(IndexPath.CreateFromIndices(path));
 }