Ejemplo n.º 1
0
        public bool InspectInternal(string name, string path, object data,
                                    Type type  = null,
                                    IMark mark = null,
                                    Action <object> OnValueChanged = null)
        {
            if (data != null)
            {
                type = data.GetType();
            }

            GUITools.SetLabelWidth(options.labelWidth);
            VisualizerBase visualizer  = GetVisualizer(type, mark);
            bool           changed     = false;
            object         changedData = data;

            if (visualizer != null)
            {
                string fieldinfo = name;
                var    postfix   = visualizer.GetLabelPostfix(this, data, type);
                if (postfix != null)
                {
                    fieldinfo += postfix;
                }

                if (visualizer.HasChildren())
                {
                    // Note: to avoid infinite expand that may cause by alwaysShowChildren,
                    // If parentAlwaysShowChild, then current node ignores alwaysShowChildren.
                    var  parentAlwaysShowChild = parentIsAlwaysShow.Count > 0 && parentIsAlwaysShow.Peek();
                    bool alwaysShowChildren    = !parentAlwaysShowChild && visualizer.AlwaysShowChildren();
                    if (!alwaysShowChildren)
                    {
                        using (GUITools.HorizontalScope())
                        {
                            var width = options.labelWidth - options.indentOffset * GUITools.GetIndentLevel();
                            using (GUITools.HorizontalScope(width))
                            {
                                isFoldout[path] = GUITools.Foldout(isFoldout.ContainsKey(path) && isFoldout[path], fieldinfo);
                            }
                            changed |= InspectRoot(name, type, ref changedData, visualizer, mark);
                        }
                    }
                    else
                    {
                        changed |= InspectRoot(name, type, ref changedData, visualizer, mark);
                    }

                    if (changedData != null && (alwaysShowChildren || isFoldout[path]))
                    {
                        try
                        {
                            parentIsAlwaysShow.Push(alwaysShowChildren);
                            using (GUITools.Indent())
                                changed |= visualizer.InspectChildren(this, path, ref changedData, type);
                        }
                        finally
                        {
                            parentIsAlwaysShow.Pop();
                        }
                    }
                }
                else
                {
                    changed |= InspectRoot(fieldinfo, type, ref changedData, visualizer, mark);
                }
            }

            if (changed && OnValueChanged != null)
            {
                OnValueChanged(changedData);
            }
            return(changed);
        }