Exemple #1
0
        private void mnuCopyXML_Click(object sender, EventArgs e)
        {
            JsonViewerTreeNode node = GetSelectedTreeNode();

            if (node != null && node.Tag != null)
            {
                JsonObject obj = node.Tag as JsonObject;
                if (obj.Value is JArray)
                {
                    JsonObject xmlObj = new JsonObject();
                    xmlObj.JsonType = JsonType.Object;
                    xmlObj.Fields.Add(obj);

                    XNode xmlNode = JsonConvert.DeserializeXNode(xmlObj.Value.ToString(), obj.Id);
                    Clipboard.SetText(xmlNode.ToString());
                }
                else if (obj.Value is JObject)
                {
                    XNode xmlNode = JsonConvert.DeserializeXNode(obj.Value.ToString(), obj.Id);
                    Clipboard.SetText(xmlNode.ToString());
                }
                else
                {
                    Clipboard.SetText("<" + obj.Id + ">" + obj.Value.ToString() + "</" + obj.Id + ">");
                }
            }
            else
            {
                Clipboard.SetText("<null />");
            }
        }
Exemple #2
0
        private void InitVisualizers(JsonViewerTreeNode node)
        {
            if (!node.Initialized)
            {
                node.Initialized = true;
                JsonObject jsonObject = node.JsonObject;
                foreach (ICustomTextProvider textVis in _pluginsManager.TextVisualizers)
                {
                    if (textVis.CanVisualize(jsonObject))
                    {
                        node.TextVisualizers.Add(textVis);
                    }
                }

                node.RefreshText();

                foreach (IJsonVisualizer visualizer in _pluginsManager.Visualizers)
                {
                    if (visualizer.CanVisualize(jsonObject))
                    {
                        node.Visualizers.Add(visualizer);
                    }
                }
            }
        }
Exemple #3
0
        private void VisualizeJsonTree(JsonObjectTree tree)
        {
            AddNode(tvJson.Nodes, tree.Root);
            JsonViewerTreeNode node = GetRootNode();

            InitVisualizers(node);
            node.Expand();
            tvJson.SelectedNode = node;
        }
Exemple #4
0
        private void mnuCopy_Click(object sender, EventArgs e)
        {
            JsonViewerTreeNode node = GetSelectedTreeNode();

            if (node != null)
            {
                Clipboard.SetText(node.Text);
            }
        }
Exemple #5
0
        private void mnuCopyValue_Click(object sender, EventArgs e)
        {
            JsonViewerTreeNode node = GetSelectedTreeNode();

            if (node != null && node.JsonObject.Value != null)
            {
                Clipboard.SetText(node.JsonObject.Value.ToString());
            }
        }
Exemple #6
0
        /// <summary>
        /// Copies just the node's value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>Menu item Viewer > Copy Value</remarks>
        /// <!-- JsonViewerTreeNode had to be made public to be accessible here -->
        private void copyValueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Control c;

            c = this.JsonViewer.Controls.Find("tvJson", true)[0];
            JsonViewerTreeNode node = (JsonViewerTreeNode)((TreeView)c).SelectedNode;

            if (node != null && node.JsonObject.Value != null)
            {
                Clipboard.SetText(node.JsonObject.Value.ToString());
            }
        }
Exemple #7
0
        private void mnuCopyName_Click(object sender, EventArgs e)
        {
            JsonViewerTreeNode node = GetSelectedTreeNode();

            if (node != null && node.JsonObject.Id != null)
            {
                JsonObject obj = node.Tag as JsonObject;
                Clipboard.SetText(obj.Id);
            }
            else
            {
                Clipboard.SetText("");
            }
        }
Exemple #8
0
        private void mnuCopyValue_Click(object sender, EventArgs e)
        {
            JsonViewerTreeNode node = GetSelectedTreeNode();

            if (node != null && node.Tag != null)
            {
                JsonObject obj = node.Tag as JsonObject;
                Clipboard.SetText(obj.Value.ToString());
            }
            else
            {
                Clipboard.SetText("null");
            }
        }
Exemple #9
0
        private void VisualizeJsonTree(JsonObjectTree tree)
        {
            if (tree == null)
            {
                return;
            }
            tvJson.Nodes.Clear();
            AddNode(tvJson.Nodes, tree.Root);
            JsonViewerTreeNode node = GetRootNode();

            InitVisualizers(node);
            node.Expand();
            tvJson.SelectedNode = node;
            GC.Collect();
        }
Exemple #10
0
        private void AddNode(TreeNodeCollection nodes, JsonObject jsonObject)
        {
            JsonViewerTreeNode newNode = new JsonViewerTreeNode(jsonObject);

            nodes.Add(newNode);
            newNode.Text               = jsonObject.Text;
            newNode.Tag                = jsonObject;
            newNode.ImageIndex         = (int)jsonObject.JsonType;
            newNode.SelectedImageIndex = newNode.ImageIndex;

            foreach (JsonObject field in jsonObject.Fields)
            {
                AddNode(newNode.Nodes, field);
            }
        }
        private void mnuCopyValue_Click(object sender, EventArgs e)
        {
            JsonViewerTreeNode node = GetSelectedTreeNode();

            if (node != null && node.Tag != null)
            {
                JsonObject obj         = node.Tag as JsonObject;
                string     valueString = obj.Value == null ? "" : (obj.JsonType == JsonType.Value ? JavaScriptConvert.ToString(obj.Value) : JavaScriptConvert.SerializeObject(obj.Value));
                Clipboard.SetText(valueString);
            }
            else
            {
                Clipboard.SetText("");
            }
        }
