Exemplo n.º 1
0
        void refreshIndex()
        {
            if (this.type != JsonType.JArray)
            {
                return;
            }

            //if(start_idx < 0 || start_new_idx < 0)
            //	return;

            // JArray 삽입시 인덱스 수정
            int cnt = this.Items.Count;

            for (int i = 0, newidx = 0; i < cnt; i++)
            {
                JsonTreeViewItem tvi = this.Items[i] as JsonTreeViewItem;
                if (tvi == null)
                {
                    continue;
                }

                KeyTextBox tb = tvi.Header.Children[0] as KeyTextBox;
                if (tb == null)
                {
                    continue;
                }

                tb.Text = newidx.ToString();
                newidx++;
            }
        }
Exemplo n.º 2
0
        static JsonTreeViewItem addToJsonTree(JsonTreeViewItem parent_tvi, JToken jtok)
        {
            if (jtok is JObject)
            {
                JObject jobj = jtok as JObject;
                if (jobj.Parent == null)
                {
                    return(parent_tvi);
                }
                if (jobj.Parent != null && jobj.Parent is JArray)
                {
                    JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                    parent_tvi.AddItem(child_tvi);
                    KeyTextBox tb_key = new KeyTextBox((jobj.Parent as JArray).IndexOf(jobj).ToString(), false);
                    child_tvi.Header.AddItem(tb_key);
                    child_tvi.type = JsonType.JObject;
                    parent_tvi     = child_tvi;
                }

                KeyTextBox tb_type = new KeyTextBox("object", false);
                parent_tvi.Header.AddItem(tb_type);
                parent_tvi.type = JsonType.JObject;
                return(parent_tvi);
            }
            else if (jtok is JProperty)
            {
                JProperty        jprop     = jtok as JProperty;
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                parent_tvi.AddItem(child_tvi);

                KeyTextBox tb_key = new KeyTextBox(jprop.Name);
                child_tvi.Header.AddItem(tb_key);

                return(child_tvi);
            }
            else if (jtok is JValue)
            {
                JValue jval = jtok as JValue;

                string       data     = jval.ToString();
                ValueTextBox tb_value = new ValueTextBox(data);
                parent_tvi.Header.AddItem(tb_value);

                parent_tvi.Header.addButtn.Visibility = Visibility.Hidden;
                //parent_tvi.Items.Clear();
                return(parent_tvi);
            }
            else if (jtok is JArray)
            {
                KeyTextBox tb_type = new KeyTextBox("array", false);
                parent_tvi.Header.AddItem(tb_type);
                parent_tvi.type = JsonType.JArray;
                return(parent_tvi);
            }
            else
            {
                Console.WriteLine("[error] undefined type = " + jtok.GetType());
                return(parent_tvi);
            }
        }
Exemplo n.º 3
0
        public void refreshJsonTree(JToken jtok_root)
        {
            JsonTreeViewItem root_jtree = JsonTreeViewItem.convertToTreeViewItem(jtok_root);

            if (root_jtree == null)
            {
                return;
            }

            // 삭제
            json_tree_view.Items.Clear();

            KeyTextBox tb = new KeyTextBox(JsonInfo.current.Filename, false);

            root_jtree.Header.Children.Insert(0, tb);
            json_tree_view.Items.Add(root_jtree);
        }
Exemplo n.º 4
0
        // Json 버튼은 JsonTreeViewItem.Header.children 에 존재
        protected override void OnClick()
        {
            base.OnClick();
            JsonTreeViewItemHeader jtvih = this.Parent as JsonTreeViewItemHeader;

            if (jtvih == null)
            {
                return;
            }
            JsonTreeViewItem jtvi = jtvih.Parent as JsonTreeViewItem;

            if (jtvi == null)
            {
                return;
            }

            if (jtvi.type == JsonTreeViewItem.JsonType.JArray)
            {
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                KeyTextBox       tb_key    = new KeyTextBox(jtvi.getCountChildProperty().ToString(), false);
                child_tvi.Header.AddItem(tb_key);
                KeyTextBox tb_type = new KeyTextBox("object", false);
                child_tvi.Header.AddItem(tb_type);
                child_tvi.type = JsonTreeViewItem.JsonType.JObject;

                jtvi.AddItem(child_tvi);
            }
            else
            {
                // window_addJson showdialog()
                Window_AddJsonItem popup = new Window_AddJsonItem();
                Point pt = this.PointToScreen(new Point(0, 0));
                popup.Left = pt.X;
                popup.Top  = pt.Y;

                // cancel return
                if (popup.ShowDialog() != true)
                {
                    return;
                }

                JsonTreeViewItem.convertToTreeView_recursive(jtvi, new JProperty(popup.key, popup.value));
            }

            //JToken tmp = jtvi.Parent;
            //// tmp == root 일때
            //if(tmp is JObject)
            //	;
            //else
            //{
            //	JProperty jprop = tmp as JProperty;
            //	tmp = jprop.Value;
            //}
            //JToken add_jtok = null;
            //if(tmp is JArray)
            //{
            //	JArray jarr = tmp as JArray;
            //	// add Jtok_root
            //	add_jtok = new JObject();
            //	jarr.Add(add_jtok);
            //}
            //else if(tmp is JObject)
            //{
            //	JObject jobj = tmp as JObject;
            //	// window_addJson showdialog()
            //	popup_AddJsonItem popup = new popup_AddJsonItem();
            //	Point pt = sender.PointToScreen(new Point(0, 0));
            //	popup.Left = pt.X;
            //	popup.Top = pt.Y;

            //	// cancel return
            //	if(popup.ShowDialog() != true)
            //		return;

            //	foreach(JProperty v in jobj.Properties())
            //	{
            //		// 키 중복
            //		if(v.Name == popup.key)
            //			return;
            //	}

            //	// ok return & add Jtok_root
            //	add_jtok = new JProperty(popup.key, popup.value);
            //	jobj.Add(add_jtok);

            //}

            //// add to jtree_root
            //if(add_jtok != null)
            //	makeTree(this, add_jtok);
            ////tvi.Add(sender as JsonButton, convertToTreeView_recursive);
            ////FileContoller.write(JSonInfo.current.filename, JSonInfo.current.jtok_root.ToString());
        }
