public static nfloat GetOptimalWidth(MacObjectValueTreeView treeView, ObjectValueNode node)
        {
            nfloat optimalWidth = MarginSize;

            var editable    = treeView.AllowWatchExpressions && node.Parent is RootObjectValueNode;
            var placeholder = string.Empty;
            var name        = node.Name;

            if (node.IsUnknown)
            {
            }
            else if (node.IsError || node.IsNotSupported)
            {
            }
            else if (node.IsImplicitNotSupported)
            {
            }
            else if (node.IsEvaluating)
            {
            }
            else if (node.IsEnumerable)
            {
            }
            else if (node is AddNewExpressionObjectValueNode)
            {
                placeholder = GettextCatalog.GetString("Add new expression");
                name        = string.Empty;
                editable    = true;
            }

            optimalWidth += ImageSize;
            optimalWidth += RowCellSpacing;

            var value = editable && string.IsNullOrEmpty(name) ? placeholder : name;

            optimalWidth += GetWidthForString(treeView.CustomFont, value);

            if (MacObjectValueTreeView.ValidObjectForPreviewIcon(node))
            {
                optimalWidth += RowCellSpacing;
                optimalWidth += ImageSize;
            }

            optimalWidth += MarginSize;

            return(optimalWidth);
        }
        void Insert(MacObjectValueNode parent, int index, ObjectValueNode node)
        {
            var value = new MacObjectValueNode(parent, node);

            mapping[node] = value;

            parent.Children.Insert(index, value);

            foreach (var child in node.Children)
            {
                Add(value, child);
            }

            if (node.HasChildren && !node.ChildrenLoaded)
            {
                Add(value, new LoadingObjectValueNode(node));
            }
        }
        public MacObjectValueTreeViewDataSource(MacObjectValueTreeView treeView, ObjectValueNode root, bool allowWatchExpressions)
        {
            AllowWatchExpressions = allowWatchExpressions;
            this.treeView         = treeView;

            Root = new MacObjectValueNode(null, root);
            mapping.Add(root, Root);

            foreach (var child in root.Children)
            {
                Add(Root, child);
            }

            if (allowWatchExpressions)
            {
                Add(Root, new AddNewExpressionObjectValueNode());
            }
        }
Beispiel #4
0
        void ISupportChildObjectValueNodeReplacement.ReplaceChildNode(ObjectValueNode node, ObjectValueNode[] newNodes)
        {
            var index = Children.IndexOf(node);

            Debug.Assert(index >= 0, "The node being replaced should be a child of this node");

            if (newNodes.Length == 0)
            {
                RemoveChildAt(index);
                return;
            }

            ReplaceChildAt(index, newNodes [0]);

            for (int i = 1; i < newNodes.Length; i++)
            {
                InsertChildAt(++index, newNodes[i]);
            }
        }
        void Add(MacObjectValueNode parent, ObjectValueNode node)
        {
            var value = new MacObjectValueNode(parent, node);

            mapping[node] = value;

            parent.Children.Add(value);

            if (treeView.AllowExpanding)
            {
                foreach (var child in node.Children)
                {
                    Add(value, child);
                }

                if (node.HasChildren && !node.ChildrenLoaded)
                {
                    Add(value, new LoadingObjectValueNode(node));
                }
            }
        }
Beispiel #6
0
 public void ReplaceValueAt(int index, ObjectValueNode value)
 {
     ReplaceChildAt(index, value);
 }
