Пример #1
0
        public void NSOutlineView_InsertNull()
        {
            NSOutlineView v = new NSOutlineView();

            v.BeginUpdates();              // We do this to prevent a crash: Insert/remove/move only works within a -beginUpdates/-endUpdates block or a View Based TableView
#if !XAMCORE_2_0
            v.InsertItems(new NSIndexSet(0), null, NSTableViewAnimationOptions.EffectFade);
#else
            v.InsertItems(new NSIndexSet(0), null, NSTableViewAnimation.None);
#endif
            v.EndUpdates();
        }
Пример #2
0
            void UpdateStructure(ITreeNode newRoot)
            {
                void Rebind(NSNodeItem item, ITreeNode newNode)
                {
                    nodeToItem.Remove(item.Node);
                    item.Node           = newNode;
                    nodeToItem[newNode] = item;
                }

                void DeleteDescendantsFromMap(NSNodeItem item)
                {
                    item.Children.ForEach(c =>
                    {
                        Debug.Assert(nodeToItem.Remove(c.Node));
                        DeleteDescendantsFromMap(c);
                    });
                }

                var edits = TreeEdit.GetTreeEdits(rootItem.Node, newRoot);

                Rebind(rootItem, newRoot);

                foreach (var e in edits)
                {
                    var node = nodeToItem[e.Node];
                    switch (e.Type)
                    {
                    case TreeEdit.EditType.Insert:
                        var insertedNode = CreateItem(e.NewChild);
                        node.Children.Insert(e.ChildIndex, insertedNode);
                        treeView.InsertItems(new NSIndexSet(e.ChildIndex), ToObject(node), NSTableViewAnimation.None);
                        break;

                    case TreeEdit.EditType.Delete:
                        var deletedNode = node.Children[e.ChildIndex];
                        node.Children.RemoveAt(e.ChildIndex);
                        Debug.Assert(deletedNode == nodeToItem[e.OldChild]);
                        nodeToItem.Remove(e.OldChild);
                        treeView.RemoveItems(new NSIndexSet(e.ChildIndex), ToObject(node), NSTableViewAnimation.None);
                        DeleteDescendantsFromMap(deletedNode);
                        break;

                    case TreeEdit.EditType.Reuse:
                        treeView.ReloadItem(ToObject(node));
                        Rebind(nodeToItem[e.OldChild], e.NewChild);
                        break;

                    case TreeEdit.EditType.Expand:
                        treeView.ExpandItem(ToObject(node), expandChildren: false);
                        break;

                    case TreeEdit.EditType.Collapse:
                        treeView.CollapseItem(ToObject(node), collapseChildren: false);
                        break;
                    }
                }
            }
Пример #3
0
            void UpdateStructure(ITreeNode newRoot)
            {
                void Rebind(NSNodeItem item, ITreeNode newNode)
                {
                    nodeToItem.Remove(item.Node);
                    item.Node           = newNode;
                    nodeToItem[newNode] = item;
                }

                void DeleteDescendantsFromMap(NSNodeItem item)
                {
                    item.Children.ForEach(c =>
                    {
                        Debug.Assert(nodeToItem.Remove(c.Node));
                        DeleteDescendantsFromMap(c);
                    });
                }

                var edits = TreeEdit.GetTreeEdits(rootItem.Node, newRoot, new TreeEdit.Options
                {
                    TemporariltyExpandParentToInitChildren = true
                });

                Rebind(rootItem, newRoot);

                foreach (var e in edits)
                {
                    var node = nodeToItem[e.Node];
                    switch (e.Type)
                    {
                    case TreeEdit.EditType.Insert:
                        var insertedNode = CreateItem(e.NewChild);
                        node.Children.Insert(e.ChildIndex, insertedNode);
                        using (var set = new NSIndexSet(e.ChildIndex))
                            treeView.InsertItems(set, ToObject(node), NSTableViewAnimation.None);
                        break;

                    case TreeEdit.EditType.Delete:
                        var deletedNode = node.Children[e.ChildIndex];
                        node.Children.RemoveAt(e.ChildIndex);
                        Debug.Assert(deletedNode == nodeToItem[e.OldChild]);
                        nodeToItem.Remove(e.OldChild);
                        using (var set = new NSIndexSet(e.ChildIndex))
                            treeView.RemoveItems(set, ToObject(node), NSTableViewAnimation.None);
                        DeleteDescendantsFromMap(deletedNode);
                        break;

                    case TreeEdit.EditType.Reuse:
                        var viewItem = nodeToItem [e.OldChild];
                        Rebind(viewItem, e.NewChild);
                        treeView.ReloadItem(ToObject(viewItem), reloadChildren: false);
                        if (owner.OnUpdateRowView != null)
                        {
                            var rowIdx  = treeView.RowForItem(ToObject(viewItem));
                            var rowView = rowIdx >= 0 ? treeView.GetRowView(rowIdx, makeIfNecessary: false) : null;
                            if (rowView != null)
                            {
                                owner.OnUpdateRowView(rowView, (Node)e.NewChild);
                            }
                        }
                        break;

                    case TreeEdit.EditType.Expand:
                        treeView.ExpandItem(ToObject(node), expandChildren: false);
                        break;

                    case TreeEdit.EditType.Collapse:
                        treeView.CollapseItem(ToObject(node), collapseChildren: false);
                        break;
                    }
                }
            }