示例#1
0
        // Json 버튼은 JsonTreeViewItem.Header.children 에 존재
        protected override void OnClick()
        {
            base.OnClick();

            string message = "";
            JsonTreeViewItemHeader header = this.Parent as JsonTreeViewItemHeader;

            if (header != null)
            {
                if (header.Children.Count > 0)
                {
                    JsonTextBox tb = header.Children[0] as JsonTextBox;
                    if (tb != null)
                    {
                        message += "Key = " + tb.Text + "\r";
                    }
                }
            }
            message += "선택된 항목을 삭제하시겠습니까?\r(하위항목도 같이 삭제됩니다.)";
            WindowMain.current.ShowMessageDialog("Delete", message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.AffirmativeAndNegative, Delete);
        }
示例#2
0
        // 삽입 시 중복 체크
        int checkDuplication(JsonTreeViewItem add_tvi)
        {
            if (add_tvi == null)
            {
                return(1);
            }

            JsonTextBox add_tb = add_tvi.Header.Children[0] as JsonTextBox;

            if (add_tb == null)
            {
                return(1);
            }

            // 중복 비교
            for (int i = 0; i < this.Items.Count; i++)
            {
                JsonTreeViewItem tvi = this.Items[i] as JsonTreeViewItem;
                if (tvi == null)
                {
                    continue;
                }

                JsonTextBox tb = tvi.Header.Children[0] as JsonTextBox;
                if (tb == null)
                {
                    continue;
                }
                // 키중복이면 삽입 x
                if (tb.Text == add_tb.Text)
                {
                    return(-1);
                }
            }
            return(0);
        }
示例#3
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;
                ValuePanel  panel_value = pan.Children[1] as ValuePanel;

                switch (panel_value.type)
                {
                case JTokenType.Object:
                {
                    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 JTokenType.Array:
                {
                    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;

                default:
                {
                    JProperty jprop = new JProperty(tb_key.Text, new JValue(panel_value.value));
                    (cur_jtok as JObject).Add(jprop);
                }
                break;
                }
            }
        }