Beispiel #7
0
 public void AddValue(ObjectValueNode value)
 {
     AddChild(value);
 }
 protected void InsertChildAt(int index, ObjectValueNode value)
 {
     children.Insert(index, value);
     value.Parent = this;
 }
 public ObjectValueEditEventArgs(ObjectValueNode node, string newValue) : base(node)
 {
     NewValue = newValue;
 }
 public ObjectValueNodeEventArgs(ObjectValueNode node)
 {
     Node = node;
 }
        public void ReloadChildren(ObjectValueNode node)
        {
            if (!TryGetValue(node, out var parent))
            {
                return;
            }

            treeView.BeginUpdates();

            try {
                NSIndexSet indexes;
                NSRange    range;

                if (parent.Children.Count > 0)
                {
                    range   = new NSRange(0, parent.Children.Count);
                    indexes = NSIndexSet.FromNSRange(range);

                    var removed = new List <MacObjectValueNode> ();
                    foreach (var child in parent.Children)
                    {
                        Remove(child, removed);
                    }

                    parent.Children.Clear();

                    if (parent.Target is RootObjectValueNode)
                    {
                        treeView.RemoveItems(indexes, null, NSTableViewAnimation.None);
                    }
                    else
                    {
                        treeView.RemoveItems(indexes, parent, NSTableViewAnimation.None);
                    }

                    for (int i = 0; i < removed.Count; i++)
                    {
                        removed[i].Dispose();
                    }
                }

                for (int i = 0; i < node.Children.Count; i++)
                {
                    Add(parent, node.Children[i]);
                }

                // if we did not load all the children, add a Show More node
                if (!node.ChildrenLoaded)
                {
                    Add(parent, new ShowMoreValuesObjectValueNode(node));
                }

                range   = new NSRange(0, parent.Children.Count);
                indexes = NSIndexSet.FromNSRange(range);

                if (parent.Target is RootObjectValueNode)
                {
                    treeView.InsertItems(indexes, null, NSTableViewAnimation.None);
                }
                else
                {
                    treeView.InsertItems(indexes, parent, NSTableViewAnimation.None);
                }

                // if we loaded children and discovered that the node does not actually have any children,
                // update the node and reload the data.
                // TOOD: it would be nice to know this before the node is expanded so we don't see the "loading" node flash
                if (!node.HasChildren)
                {
                    treeView.ReloadItem(parent);
                }
                else
                {
                    RestoreExpandedState(node.Children);
                }
            } finally {
                treeView.EndUpdates();
            }
        }
        public void Replace(ObjectValueNode node, ObjectValueNode[] replacementNodes)
        {
            if (!TryGetValue(node, out var item))
            {
                return;
            }

            var parent = item.Parent;
            int index  = -1;

            if (parent == null)
            {
                return;
            }

            for (int i = 0; i < parent.Children.Count; i++)
            {
                if (parent.Children[i] == item)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                return;
            }

            var removed = new List <MacObjectValueNode> ();

            parent.Children.RemoveAt(index);
            Remove(item, removed);

            treeView.BeginUpdates();

            try {
                var indexes = new NSIndexSet(index);

                if (parent.Target is RootObjectValueNode)
                {
                    treeView.RemoveItems(indexes, null, NSTableViewAnimation.None);
                }
                else
                {
                    treeView.RemoveItems(indexes, parent, NSTableViewAnimation.None);
                }

                if (replacementNodes.Length > 0)
                {
                    for (int i = 0; i < replacementNodes.Length; i++)
                    {
                        Insert(parent, index + i, replacementNodes[i]);
                    }

                    var range = new NSRange(index, replacementNodes.Length);
                    indexes = NSIndexSet.FromNSRange(range);

                    if (parent.Target is RootObjectValueNode)
                    {
                        treeView.InsertItems(indexes, null, NSTableViewAnimation.None);
                    }
                    else
                    {
                        treeView.InsertItems(indexes, parent, NSTableViewAnimation.None);
                    }

                    RestoreExpandedState(replacementNodes);
                }
            } finally {
                treeView.EndUpdates();
            }

            for (int i = 0; i < removed.Count; i++)
            {
                removed[i].Dispose();
            }
        }
        public void LoadChildren(ObjectValueNode node, int startIndex, int count)
        {
            if (!TryGetValue(node, out var parent))
            {
                return;
            }

            treeView.BeginUpdates();

            try {
                int        lastIndex    = parent.Children.Count - 1;
                bool       needShowMore = !node.ChildrenLoaded;
                bool       haveShowMore = false;
                NSIndexSet indexes      = null;
                NSRange    range;

                if (lastIndex >= 0 && parent.Children[lastIndex].Target is ShowMoreValuesObjectValueNode)
                {
                    haveShowMore = true;
                }

                if (startIndex < parent.Children.Count)
                {
                    // Note: This can only happen if we have either a "Loading..." node or a "Show More" node.
                    var removed = new List <MacObjectValueNode> ();
                    int extra   = parent.Children.Count - startIndex;

                    if (lastIndex == 0 && parent.Children[0].Target is LoadingObjectValueNode)
                    {
                        // Remove the "Loading..." node
                        indexes = NSIndexSet.FromIndex(0);
                        Remove(parent.Children[0], removed);
                        parent.Children.Clear();
                    }
                    else if (haveShowMore && extra == 1)
                    {
                        // Only remove the "Show More" node if we don't need it anymore...
                        if (!needShowMore)
                        {
                            indexes = NSIndexSet.FromIndex(lastIndex);
                            Remove(parent.Children[lastIndex], removed);
                            parent.Children.RemoveAt(lastIndex);
                        }
                    }
                    else
                    {
                        // Unexpected, but let's try to deal with this...
                        range   = new NSRange(startIndex, extra);
                        indexes = NSIndexSet.FromNSRange(range);

                        for (int i = parent.Children.Count - 1; i >= startIndex; i--)
                        {
                            Remove(parent.Children[i], removed);
                            parent.Children.RemoveAt(i);
                        }

                        haveShowMore = false;
                    }

                    if (indexes != null)
                    {
                        if (parent.Target is RootObjectValueNode)
                        {
                            treeView.RemoveItems(indexes, null, NSTableViewAnimation.None);
                        }
                        else
                        {
                            treeView.RemoveItems(indexes, parent, NSTableViewAnimation.None);
                        }

                        for (int i = 0; i < removed.Count; i++)
                        {
                            removed[i].Dispose();
                        }
                    }
                }

                for (int i = startIndex; i < startIndex + count; i++)
                {
                    Insert(parent, i, node.Children[i]);
                }

                // Add a "Show More" node only if we need one and don't already have one.
                if (needShowMore && !haveShowMore)
                {
                    Add(parent, new ShowMoreValuesObjectValueNode(node));
                    count++;
                }

                range   = new NSRange(startIndex, count);
                indexes = NSIndexSet.FromNSRange(range);

                if (parent.Target is RootObjectValueNode)
                {
                    treeView.InsertItems(indexes, null, NSTableViewAnimation.None);
                }
                else
                {
                    treeView.InsertItems(indexes, parent, NSTableViewAnimation.None);
                }

                // if we loaded children and discovered that the node does not actually have any children,
                // update the node and reload the data.
                // TOOD: it would be nice to know this before the node is expanded so we don't see the "loading" node flash
                if (!node.HasChildren)
                {
                    treeView.ReloadItem(parent);
                }
                else
                {
                    RestoreExpandedState(node.Children);
                }
            } finally {
                treeView.EndUpdates();
            }
        }
        public void Replace(ObjectValueNode node, ObjectValueNode[] replacementNodes)
        {
            if (!TryGetValue(node, out var item))
            {
                return;
            }

            var parent = item.Parent;
            int index  = -1;

            if (parent == null)
            {
                return;
            }

            for (int i = 0; i < parent.Children.Count; i++)
            {
                if (parent.Children[i] == item)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                return;
            }

            parent.Children.RemoveAt(index);
            mapping.Remove(item.Target);
            item.Dispose();

            treeView.BeginUpdates();

            var indexes = new NSIndexSet(index);

            if (parent.Target is RootObjectValueNode)
            {
                treeView.RemoveItems(indexes, null, NSTableViewAnimation.None);
            }
            else
            {
                treeView.RemoveItems(indexes, parent, NSTableViewAnimation.None);
            }

            if (replacementNodes.Length > 0)
            {
                for (int i = 0; i < replacementNodes.Length; i++)
                {
                    Insert(parent, index + i, replacementNodes [i]);
                }

                var range = new NSRange(index, replacementNodes.Length);
                indexes = NSIndexSet.FromNSRange(range);

                if (parent.Target is RootObjectValueNode)
                {
                    treeView.InsertItems(indexes, null, NSTableViewAnimation.None);
                }
                else
                {
                    treeView.InsertItems(indexes, parent, NSTableViewAnimation.None);
                }

                foreach (var n in replacementNodes)
                {
                    if (treeView.Controller.GetNodeWasExpandedAtLastCheckpoint(n))
                    {
                        if (TryGetValue(n, out MacObjectValueNode x))
                        {
                            treeView.ExpandItem(x);
                        }
                    }
                }
            }

            treeView.EndUpdates();
        }
 public ObjectValueExpressionEventArgs(ObjectValueNode node, string expression) : base(node)
 {
     Expression = expression;
 }
        public void ReloadChildren(ObjectValueNode node)
        {
            if (!TryGetValue(node, out var parent))
            {
                return;
            }

            treeView.BeginUpdates();

            NSIndexSet indexes;
            NSRange    range;

            if (parent.Children.Count > 0)
            {
                range   = new NSRange(0, parent.Children.Count);
                indexes = NSIndexSet.FromNSRange(range);

                foreach (var child in parent.Children)
                {
                    mapping.Remove(child.Target);
                    child.Dispose();
                }

                parent.Children.Clear();

                if (parent.Target is RootObjectValueNode)
                {
                    treeView.RemoveItems(indexes, null, NSTableViewAnimation.None);
                }
                else
                {
                    treeView.RemoveItems(indexes, parent, NSTableViewAnimation.None);
                }
            }

            for (int i = 0; i < node.Children.Count; i++)
            {
                Add(parent, node.Children[i]);
            }

            // if we did not load all the children, add a Show More node
            if (!node.ChildrenLoaded)
            {
                Add(parent, new ShowMoreValuesObjectValueNode(node));
            }

            range   = new NSRange(0, parent.Children.Count);
            indexes = NSIndexSet.FromNSRange(range);

            if (parent.Target is RootObjectValueNode)
            {
                treeView.InsertItems(indexes, null, NSTableViewAnimation.None);
            }
            else
            {
                treeView.InsertItems(indexes, parent, NSTableViewAnimation.None);
            }

            // if we loaded children and discovered that the node does not actually have any children,
            // update the node and reload the data.
            // TOOD: it would be nice to know this before the node is expanded so we don't see the "loading" node flash
            if (!node.HasChildren)
            {
                treeView.ReloadItem(parent);
            }
            else
            {
                // expand any items that we loaded that were expanded previously

                foreach (var n in node.Children)
                {
                    if (treeView.Controller.GetNodeWasExpandedAtLastCheckpoint(n))
                    {
                        if (TryGetValue(n, out MacObjectValueNode x))
                        {
                            treeView.ExpandItem(x);
                        }
                    }
                }
            }

            treeView.EndUpdates();
        }
