Пример #1
0
        // JArray 삽입시 인덱스 수정
        void refreshIndex()
        {
            if (this.value_token_type != JTokenType.Array)
            {
                return;
            }

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

            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++;
            }
        }
Пример #2
0
        public void refreshJsonTree(JToken jtok_root)
        {
            // 변환
            JsonTreeViewItem root_jtree = JsonTreeViewItem.convertToTreeViewItem(jtok_root);

            if (root_jtree == null)
            {
                return;
            }

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

            // 추가
            //TextBlock tblock = new TextBlock();
            //tblock.Text = JsonInfo.current.Filename;
            //root_jtree.Header.Children.Insert(0, tblock);
            //json_tree_view.Items.Add(root_jtree);

            // 추가
            Label label = new Label();

            label.VerticalAlignment = VerticalAlignment.Center;
            label.Content           = JsonTreeViewItem.Filename;
            root_jtree.Header.Children.Insert(0, label);
            int MAX_WIDTH_TREE = Size.WIDTH_TEXTBOX + Size.MARGIN_TEXTBOX + Size.WIDTH_VALUEPANEL + 50;

            root_jtree.Header.Width = MAX_WIDTH_TREE;
            json_tree_view.Items.Add(root_jtree);

            JsonTreeViewItem.Root = root_jtree;
        }
Пример #3
0
        public static JObject convertToJToken(JsonTreeViewItem root_tvi)
        {
            if (root_tvi == null)
            {
                return(null);
            }

            /*
             * MyTreeViewItem.Items     --N-> MyTreeViewItem * N + Add_Button
             * MyTreeViewItem.Header     --1-> JsonPanel_Header
             * JsonPanel_Header            --3-> TextBox * 2 (key, val or val.type) + Delete_Button
             * MyTreeViewItem.Items => MyTreeViewItem 타입의 자식개념, MyTreeViewItem.Header => JsonPanel 타입의 해당 property
             */
            /*
             * JToken 상위 클래스
             * JObject         --N-> JProperty
             * JProperty        --1->    {JObject}
             *              {JArray } 중 하나
             *              {JValue }
             * JArray             --N-> JObject
             *      children
             */

            // tree root 는 object 로 시작
            JObject jtok_root = new JObject();

            convertToJToken_recursive(root_tvi, jtok_root);

            return(jtok_root);
        }
Пример #4
0
        protected override void OnChecked(RoutedEventArgs e)
        {
            // this 는 JsonTreeViewItem.Children 에 위치
            JsonTreeViewItem tvi = this.Parent as JsonTreeViewItem;

            if (tvi == null)
            {
                return;
            }

            tvi.visibleMore();
        }
Пример #5
0
        protected override void OnUnchecked(RoutedEventArgs e)
        {
            // this 는 JsonTreeViewItem.Children 에 위치
            JsonTreeViewItem tvi = this.Parent as JsonTreeViewItem;

            if (tvi == null)
            {
                return;
            }
            base.OnUnchecked(e);

            tvi.hideMore();
        }
Пример #6
0
        public void hideMore()
        {
            for (int i = IDX_MOREBUTTON; i < this.Items.Count; i++)
            {
                JsonTreeViewItem ui = this.Items[i] as JsonTreeViewItem;
                if (ui == null)
                {
                    continue;
                }

                ui.Visibility = Visibility.Collapsed;
            }
        }
Пример #7
0
        public void visibleMore()
        {
            for (int i = 0; i < this.Items.Count; i++)
            {
                JsonTreeViewItem ui = this.Items[i] as JsonTreeViewItem;
                if (ui == null)
                {
                    continue;
                }

                ui.Visibility = Visibility.Visible;
            }
        }
Пример #8
0
        protected override void OnDrop(DragEventArgs e)
        {
            Log.PrintConsole("KeyTextBox.OnDrop()");
            JsonTreeViewItem tvi_parent = this.Parent as JsonTreeViewItem;

            if (tvi_parent == null)
            {
                return;
            }

            tvi_parent.PublicDrop(e);
            base.OnDrop(e);
        }
Пример #9
0
        public static void convertToTreeView_recursive(JsonTreeViewItem parent_tvi, JToken jtok)
        {
            if (jtok == null)
            {
                return;
            }

            JsonTreeViewItem child_tvi = addUIToJsonTreeItem(parent_tvi, jtok);

            foreach (var v in jtok.Children())
            {
                convertToTreeView_recursive(child_tvi, v);
            }
        }
