Exemplo n.º 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 />");
            }
        }
Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void VisualizeJsonTree(JsonObjectTree tree)
        {
            AddNode(tvJson.Nodes, tree.Root);
            JsonViewerTreeNode node = GetRootNode();

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

            if (node != null)
            {
                Clipboard.SetText(node.Text);
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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("");
            }
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 11
0
        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("");
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
                }
            }
        }