Ejemplo n.º 1
0
        public static void SelectAndScrollInView <Item>(NSOutlineView treeView, Item[] items,
                                                        Func <Item, Item> parentGetter) where Item : NSObject
        {
            var rows = new List <uint> ();

            foreach (var item in items)
            {
                var rowIdx = treeView.RowForItem(item);
                if (rowIdx < 0)
                {
                    var stack = new Stack <Item>();
                    for (var i = parentGetter(item); i != null; i = parentGetter(i))
                    {
                        stack.Push(i);
                    }
                    while (stack.Count > 0)
                    {
                        treeView.ExpandItem(stack.Pop());
                    }
                    rowIdx = treeView.RowForItem(item);
                }
                if (rowIdx >= 0)
                {
                    rows.Add((uint)rowIdx);
                }
            }
            treeView.SelectRows(
                NSIndexSet.FromArray(rows.ToArray()),
                byExtendingSelection: false
                );
            if (rows.Count > 0)
            {
                treeView.ScrollRowToVisible((nint)rows[0]);
            }
        }
Ejemplo n.º 2
0
            void UpdateSelection()
            {
                var rowsToSelect = new HashSet <nuint>();

                void DiscoverSelected(ITreeNode node)
                {
                    if (node.IsSelected)
                    {
                        var rowToSelect = treeView.RowForItem(ToObject(nodeToItem[node]));
                        Debug.Assert(rowToSelect >= 0);
                        rowsToSelect.Add((nuint)rowToSelect);
                    }
                    if (node.IsExpanded)
                    {
                        foreach (var n in node.Children)
                        {
                            DiscoverSelected(n);
                        }
                    }
                }

                DiscoverSelected(rootItem.Node);

                treeView.SelectRows(NSIndexSet.FromArray(rowsToSelect.ToArray()), byExtendingSelection: false);
            }
Ejemplo n.º 3
0
		public override NSView GetView (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) {
			// Cast item
			var product = item as Product;

			// This pattern allows you reuse existing views when they are no-longer in use.
			// If the returned view is null, you instance up a new view
			// If a non-null view is returned, you modify it enough to reflect the new data
			NSTableCellView view = (NSTableCellView)outlineView.MakeView (tableColumn.Title, this);
			if (view == null) {
				view = new NSTableCellView ();
				if (tableColumn.Title == "Product") {
					view.ImageView = new NSImageView (new CGRect (0, 0, 16, 16));
					view.AddSubview (view.ImageView);
					view.TextField = new NSTextField (new CGRect (20, 0, 400, 16));
				} else {
					view.TextField = new NSTextField (new CGRect (0, 0, 400, 16));
				}
				view.TextField.AutoresizingMask = NSViewResizingMask.WidthSizable;
				view.AddSubview (view.TextField);
				view.Identifier = tableColumn.Title;
				view.TextField.BackgroundColor = NSColor.Clear;
				view.TextField.Bordered = false;
				view.TextField.Selectable = false;
				view.TextField.Editable = !product.IsProductGroup;
			}

			// Tag view
			view.TextField.Tag = outlineView.RowForItem (item);

			// Allow for edit
			view.TextField.EditingEnded += (sender, e) => {

				// Grab product
				var prod = outlineView.ItemAtRow(view.Tag) as Product;

				// Take action based on type
				switch(view.Identifier) {
				case "Product":
					prod.Title = view.TextField.StringValue;
					break;
				case "Details":
					prod.Description = view.TextField.StringValue;
					break; 
				}
			};

			// Setup view based on the column selected
			switch (tableColumn.Title) {
			case "Product":
				view.ImageView.Image = NSImage.ImageNamed (product.IsProductGroup ? "tags.png" : "tag.png");
				view.TextField.StringValue = product.Title;
				break;
			case "Details":
				view.TextField.StringValue = product.Description;
				break;
			}

			return view;
		}
