Exemplo n.º 1
0
        private void Add(Func <string> source)
        {
            if (treeView.SelectedNode == null)
            {
                Message("Nothing selected." + Environment.NewLine);
                return;
            }

            if (!(treeView.SelectedNode.Tag is ValueInfo))
            {
                Message("Cannot add to this node." + Environment.NewLine);
                return;
            }

            ValueInfo valueInfo = (ValueInfo)treeView.SelectedNode.Tag;

            DatatreeDotNet.dt_type_t t = DatatreeDotNet.dt_value_type(valueInfo.Value);
            if (t == DatatreeDotNet.dt_type_t.DT_ARRAY)
            {
                string ipt = source();

                IntPtr o = IntPtr.Zero;
                DatatreeDotNet.dt_create_value(datatree, ref o, OnError, ipt);
                uint idx = 0;
                DatatreeDotNet.dt_add_array_elem
                (
                    datatree,
                    DatatreeDotNet.dt_value_data(valueInfo.Value),
                    o,
                    ref idx
                );
            }
            else if (t == DatatreeDotNet.dt_type_t.DT_OBJECT)
            {
                string ipt = source();

                IntPtr k = IntPtr.Zero;
                IntPtr v = IntPtr.Zero;
                DatatreeDotNet.dt_create_value(datatree, ref k, OnError, ipt);
                DatatreeDotNet.dt_create_value(datatree, ref v, OnError, "null");
                uint idx = 0;
                DatatreeDotNet.dt_status_t status = DatatreeDotNet.dt_add_object_member
                                                    (
                    datatree,
                    DatatreeDotNet.dt_value_data(valueInfo.Value),
                    k,
                    v,
                    ref idx
                                                    );
                if (status == DatatreeDotNet.dt_status_t.DT_KEY_EXISTS)
                {
                    Message("A key-value pair with the same key already exists." + Environment.NewLine);
                    return;
                }
            }
            else
            {
                Message("Cannot add to this node." + Environment.NewLine);
                return;
            }

            treeView.SelectedNode.Nodes.Add(new TreeNode());

            UpdateNodes();

            EditState = EditStates.OpenedNotSaved;
        }