Ejemplo n.º 1
0
        public override nfloat GetSizeToFitColumnWidth(NSOutlineView outlineView, nint column)
        {
            var columns     = outlineView.TableColumns();
            var col         = columns[column];
            var columnWidth = col.MinWidth;

            for (nint row = 0; row < outlineView.RowCount; row++)
            {
                var rowView    = outlineView.GetRowView(row, true);
                var columnView = rowView.ViewAtColumn(column);
                var width      = columnView.Frame.Width;

                if (column == 0)
                {
                    width += columnView.Frame.X;
                }

                if (width > columnWidth)
                {
                    columnWidth = NMath.Min(width, col.MaxWidth);
                }
            }

            return(columnWidth);
        }
Ejemplo n.º 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, 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;
                    }
                }
            }
Ejemplo n.º 3
0
 public override NSTableRowView RowViewForItem(NSOutlineView outlineView, NSObject item)
 {
     return(outlineView.GetRowView(outlineView.RowForItem(item), false) ?? new TableRowView());
 }