Ejemplo n.º 4
0
        public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
        {
            // Cast item
            var product = item as Product;

            // This pattern allows you reuse existing views when they are no-longer in use.
            // If the returned view is null, you instance up a new view
            // If a non-null view is returned, you modify it enough to reflect the new data
            NSTextField view = (NSTextField)outlineView.MakeView(tableColumn.Title, this);

            if (view == null)
            {
                view                 = new NSTextField();
                view.Identifier      = tableColumn.Title;
                view.BackgroundColor = NSColor.Clear;
                view.Bordered        = false;
                view.Selectable      = false;
                view.Editable        = !product.IsProductGroup;
            }

            // Tag view
            view.Tag = outlineView.RowForItem(item);

            // Allow for edit
            view.EditingEnded += (sender, e) => {
                // Grab product
                var prod = outlineView.ItemAtRow(view.Tag) as Product;

                // Take action based on type
                switch (view.Identifier)
                {
                case "Product":
                    prod.Title = view.StringValue;
                    break;

                case "Details":
                    prod.Description = view.StringValue;
                    break;
                }
            };

            // Setup view based on the column selected
            switch (tableColumn.Title)
            {
            case "Product":
                view.StringValue = product.Title;
                break;

            case "Details":
                view.StringValue = product.Description;
                break;
            }

            return(view);
        }
Ejemplo n.º 5
0
            public override void SetObjectValue(NSOutlineView outlineView, NSObject theObject, NSTableColumn tableColumn, NSObject item)
            {
                var colHandler = Handler.GetColumn(tableColumn);

                if (colHandler != null)
                {
                    var myitem = (EtoTreeItem)item;
                    colHandler.SetObjectValue(myitem.Item, theObject);

                    Handler.SetIsEditing(false);
                    var row = outlineView.RowForItem(item);
                    Handler.Callback.OnCellEdited(Handler.Widget, new GridViewCellEventArgs(colHandler.Widget, (int)row, colHandler.Column, myitem.Item));
                }
            }
Ejemplo n.º 6
0
            public override nfloat GetRowHeight(NSOutlineView outlineView, NSObject item)
            {
                var height = outlineView.RowHeight;
                var row    = outlineView.RowForItem(item);

                for (int i = 0; i < outlineView.ColumnCount; i++)
                {
                    var cell = outlineView.GetCell(i, row);
                    if (cell != null)
                    {
                        height = (nfloat)Math.Max(height, cell.CellSize.Height);
                    }
                }
                return(height);
            }
Ejemplo n.º 7
0
            /// <inheritdoc />
            public override nfloat GetRowHeight(NSOutlineView outlineView, NSObject item)
            {
                float height     = 20;
                var   rowForItem = outlineView.RowForItem(item);

                if (rowForItem == 0)
                {
                    ////outlineView.IndentationPerLevel = 0;
                    height = float.Epsilon; // can't be zero, but we don't want to see it.
                }
                else
                {
                    ////outlineView.IndentationPerLevel = 16;
                }
                return(height);
            }
Ejemplo n.º 8
0
        public override NSTableRowView RowViewForItem(NSOutlineView outlineView, NSObject item)
        {
            var view = new ColoredTableRowView(SortedOutlineIntegers.DisableRowSelectionGradient.AsResourceInterger() == 1, false);
            ColoredTableRowView cachedRowView;

            if (_cashedRowViews.TryGetValue(item.Handle, out cachedRowView))
            {
                return(cachedRowView);
            }
            if (outlineView.RowForItem(item) != outlineView.RowCount - 1)
            {
                view.CreateHorizontalSeparator(0, SortedViewImages.SortedViewSeparator.AsResourceNsImage(), RowHeight, MainViewFloats.SeparatorsImageHeight.AsFloat());
            }
            _cashedRowViews.Add(item.Handle, view);
            return(view);
        }
Ejemplo n.º 9
0
        public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
        {
            var view = (MacDebuggerObjectCellViewBase)outlineView.MakeView(tableColumn.Identifier, this);

            switch (tableColumn.Identifier)
            {
            case "name":
                if (view == null)
                {
                    view = new MacDebuggerObjectNameView(treeView);
                }
                break;

            case "value":
                if (view == null)
                {
                    view = new MacDebuggerObjectValueView(treeView);
                }
                break;

            case "type":
                if (view == null)
                {
                    view = new MacDebuggerObjectTypeView(treeView);
                }
                break;

            case "pin":
                if (view == null)
                {
                    view = new MacDebuggerObjectPinView(treeView);
                }
                break;

            default:
                return(null);
            }

            view.Row         = outlineView.RowForItem(item);
            view.ObjectValue = item;

            return(view);
        }