Пример #10
0
        // Json 버튼은 JsonTreeViewItem.Header.children 에 존재
        protected override void OnClick()
        {
            base.OnClick();
            JsonTreeViewItem this_jtvi = (this.Parent as Grid).Parent as JsonTreeViewItem;

            if (this_jtvi == null)
            {
                return;
            }

            if (this_jtvi != null)
            {
                this_jtvi.Remove();
            }
            //FileContoller.write(JsonInfo.current.filename, JsonInfo.current.jtok_root.ToString());
        }
Пример #11
0
        private bool CheckJson()
        {
            // 로드된 오브젝트가 없으면 실행 x
            if (json_tree_view.Items.Count < 1)
            {
                return(false);
            }
            JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem;

            if (root == null)
            {
                return(false);
            }

            return(true);
        }
Пример #12
0
        public void PublicMouseMove(MouseEventArgs e)
        {
            //Log.Print(linked_jtoken);
            base.OnMouseMove(e);
            if (e.LeftButton == MouseButtonState.Pressed &&
                JsonTreeViewItem.selected_tvi != null)
            {
                Log.PrintConsole(this.Name + ", called DoDragDrop(" + JsonTreeViewItem.selected_tvi.Name + ")");
                DataObject data = new DataObject();
                data.SetData("Object", JsonTreeViewItem.selected_tvi);
                JsonTreeViewItem.selected_tvi = null;
                Log.PrintConsole(this.GetType().ToString());
                DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
            }

            e.Handled = true;
        }
Пример #13
0
 private void NewJsonFile()
 {
     JsonTreeViewItem.Clear();
     //if(JSonInfo.current.IsModify_tree)
     //{
     //	MessageBoxResult mbr = MessageBox.Show("변경사항을 저장하겠습니까?", "저장", MessageBoxButton.YesNoCancel);
     //	switch(mbr)
     //	{
     //		case MessageBoxResult.Yes:
     //			Btn_save_jtree_Click(sender, e);
     //			break;
     //		case MessageBoxResult.Cancel:
     //			return;
     //	}
     //}
     //JsonInfo.current.Jtok_root = new JObject();
     refreshJsonTree(new JObject());
 }
Пример #14
0
        public static JsonTreeViewItem convertToTreeViewItem(JToken jtok_root)
        {
            if (jtok_root == null)
            {
                WindowMain.current.ShowMessageDialog("Json Context Error!!", JsonController.Error_message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative);
                //MessageBox.Show(JsonController.Error_message, "JSon Context Error");
                return(null);
            }
            // object 로 시작.
            JsonTreeViewItem jtree_root = new JsonTreeViewItem();

            jtree_root.HorizontalAlignment = HorizontalAlignment.Left;

            //JsonInfo.current.Jtok_root = jtok_root;
            //JsonInfo.current.Jtree_root = jtree_root;
            convertToTreeView_recursive(jtree_root, jtok_root);
            return(jtree_root);
        }
Пример #15
0
        private void SaveFile(string path)
        {
            if (!CheckJson())
            {
                return;
            }

            JToken Jtok_root = JsonTreeViewItem.convertToJToken(json_tree_view.Items[0] as JsonTreeViewItem);

            if (Jtok_root != null && FileContoller.Write(path, Jtok_root.ToString()))
            {
                WindowMain.current.ShowMessageDialog("Save", path + " 파일이 저장되었습니다.");
            }
            else
            {
                string caption = "Save Error";
                string message = path + " 파일을 저장하는데 문제가 생겼습니다.";
                WindowMain.current.ShowMessageDialog(caption, message);
                Console.WriteLine("[" + caption + "] " + message);
            }
        }