Beispiel #17
0
 public MacObjectValueNode(MacObjectValueNode parent, ObjectValueNode target)
 {
     Parent = parent;
     Target = target;
 }
 public bool TryGetValue(ObjectValueNode node, out MacObjectValueNode value)
 {
     return(mapping.TryGetValue(node, out value));
 }
        public static nfloat GetOptimalWidth(MacObjectValueTreeView treeView, ObjectValueNode node, bool hideValueButton)
        {
            nfloat optimalWidth       = MarginSize;
            string evaluateStatusIcon = null;
            string valueButtonText    = null;
            var    showViewerButton   = false;
            Color? previewColor       = null;
            bool   showSpinner        = false;
            string strval;

            if (node.IsUnknown)
            {
                if (treeView.DebuggerService.Frame != null)
                {
                    strval = GettextCatalog.GetString("The name '{0}' does not exist in the current context.", node.Name);
                }
                else
                {
                    strval = string.Empty;
                }
                evaluateStatusIcon = Ide.Gui.Stock.Warning;
            }
            else if (node.IsError || node.IsNotSupported)
            {
                evaluateStatusIcon = Ide.Gui.Stock.Warning;
                strval             = node.Value ?? string.Empty;
                int i = strval.IndexOf('\n');
                if (i != -1)
                {
                    strval = strval.Substring(0, i);
                }
            }
            else if (node.IsImplicitNotSupported)
            {
                strval = string.Empty;                //val.Value; with new "Show Value" button we don't want to display message "Implicit evaluation is disabled"
                if (node.CanRefresh)
                {
                    valueButtonText = GettextCatalog.GetString("Show Value");
                }
            }
            else if (node.IsEvaluating)
            {
                strval      = GettextCatalog.GetString("Evaluating\u2026");
                showSpinner = true;
            }
            else if (node.IsEnumerable)
            {
                if (node is ShowMoreValuesObjectValueNode)
                {
                    valueButtonText = GettextCatalog.GetString("Show More");
                }
                else
                {
                    valueButtonText = GettextCatalog.GetString("Show Values");
                }
                strval = string.Empty;
            }
            else if (node is AddNewExpressionObjectValueNode)
            {
                strval = string.Empty;
            }
            else
            {
                strval = treeView.Controller.GetDisplayValueWithVisualisers(node, out showViewerButton);

                var val = node.GetDebuggerObjectValue();
                if (val != null && !val.IsNull && DebuggingService.HasGetConverter <Color> (val))
                {
                    try {
                        previewColor = DebuggingService.GetGetConverter <Color> (val).GetValue(val);
                    } catch {
                        previewColor = null;
                    }
                }
            }

            strval = strval.Replace("\r\n", " ").Replace("\n", " ");

            // First item: Status Icon -or- Spinner
            if (evaluateStatusIcon != null)
            {
                optimalWidth += ImageSize;
                optimalWidth += RowCellSpacing;
            }

            if (showSpinner)
            {
                optimalWidth += ImageSize;
                optimalWidth += RowCellSpacing;
            }

            // Second Item: Color Preview
            if (previewColor.HasValue)
            {
                optimalWidth += ImageSize;
                optimalWidth += RowCellSpacing;
            }

            // Third Item: Value Button
            if (valueButtonText != null && !hideValueButton)
            {
                optimalWidth += GetWidthForString(treeView.CustomFont, valueButtonText, -3);
                optimalWidth += RowCellSpacing;
            }

            // Fourth Item: Viewer Button
            if (showViewerButton)
            {
                optimalWidth += treeView.CompactView ? CompactImageSize : ImageSize;
                optimalWidth += RowCellSpacing;
            }

            // Fifth Item: Text Value
            optimalWidth += GetWidthForString(treeView.CustomFont, strval);
            optimalWidth += MarginSize;

            return(optimalWidth);
        }
Beispiel #20
0
 public LoadingObjectValueNode(ObjectValueNode parent) : base(GettextCatalog.GetString("Loading\u2026"))
 {
     Parent = parent;
 }
 protected void AddChild(ObjectValueNode value)
 {
     value.Parent = this;
     children.Add(value);
 }