Ejemplo n.º 10
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.º 11
0
 public override NSTableRowView RowViewForItem(NSOutlineView outlineView, NSObject item)
 {
     return(outlineView.GetRowView(outlineView.RowForItem(item), false) ?? new TableRowView());
 }
Ejemplo n.º 12
0
        // the table is looking for this method, picks it up automagically
        public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
        {
            var    facade         = (NSObjectFacade)item;
            var    vm             = facade.Target as PropertyViewModel;
            var    group          = facade.Target as IGroupingList <string, EditorViewModel>;
            string cellIdentifier = (group == null) ? vm.GetType().Name : group.Key;

            // Let's make the columns look pretty
            if (!goldenRatioApplied)
            {
                int    middleColumnWidth = 5;
                nfloat rightColumnWidth  = (outlineView.Frame.Width - middleColumnWidth) / 1.618f;
                nfloat leftColumnWidth   = outlineView.Frame.Width - rightColumnWidth - middleColumnWidth;
                outlineView.TableColumns()[0].Width = leftColumnWidth;
                outlineView.TableColumns()[1].Width = rightColumnWidth;
                goldenRatioApplied = true;
            }

            // Setup view based on the column
            switch (tableColumn.Identifier)
            {
            case PropertyEditorPanel.PropertyListColId:
                var view = (UnfocusableTextField)outlineView.MakeView("label", this);
                if (view == null)
                {
                    view = new UnfocusableTextField {
                        Identifier = "label",
                        Alignment  = NSTextAlignment.Right,
                    };
                }

                view.StringValue = ((group == null) ? vm.Property.Name + ":" : group.Key) ?? String.Empty;

                // Set tooltips only for truncated strings
                var stringWidth = view.AttributedStringValue.Size.Width + 30;
                if (stringWidth > tableColumn.Width)
                {
                    view.ToolTip = vm.Property.Name;
                }

                return(view);

            case PropertyEditorPanel.PropertyEditorColId:
                if (vm == null)
                {
                    return(null);
                }

                var editor = (PropertyEditorControl)outlineView.MakeView(cellIdentifier + "edits", this);
                if (editor == null)
                {
                    editor = GetEditor(vm, outlineView);
                    // If still null we have no editor yet.
                    if (editor == null)
                    {
                        return(new NSView());
                    }
                }

                // we must reset these every time, as the view may have been reused
                editor.TableRow = outlineView.RowForItem(item);

                // Force a row update due to new height, but only when we are non-default
                if (editor.TriggerRowChange)
                {
                    outlineView.NoteHeightOfRowsWithIndexesChanged(new NSIndexSet(editor.TableRow));
                }

                return(editor);
            }

            throw new Exception("Unknown column identifier: " + tableColumn.Identifier);
        }
