ide: Json viewer

git-svn-id: svn://ultimatepp.org/upp/trunk@6538 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-08 10:55:56 +00:00
parent cb975732af
commit 1f826362d2
7 changed files with 117 additions and 0 deletions

97
uppsrc/ide/Json.cpp Normal file
View file

@ -0,0 +1,97 @@
#include "ide.h"
struct JsonView : TopWindow {
TreeCtrl tree;
int AddNode(int parent_id, const Value& id, const String& name, const Value& v);
void Load(const char *json);
void CopyPath();
void Serialize(Stream& s);
typedef JsonView CLASSNAME;
JsonView();
};
int JsonView::AddNode(int parent_id, const Value& id, const String& name, const Value& v)
{
if(v.Is<ValueMap>()) {
ValueMap m = v;
parent_id = tree.Add(parent_id, IdeImg::JsonStruct(), id, "[G1 [* " + name);
for(int i = 0; i < m.GetCount(); i++)
AddNode(parent_id, m.GetKey(i), "[@B \1" + String(m.GetKey(i)) + "\1:]", m.GetValue(i));
}
else
if(v.Is<ValueArray>()) {
parent_id = tree.Add(parent_id, IdeImg::JsonArray(), id, "[G1 [* " + name);
for(int i = 0; i < v.GetCount(); i++)
AddNode(parent_id, i, "[@c " + AsString(i) + ":]", v[i]);
}
else {
String qtf = "[G1 [* " + name + "]";
Image img = IdeImg::JsonNumber();
if(IsString(v)) {
img = IdeImg::JsonString();
if(IsNull(v))
qtf << "[*@g Null";
else
qtf << "[@r \1 " + AsCString(String(v));
}
else {
if(v.Is<bool>())
img = IdeImg::JsonBool();
if(IsNull(v))
qtf << "[*@g Null";
else
qtf << "\1 " + AsString(v);
}
parent_id = tree.Add(parent_id, img, id, qtf);
}
return parent_id;
}
void JsonView::Load(const char *json)
{
tree.Open(AddNode(0, Null, "JSON", ParseJSON(json)));
}
void JsonView::CopyPath()
{
int id = tree.GetCursor();
String path;
while(id) {
Value k = tree.Get(id);
if(!IsNull(k)) {
if(IsNumber(k))
path = "[" + AsString(k) + "]" + path;
if(IsString(k))
path = "[" + AsCString(String(k)) + "]" + path;
}
id = tree.GetParent(id);
}
WriteClipboardText(path);
}
void JsonView::Serialize(Stream& s)
{
int version = 0;
s / version;
SerializePlacement(s);
}
JsonView::JsonView()
{
Add(tree.SizePos()); tree.SetDisplay(QTFDisplay()); tree.NoRoot(); Sizeable().Zoomable();
Icon(IdeCommonImg::xml());
tree.WhenLeftDouble = THISBACK(CopyPath);
}
void Ide::Json()
{
JsonView dlg;
LoadFromGlobal(dlg, "JSONview");
dlg.Load(editor.IsSelection() ? editor.GetSelection() : editor.Get());
dlg.Execute();
StoreToGlobal(dlg, "JSONview");
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

@ -968,6 +968,7 @@ public:
void CtrlClick(int pos);
void Qtf();
void Xml();
void Json();
void ConsoleMenu(Bar& menu);

View file

@ -86,6 +86,11 @@ IMAGE_ID(XmlText)
IMAGE_ID(XmlPI)
IMAGE_ID(XmlDecl)
IMAGE_ID(XmlComment)
IMAGE_ID(JsonStruct)
IMAGE_ID(JsonArray)
IMAGE_ID(JsonString)
IMAGE_ID(JsonNumber)
IMAGE_ID(JsonBool)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,152,141,153,131,32,12,134,29,161,35,220,116,157,163,163,117,179,92,181,141,66,126,72,20,17,84,194,147,167)
@ -2339,3 +2344,14 @@ IMAGE_DATA(142,245,214,96,26,195,192,27,219,182,139,137,246,36,177,182,120,151,7
IMAGE_DATA(137,19,145,79,29,35,16,39,17,31,23,67,135,143,235,143,161,134,44,231,37,171,245,17,138,37,241,134,182,255,1,251)
IMAGE_DATA(141,23,93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(1760, 17)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,148,225,13,2,33,12,133,25,65,127,146,56,172,83,56,153,3,176,9,106,204,157,23,210,7,175,165,42,158)
IMAGE_DATA(52,121,73,115,161,31,45,237,53,28,195,33,252,145,101,32,58,62,95,179,40,146,179,57,159,129,95,229,136,49,10,14)
IMAGE_DATA(60,143,190,21,156,102,188,23,167,17,239,245,30,94,125,17,235,50,204,199,202,1,26,219,118,188,76,80,67,88,61,25)
IMAGE_DATA(247,89,48,9,49,194,249,165,218,183,22,3,222,59,25,102,70,111,95,172,243,209,63,167,99,216,142,151,137,100,189,77)
IMAGE_DATA(162,199,165,151,241,169,28,150,159,165,244,61,226,127,233,29,190,153,131,66,99,219,92,38,186,101,114,202,23,74,189,12)
IMAGE_DATA(38,62,198,40,250,44,227,17,35,73,91,67,45,15,182,14,148,135,230,29,81,30,26,198,59,122,217,98,40,52,182,205)
IMAGE_DATA(101,162,91,38,41,37,74,45,198,246,46,75,252,114,70,242,189,24,236,59,212,106,209,48,144,207,196,123,50,202,90,52)
IMAGE_DATA(241,150,121,80,104,104,187,1,173,122,28,98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(256, 5)

View file

@ -86,6 +86,7 @@ KEY(BROWSETOPICS, "Help & Topics", K_F1)
KEY(CALC, "Calculator", K_CTRL_E)
KEY(QTF, "QTF designer", K_ALT_Q)
KEY(XML, "XML view", K_ALT_X)
KEY(JSON, "JSON view", K_ALT_N)
KEY(ASSIST, "Assist", ' '|K_CTRL)
KEY(ABBR, "Complete abbreviation", K_CTRL_PERIOD)
KEY(DCOPY, "Copy as definition/declaration", K_ALT_C)

View file

@ -68,6 +68,7 @@ file
Abbr.cpp,
Qtf.cpp,
Xml.cpp,
Json.cpp,
Update.cpp,
Compile readonly separator,
Methods.cpp,

View file

@ -527,6 +527,7 @@ void Ide::BrowseMenu(Bar& menu) {
.Check(IsBottomShown() && btabs.GetCursor() == BCALC);
menu.AddMenu(AK_QTF, IdeImg::qtf(), THISBACK(Qtf));
menu.AddMenu(!designer, AK_XML, IdeCommonImg::xml(), THISBACK(Xml));
menu.AddMenu(!designer, AK_JSON, IdeCommonImg::json(), THISBACK(Json));
menu.MenuSeparator();
menu.Add(AK_BROWSETOPICS, IdeImg::help(), THISBACK(ShowTopics));
menu.Add(AK_SEARCHTOPICS, THISBACK(SearchTopics));