Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
adds collapse/expend all
Browse files Browse the repository at this point in the history
  • Loading branch information
gulyasm committed Mar 27, 2018
1 parent ab58871 commit 50385df
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
20 changes: 20 additions & 0 deletions jsonui.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func main() {
if err := g.SetKeybinding(treeView, 'e', gocui.ModNone, toggleExpand); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding(treeView, 'E', gocui.ModNone, expandAll); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding(treeView, 'C', gocui.ModNone, collapseAll); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", 'h', gocui.ModNone, toggleHelp); err != nil {
log.Panicln(err)
}
Expand All @@ -137,6 +143,8 @@ k/ArrowUp ═ Move a line up
J/PageDown ═ Move 15 line down
K/PageUp ═ Move 15 line up
e ═ Toggle expend/collapse node
E ═ Expand all nodes
C ═ Collapse all nodes
h/? ═ Toggle help message
`

Expand Down Expand Up @@ -288,6 +296,18 @@ func findTreePosition(v *gocui.View) treePosition {
return path[1:]
}

func expandAll(g *gocui.Gui, v *gocui.View) error {
tree.expandAll()
v.Clear()
tree.draw(v, 2, 0)
return nil
}
func collapseAll(g *gocui.Gui, v *gocui.View) error {
tree.collapseAll()
v.Clear()
tree.draw(v, 2, 0)
return nil
}
func toggleExpand(g *gocui.Gui, v *gocui.View) error {
tv, err := g.View(treeView)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type treeNode interface {
search(query string) (treeNode, error)
isCollapsable() bool
toggleExpanded()
collapseAll()
expandAll()
isExpanded() bool
}

Expand Down Expand Up @@ -72,6 +74,18 @@ type complexNode struct {
data map[string]treeNode
}

func (n *complexNode) collapseAll() {
n.expanded = false
for _, v := range n.data {
v.collapseAll()
}
}
func (n *complexNode) expandAll() {
n.expanded = true
for _, v := range n.data {
v.expandAll()
}
}
func (n complexNode) isCollapsable() bool {
return true
}
Expand Down Expand Up @@ -169,6 +183,18 @@ type listNode struct {
data []treeNode
}

func (n *listNode) collapseAll() {
n.expanded = false
for _, v := range n.data {
v.collapseAll()
}
}
func (n *listNode) expandAll() {
n.expanded = true
for _, v := range n.data {
v.expandAll()
}
}
func (n listNode) isCollapsable() bool {
return true
}
Expand Down Expand Up @@ -248,6 +274,10 @@ type floatNode struct {
data float64
}

func (n *floatNode) collapseAll() {
}
func (n *floatNode) expandAll() {
}
func (n floatNode) isCollapsable() bool {
return false
}
Expand Down Expand Up @@ -277,6 +307,11 @@ type stringNode struct {
data string
}

func (n *stringNode) collapseAll() {
}
func (n *stringNode) expandAll() {
}

func (n stringNode) isCollapsable() bool {
return false
}
Expand Down

0 comments on commit 50385df

Please sign in to comment.