Пример #16
0
        // Json 버튼은 JsonTreeViewItem.Header.children 에 존재
        protected override void OnClick()
        {
            base.OnClick();
            JsonTreeViewItem this_jtvi = (this.Parent as Grid).Parent as JsonTreeViewItem;

            if (this_jtvi == null)
            {
                return;
            }

            if (this_jtvi.value_token_type == JTokenType.Array)
            {
                JsonTreeViewItem child_tvi = new JsonTreeViewItem();
                KeyTextBox       tb_key    = new KeyTextBox(this_jtvi.Actual_child_count.ToString(), false);
                child_tvi.Header.AddItem(tb_key);
                KeyTextBox tb_type = new KeyTextBox("object", false);
                child_tvi.Header.AddItem(tb_type);
                child_tvi.value_token_type = JTokenType.Object;

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

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

                JsonTreeViewItem.convertToTreeView_recursive(this_jtvi, new JProperty(wnd_add.key, wnd_add.value));
            }
        }
Пример #17
0
        private void OnClickButtonViewJsonFile(object sender, RoutedEventArgs e)
        {
            if (JsonTreeViewItem.Path == null)
            {
                return;
            }

            JsonTreeViewItem root = json_tree_view.Items[0] as JsonTreeViewItem;

            if (root == null)
            {
                return;
            }

            Window_ViewFile w = new Window_ViewFile(JsonTreeViewItem.convertToJToken(root).ToString(), JsonTreeViewItem.Path);

            //Window_ViewFile w = new Window_ViewFile(FileContoller.read(JsonInfo.current.Path), JsonInfo.current.Path);

            if (w.ShowDialog() == true)
            {
                refreshJsonTree(JsonController.parseJson(w.tb_file.Text));
            }
        }
Пример #18
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);
        }
Пример #19
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;
                }
            }
        }
Пример #20
0
        public void PublicDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            // bubble (자식부터 부모요소로 이벤트 전달 방식) 이므로 처음 수행할때 (제일 자식에서 이벤트를 받았을 때), 이벤트 수행처리.
            e.Handled = true;

            // If the DataObject contains string data, extract it.
            if (e.Data.GetDataPresent("Object"))
            {
                Object data_obj = (Object)e.Data.GetData("Object");

                JsonTreeViewItem tvi_src = data_obj as JsonTreeViewItem;
                if (tvi_src == null)
                {
                    return;
                }

                // dst 의 조상중에 src 가 있나 체크 & dst == src 인지 체크
                JsonTreeViewItem tmp_parent = this;
                while (tmp_parent != null)
                {
                    if (tmp_parent == tvi_src)
                    {
                        return;
                    }

                    tmp_parent = tmp_parent.Parent as JsonTreeViewItem;
                }

                JsonTreeViewItem tvi_parent     = this.Parent as JsonTreeViewItem;
                JsonTreeViewItem tvi_src_parent = tvi_src.Parent as JsonTreeViewItem;
                if (tvi_parent == null || tvi_src_parent == null)
                {
                    return;
                }

                // JArray 타입과 다른타입과는 드래그앤드롭 불가. (src==JArray && dst==JArray) 이거나 (src != JArray && dst==JArray) 일떄 수행
                if ((tvi_parent.value_token_type == JTokenType.Array && tvi_src_parent.value_token_type != JTokenType.Array) ||
                    (tvi_parent.value_token_type != JTokenType.Array && tvi_src_parent.value_token_type == JTokenType.Array))
                {
                    return;
                }

                // 중복 체크
                if (tvi_parent.value_token_type != JTokenType.Array && tvi_src_parent.value_token_type != JTokenType.Array &&
                    tvi_parent != tvi_src_parent &&
                    tvi_parent.checkDuplication(tvi_src) < 0)
                {
                    return;
                }

                // remove
                bool ischecked_more_button = false;
                if (tvi_parent.button_more != null)
                {
                    ischecked_more_button = tvi_parent.button_more.IsChecked.Value;
                }

                int idx_insert = tvi_parent.Items.IndexOf(this);
                tvi_src.Remove();

                // insert
                tvi_parent.ChildAddItem(tvi_src, idx_insert);
                if (tvi_parent.button_more != null)
                {
                    tvi_parent.button_more.IsChecked = ischecked_more_button;
                }
            }
        }
Пример #21
0
 public void PublicMouseLeftButtonDown(MouseButtonEventArgs e)
 {
     base.OnMouseLeftButtonDown(e);
     selected_tvi = this;
     e.Handled    = true;
 }
Пример #22
0
        static JsonTreeViewItem addUIToJsonTreeItem(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.ChildAddItem(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.ChildAddItem(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.PrintConsole("[error] undefined type = " + jtok.GetType());
                return(parent_tvi);
            }
        }