Ejemplo n.º 13
0
		/// <summary>
		/// Gets the cell.
		/// </summary>
		/// <returns>The cell.</returns>
		/// <param name="outlineView">Outline view.</param>
		/// <param name="tableColumn">Table column.</param>
		/// <param name="item">Item.</param>
		public override NSCell GetCell (NSOutlineView outlineView, NSTableColumn tableColumn, Foundation.NSObject item)
		{
			nint row = outlineView.RowForItem (item);
			return tableColumn.DataCellForRow (row);
		}
        public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
        {
            GetVMGroupCellItendifiterFromFacade(item, out EditorViewModel evm, out PanelGroupViewModel group, out var cellIdentifier);

            if (group != null)
            {
                var categoryContainer = (CategoryContainerControl)outlineView.MakeView(CategoryIdentifier, this);
                if (categoryContainer == null)
                {
                    categoryContainer = new CategoryContainerControl(this.hostResources, outlineView)
                    {
                        Identifier = CategoryIdentifier,
                        TableView  = outlineView,
                    };
                }

                ((UnfocusableTextField)categoryContainer.Subviews[1]).StringValue = group.Category;

                if (this.dataSource.DataContext.GetIsExpanded(group.Category))
                {
                    SynchronizationContext.Current.Post(s => {
                        outlineView.ExpandItem(item);
                    }, null);
                }

                return(categoryContainer);
            }

            NSView editorOrContainer = null;

            if (this.firstCache.TryGetValue(cellIdentifier, out IEditorView editor))
            {
                this.firstCache.Remove(cellIdentifier);
                editorOrContainer = (editor.NativeView is PropertyEditorControl) ? new EditorContainer(this.hostResources, editor)
                {
                    Identifier = cellIdentifier
                } : editor.NativeView;
            }
            else
            {
                editorOrContainer = GetEditor(cellIdentifier, evm, outlineView);
                editor            = ((editorOrContainer as EditorContainer)?.EditorView) ?? editorOrContainer as IEditorView;
            }

            if (editorOrContainer is EditorContainer ec)
            {
                ec.ViewModel = evm;
                ec.Label     = evm.Name;

#if DEBUG // Currently only used to highlight which controls haven't been implemented
                if (editor == null)
                {
                    ec.LabelTextColor = NSColor.Red;
                }
#endif
            }

            if (editor != null)
            {
                var ovm = evm as ObjectPropertyViewModel;
                if (ovm != null && editorOrContainer is EditorContainer container)
                {
                    if (container.LeftEdgeView == null)
                    {
                        if (ovm.CanDelve)
                        {
                            container.LeftEdgeView = outlineView.MakeView("NSOutlineViewDisclosureButtonKey", outlineView);
                        }
                    }
                    else if (!ovm.CanDelve)
                    {
                        container.LeftEdgeView = null;
                    }
                }
                else if (!(editorOrContainer is EditorContainer))
                {
                    editor.ViewModel = evm;
                }

                bool openObjectRow = ovm != null && outlineView.IsItemExpanded(item);
                if (!openObjectRow)
                {
                    var parent = outlineView.GetParent(item);
                    openObjectRow = (parent != null && ((NSObjectFacade)parent).Target is ObjectPropertyViewModel);
                }

                SetRowValueBackground(editorOrContainer, openObjectRow);

                // Force a row update due to new height, but only when we are non-default
                if (editor.IsDynamicallySized)
                {
                    nint index = outlineView.RowForItem(item);
                    outlineView.NoteHeightOfRowsWithIndexesChanged(new NSIndexSet(index));
                }
            }
            else if (editorOrContainer is PanelHeaderEditorControl header)
            {
                header.ViewModel = this.dataSource.DataContext;
            }

            return(editorOrContainer);
        }
        private NSView GetViewForItem(NSOutlineView outline, NSObjectFacade facade, bool makeIfNeccessary = false)
        {
            nint row = outline.RowForItem(facade);

            return(outline.GetView(0, row, makeIfNeccessary));
        }
Ejemplo n.º 16
0
            /// <inheritdoc />
            public override bool ShouldSelectItem(NSOutlineView outlineView, NSObject item)
            {
                var rowForItem = outlineView.RowForItem(item);

                return(rowForItem != 0);
            }
Ejemplo n.º 17
0
            /// <inheritdoc />
            public override bool ShouldShowOutlineCell(NSOutlineView outlineView, NSObject item)
            {
                var rowForItem = outlineView.RowForItem(item);

                return(rowForItem > 0);
            }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <returns>The cell.</returns>
        /// <param name="outlineView">Outline view.</param>
        /// <param name="tableColumn">Table column.</param>
        /// <param name="item">Item.</param>
        public override NSCell GetCell(NSOutlineView outlineView, NSTableColumn tableColumn, Foundation.NSObject item)
        {
            nint row = outlineView.RowForItem(item);

            return(tableColumn.DataCellForRow(row));
        }
        private NSView GetViewForItem(NSOutlineView outline, NSObjectFacade facade)
        {
            nint row = outline.RowForItem(facade);

            return(outline.GetView(0, row, false));
        }