|
|
@ -150,7 +150,6 @@ func (g *Gui) LoadJSON() {
|
|
|
|
log.Println(fmt.Sprintf("can't open file: %s", err))
|
|
|
|
log.Println(fmt.Sprintf("can't open file: %s", err))
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i, err := UnMarshalJSON(file)
|
|
|
|
i, err := UnMarshalJSON(file)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -216,7 +215,7 @@ func (g *Gui) SaveJSONToFile(file string) error {
|
|
|
|
enc := json.NewEncoder(&buf)
|
|
|
|
enc := json.NewEncoder(&buf)
|
|
|
|
enc.SetIndent("", " ")
|
|
|
|
enc.SetIndent("", " ")
|
|
|
|
|
|
|
|
|
|
|
|
if err := enc.Encode(g.MakeJSON(g.Tree.OriginRoot)); err != nil {
|
|
|
|
if err := enc.Encode(g.makeJSON(g.Tree.GetRoot())); err != nil {
|
|
|
|
log.Println(fmt.Sprintf("can't marshal json: %s", err))
|
|
|
|
log.Println(fmt.Sprintf("can't marshal json: %s", err))
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -229,7 +228,7 @@ func (g *Gui) SaveJSONToFile(file string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *Gui) MakeJSON(node *tview.TreeNode) interface{} {
|
|
|
|
func (g *Gui) makeJSON(node *tview.TreeNode) interface{} {
|
|
|
|
ref := node.GetReference().(Reference)
|
|
|
|
ref := node.GetReference().(Reference)
|
|
|
|
children := node.GetChildren()
|
|
|
|
children := node.GetChildren()
|
|
|
|
|
|
|
|
|
|
|
@ -237,25 +236,22 @@ func (g *Gui) MakeJSON(node *tview.TreeNode) interface{} {
|
|
|
|
case Object:
|
|
|
|
case Object:
|
|
|
|
i := make(map[string]interface{})
|
|
|
|
i := make(map[string]interface{})
|
|
|
|
for _, n := range children {
|
|
|
|
for _, n := range children {
|
|
|
|
i[n.GetText()] = g.MakeJSON(n)
|
|
|
|
i[n.GetText()] = g.makeJSON(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
return i
|
|
|
|
case Array:
|
|
|
|
case Array:
|
|
|
|
var i []interface{}
|
|
|
|
var i []interface{}
|
|
|
|
for _, n := range children {
|
|
|
|
for _, n := range children {
|
|
|
|
i = append(i, g.MakeJSON(n))
|
|
|
|
i = append(i, g.makeJSON(n))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
return i
|
|
|
|
case Key:
|
|
|
|
case Key:
|
|
|
|
if len(node.GetChildren()) == 0 {
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
v := node.GetChildren()[0]
|
|
|
|
v := node.GetChildren()[0]
|
|
|
|
if v.GetReference().(Reference).JSONType == Value {
|
|
|
|
if v.GetReference().(Reference).JSONType == Value {
|
|
|
|
return g.parseValue(v)
|
|
|
|
return g.parseValue(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
|
|
return map[string]interface{}{
|
|
|
|
node.GetText(): g.MakeJSON(v),
|
|
|
|
node.GetText(): g.makeJSON(v),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -351,6 +347,7 @@ func (g *Gui) EditWithEditor() {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
defer os.RemoveAll(f.Name())
|
|
|
|
|
|
|
|
|
|
|
|
if err := g.SaveJSONToFile(f.Name()); err != nil {
|
|
|
|
if err := g.SaveJSONToFile(f.Name()); err != nil {
|
|
|
|
log.Println(fmt.Sprintf("can't write to temp file: %s", err))
|
|
|
|
log.Println(fmt.Sprintf("can't write to temp file: %s", err))
|
|
|
@ -422,7 +419,6 @@ func (g *Gui) EditWithEditor() {
|
|
|
|
g.Message(err.Error(), "main", func() {})
|
|
|
|
g.Message(err.Error(), "main", func() {})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i, err := UnMarshalJSON(f)
|
|
|
|
i, err := UnMarshalJSON(f)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -431,7 +427,6 @@ func (g *Gui) EditWithEditor() {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
os.RemoveAll(f.Name())
|
|
|
|
|
|
|
|
g.Tree.UpdateView(g, i)
|
|
|
|
g.Tree.UpdateView(g, i)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|