Exemplo n.º 5
0
        static void convertToJToken_recursive(JsonTreeViewItem tvi_cur, JObject jobj_cur)
        {
            if (tvi_cur == null || jobj_cur == null)
            {
                return;
            }

            JToken cur_jtok = jobj_cur;

            // 여기서부터는 property 로 시작
            foreach (var v in tvi_cur.Items)
            {
                JsonTreeViewItem tvi_child = v as JsonTreeViewItem;
                if (tvi_child == null)
                {
                    continue;
                }

                JsonTreeViewItemHeader pan = tvi_child.Header as JsonTreeViewItemHeader;
                if (pan == null)
                {
                    continue;
                }

                // pan(MyTreeViewItem.Header) = key, val or val.type, button
                JsonTextBox tb_key = pan.Children[0] as JsonTextBox;
                JsonTextBox tb_val = pan.Children[1] as JsonTextBox;

                if (tb_val is KeyTextBox)
                {
                    KeyTextBox tb_type = tb_val as KeyTextBox;
                    switch (tvi_child.type)
                    {
                    case JsonTreeViewItem.JsonType.JObject:
                    {
                        JObject   jobj  = new JObject();
                        JProperty jprop = new JProperty(tb_key.Text, jobj);
                        (cur_jtok as JObject).Add(jprop);
                        convertToJToken_recursive(tvi_child, jobj);
                    }
                    break;

                    case JsonTreeViewItem.JsonType.JArray:
                    {
                        JArray    jarr  = new JArray();
                        JProperty jprop = new JProperty(tb_key.Text, jarr);
                        (cur_jtok as JObject).Add(jprop);
                        for (int i = 0; i < tvi_child.Items.Count; i++)
                        {
                            JObject jobj = new JObject();
                            jarr.Add(jobj);
                            convertToJToken_recursive(tvi_child.Items[i] as JsonTreeViewItem, jobj);
                        }
                    }
                    break;
                    }
                }
                else
                {
                    JProperty jprop = new JProperty(tb_key.Text, tb_val.Text);
                    (cur_jtok as JObject).Add(jprop);
                }
            }
        }
Exemplo n.º 6
0
        static JsonTreeViewItem addToJsonTree(JsonTreeViewItem parent_tvi, JToken jtok)
        {
            if (jtok is JObject)
            {
                JObject jobj = jtok as JObject;
                if (jobj.Parent == null)
                {
                    return(parent_tvi);
                }
                if (jobj.Parent != null && jobj.Parent is JArray)
                {
                    JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                    parent_tvi.AddItem(child_tvi);
                    KeyTextBox tb_key = new KeyTextBox((jobj.Parent as JArray).IndexOf(jobj).ToString(), false);
                    child_tvi.Header.AddItem(tb_key);
                    child_tvi.value_token_type = JTokenType.Object;
                    parent_tvi = child_tvi;
                }

                //KeyTextBox tb_type = new KeyTextBox("object", false);
                //parent_tvi.Header.AddItem(tb_type);
                //parent_tvi.value_token_type = JTokenType.Object;
                //return parent_tvi;
                ValuePanel panel_value = new ValuePanel(JTokenType.Object, "object");
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = JTokenType.Object;
                return(parent_tvi);
            }
            else if (jtok is JProperty)
            {
                JProperty        jprop     = jtok as JProperty;
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                parent_tvi.AddItem(child_tvi);

                KeyTextBox tb_key = new KeyTextBox(jprop.Name);
                child_tvi.Header.AddItem(tb_key);

                return(child_tvi);
            }
            else if (jtok is JValue)
            {
                JValue     jval        = jtok as JValue;
                ValuePanel panel_value = new ValuePanel(jval.Type, jval.Value);
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = jval.Type;

                parent_tvi.Header.addButtn.Visibility = Visibility.Hidden;
                //parent_tvi.Items.Clear();
                return(parent_tvi);
            }
            else if (jtok is JArray)
            {
                //KeyTextBox tb_type = new KeyTextBox("array", false);
                //parent_tvi.Header.AddItem(tb_type);
                //parent_tvi.value_token_type = JTokenType.Array;
                //return parent_tvi;
                ValuePanel panel_value = new ValuePanel(JTokenType.Array, "array");
                parent_tvi.Header.AddItem(panel_value);
                parent_tvi.value_token_type = JTokenType.Array;
                return(parent_tvi);
            }
            else
            {
                Log.Print("[error] undefined type = " + jtok.GetType());
                return(parent_tvi);
            }
        }