Exemple #12
0
        private void tvJson_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (_pluginsManager.DefaultVisualizer == null)
            {
                return;
            }

            cbVisualizers.BeginUpdate();
            _updating = true;
            try
            {
                JsonViewerTreeNode node       = (JsonViewerTreeNode)e.Node;
                IJsonVisualizer    lastActive = node.LastVisualizer;
                if (lastActive == null)
                {
                    lastActive = (IJsonVisualizer)cbVisualizers.SelectedItem;
                }
                if (lastActive == null)
                {
                    lastActive = _pluginsManager.DefaultVisualizer;
                }

                cbVisualizers.Items.Clear();
                cbVisualizers.Items.AddRange(node.Visualizers.ToArray());
                int index = cbVisualizers.Items.IndexOf(lastActive);
                if (index != -1)
                {
                    cbVisualizers.SelectedIndex = index;
                }
                else
                {
                    cbVisualizers.SelectedIndex = cbVisualizers.Items.IndexOf(_pluginsManager.DefaultVisualizer);
                }
            }
            finally
            {
                cbVisualizers.EndUpdate();
                _updating = false;
            }
            ActivateVisualizer();
        }
        private void VisualizeJsonTree(JsonObjectTree tree)
        {
            levelNodesCount = new int[20];
            AddNode(tvJson.Nodes, tree.Root);
            JsonViewerTreeNode node = GetRootNode();
            int total = 0;
            int index = 0;

            for (int i = 0; i < 20; i++)
            {
                total += levelNodesCount[i];
                if (total * 18 > tvJson.Bounds.Height * 1)
                {
                    break;
                }
                else
                {
                    index = i;
                }
            }
            expandSubNodes(node, index - 1 < 0?0:index - 1);
            tvJson.SelectedNode = node;
        }
Exemple #14
0
        private void AddNode(TreeNodeCollection nodes, JsonObject jsonObject)
        {
            if(!ckObjectsOnly.Checked || jsonObject.JsonType == JsonType.Object)
            {
                JsonViewerTreeNode newNode = new JsonViewerTreeNode(jsonObject);
                nodes.Add(newNode);

                newNode.Text = GetNodeLabel(jsonObject);
                newNode.Tag = jsonObject;
                newNode.ImageIndex = (int)jsonObject.JsonType;
                newNode.SelectedImageIndex = newNode.ImageIndex;

                foreach(JsonObject field in jsonObject.Fields)
                {
                    AddNode(newNode.Nodes, field);
                }
            }
        }
Exemple #15
0
        private void AddNode(TreeNodeCollection nodes, JsonObject jsonObject)
        {
            JsonViewerTreeNode newNode = new JsonViewerTreeNode(jsonObject);
            nodes.Add(newNode);
            newNode.Text = jsonObject.Text;
            newNode.Tag = jsonObject;
            newNode.ImageIndex = (int)jsonObject.JsonType;
            newNode.SelectedImageIndex = newNode.ImageIndex;

            foreach (JsonObject field in jsonObject.Fields)
            {
                AddNode(newNode.Nodes, field);
            }
        }
Exemple #16
0
        private void btnJumpToNode_Click(object sender, EventArgs e)
        {
            if(!skipSrcSelectionChangedEvent)
            {
                int selectionStart = rtxtParsedSrc.SelectionStart;
                selectionStart += Util.CountMissingCrNl(parsedSrc, rtxtParsedSrc.Text, selectionStart);

                JsonViewerTreeNode node = GetRootNode();
                bool done = false;
                while(!done)
                {
                    JsonViewerTreeNode prevSubNode = null;
                    JsonViewerTreeNode nextNode = null;
                    foreach(TreeNode subNodeBase in node.Nodes)
                    {
                        JsonViewerTreeNode subNode = (JsonViewerTreeNode)subNodeBase;
                        JsonObject jsonObj = subNode.JsonObject;

                        int srcIndexStart = Convert.ToInt32(GetValue(jsonObj, "srcIndexStart"));
                        if(srcIndexStart > selectionStart)
                        {
                            nextNode = prevSubNode;
                            break;
                        }

                        prevSubNode = subNode;
                    }

                    if(nextNode == null)
                    {
                        if(prevSubNode == null)
                            done = true;
                        else
                            node = prevSubNode;
                    }
                    else
                        node = nextNode;
                }

                DehighlightNode(highlightedNode);

                // Go to the node, but then de-select it so the highlight will show
                tvJson.SelectedNode = node;
                tvJson.SelectedNode = null;

                HighlightNode(node);
                highlightedNode = node;

                //TODO: Scroll treeview left/right to make sure node is on-screen (possible?)
                //node.Bounds.Left
                //tvJson.ScrollControlIntoView(node);
                //scrollTarget.Bounds = node.Bounds;
                //scrollTarget.AutoScrollOffset = new Point(scrollTarget.Width, 0);
                //spcViewer2.Panel1.ScrollControlIntoView(scrollTarget);
            }
        }
Exemple #17
0
        private void InitVisualizers(JsonViewerTreeNode node)
        {
            if (!node.Initialized)
            {
                node.Initialized = true;
                JsonObject jsonObject = node.JsonObject;
                foreach (ICustomTextProvider textVis in _pluginsManager.TextVisualizers)
                {
                    if (textVis.CanVisualize(jsonObject))
                        node.TextVisualizers.Add(textVis);
                }

                node.RefreshText();

                foreach (IJsonVisualizer visualizer in _pluginsManager.Visualizers)
                {
                    if (visualizer.CanVisualize(jsonObject))
                        node.Visualizers.Add(visualizer);
                }
            }
        }