Fix Tree Browser

This commit is contained in:
2026-02-01 17:33:34 -06:00
parent 330a2e3ddf
commit ce67592dbb
2 changed files with 48 additions and 30 deletions

View File

@@ -112,6 +112,7 @@ func (s *ScreenHome) Init(a *App) {
s.pdsListing.SetOnSelect(s.selectPdsListingEntry) s.pdsListing.SetOnSelect(s.selectPdsListingEntry)
s.pdsListing.SetOnChange(s.changePdsList) s.pdsListing.SetOnChange(s.changePdsList)
s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode)) s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode))
s.pdsListing.SetLogger(s.Log)
s.jsonContent = wd.NewJsonContent("jsoncontent", s.style) s.jsonContent = wd.NewJsonContent("jsoncontent", s.style)
km := s.jsonContent.GetKeyMap() km := s.jsonContent.GetKeyMap()
@@ -151,6 +152,8 @@ func (s *ScreenHome) Init(a *App) {
s.layout.AddAll(s.columns) s.layout.AddAll(s.columns)
s.layout.SetWeight(s.columns, 4) s.layout.SetWeight(s.columns, 4)
s.menuLayout.SetWidget(s.layout) s.menuLayout.SetWidget(s.layout)
s.layout.SetLogger(s.Log)
s.columns.SetLogger(s.Log)
} }
func (s *ScreenHome) GetName() string { return "home" } func (s *ScreenHome) GetName() string { return "home" }
@@ -182,7 +185,6 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
} }
return s.openPdsEntry.HandleKey(ev) return s.openPdsEntry.HandleKey(ev)
} }
return s.menuLayout.HandleKey(ev) return s.menuLayout.HandleKey(ev)
} }
func (s *ScreenHome) HandleTime(ev *tcell.EventTime) { func (s *ScreenHome) HandleTime(ev *tcell.EventTime) {
@@ -330,6 +332,9 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
if err == nil && n != nil { if err == nil && n != nil {
s.changePdsList(n) s.changePdsList(n)
} }
s.layout.ActivateWidget(s.columns)
s.columns.ActivateWidget(s.pdsListing)
s.isLoading = false s.isLoading = false
}() }()
return true return true
@@ -372,6 +377,13 @@ func (s *ScreenHome) selectPdsListingEntry(tn *wd.TreeNode) bool {
if !s.updateJsonView(tn) { if !s.updateJsonView(tn) {
return false return false
} }
if tn.HasChildren() {
tn.ToggleExpand()
s.pdsListing.UpdateList()
} else {
s.columns.ActivateWidget(s.jsonContent)
}
return true return true
} }
@@ -381,7 +393,11 @@ func (s *ScreenHome) changePdsList(tn *wd.TreeNode) bool {
return upd return upd
} }
func (s *ScreenHome) updateStatusPathBlock(tn *wd.TreeNode) bool { func (s *ScreenHome) updateStatusPathBlock(tn *wd.TreeNode) bool {
// TODO: UpdateStatusPathBlock n, err := s.pdsListing.GetActiveNode()
if err != nil || n == nil {
return false
}
s.stPathBlock.SetParts(n.GetLabelPath())
return true return true
} }
@@ -414,25 +430,6 @@ func (s *ScreenHome) o_selectPdsListingEntry(idx int, nm string) bool {
return false return false
} }
func (s *ScreenHome) o_changePdsList(idx int, nm string) bool {
upd := s.o_updateJsonView(idx, nm)
upd = s.o_updateStatusPathBlock(idx, nm)
return upd
}
func (s *ScreenHome) o_updateStatusPathBlock(idx int, nm string) bool {
if len(s.pdsListingTypes) < idx {
s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes))
return false
}
switch s.pdsListingTypes[idx] {
case models.TypeNSID:
s.stPathBlock.SetParts([]string{s.activePds.AtId.String(), nm})
case models.TypeRecord:
nsidNm := s.activePds.GetNSIDForRecordId(nm).String()
s.stPathBlock.SetParts([]string{s.activePds.AtId.String(), nsidNm, nm})
}
return true
}
func (s *ScreenHome) o_updateJsonView(idx int, nm string) bool { func (s *ScreenHome) o_updateJsonView(idx int, nm string) bool {
if len(s.pdsListingTypes) < idx { if len(s.pdsListingTypes) < idx {
s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes)) s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes))

View File

@@ -2,6 +2,8 @@ package widgets
import ( import (
"errors" "errors"
"fmt"
"strings"
h "git.bullercodeworks.com/brian/expds/helpers" h "git.bullercodeworks.com/brian/expds/helpers"
t "git.bullercodeworks.com/brian/tcell-widgets" t "git.bullercodeworks.com/brian/tcell-widgets"
@@ -142,12 +144,12 @@ func (w *TreeBrowser) Draw(screen tcell.Screen) {
} }
func (w *TreeBrowser) SetStyle(s tcell.Style) { w.style = s } func (w *TreeBrowser) SetStyle(s tcell.Style) { w.style = s }
func (w *TreeBrowser) Active() bool { return false } func (w *TreeBrowser) Active() bool { return w.active }
func (w *TreeBrowser) SetActive(a bool) {} func (w *TreeBrowser) SetActive(a bool) { w.active = a }
func (w *TreeBrowser) Visible() bool { return w.visible } func (w *TreeBrowser) Visible() bool { return w.visible }
func (w *TreeBrowser) SetVisible(a bool) { w.visible = a } func (w *TreeBrowser) SetVisible(a bool) { w.visible = a }
func (w *TreeBrowser) Focusable() bool { return false } func (w *TreeBrowser) Focusable() bool { return w.focusable }
func (w *TreeBrowser) SetFocusable(b bool) {} func (w *TreeBrowser) SetFocusable(b bool) { w.focusable = b }
func (w *TreeBrowser) SetX(x int) { w.SetPos(t.Coord{X: x, Y: w.y}) } func (w *TreeBrowser) SetX(x int) { w.SetPos(t.Coord{X: x, Y: w.y}) }
func (w *TreeBrowser) SetY(y int) { w.SetPos(t.Coord{X: w.x, Y: y}) } func (w *TreeBrowser) SetY(y int) { w.SetPos(t.Coord{X: w.x, Y: y}) }
func (w *TreeBrowser) GetX() int { return w.x } func (w *TreeBrowser) GetX() int { return w.x }
@@ -269,18 +271,18 @@ func (w *TreeBrowser) Title() string { return w.title }
func (w *TreeBrowser) SetTitle(ttl string) { w.title = ttl } func (w *TreeBrowser) SetTitle(ttl string) { w.title = ttl }
func (w *TreeBrowser) SetTree(l []*TreeNode) { func (w *TreeBrowser) SetTree(l []*TreeNode) {
w.nodes = l w.nodes = l
w.updateList() w.UpdateList()
} }
func (w *TreeBrowser) Clear() { func (w *TreeBrowser) Clear() {
w.nodes = []*TreeNode{} w.nodes = []*TreeNode{}
w.updateList() w.UpdateList()
} }
func (w *TreeBrowser) Add(n *TreeNode) { func (w *TreeBrowser) Add(n *TreeNode) {
w.nodes = append(w.nodes, n) w.nodes = append(w.nodes, n)
w.updateList() w.UpdateList()
} }
func (w *TreeBrowser) updateList() { func (w *TreeBrowser) UpdateList() {
w.list = []string{} w.list = []string{}
w.listNodes = []*TreeNode{} w.listNodes = []*TreeNode{}
for i := range w.nodes { for i := range w.nodes {
@@ -309,8 +311,25 @@ func NewTreeNode(l, v string) *TreeNode {
value: v, value: v,
} }
} }
func (tn *TreeNode) Depth() int {
if tn.parent == nil {
return 0
}
return tn.parent.Depth() + 1
}
func (tn *TreeNode) Label() string { return tn.label }
func (tn *TreeNode) Value() string { return tn.value }
func (tn *TreeNode) GetLabelPath() []string {
var path []string
if tn.parent != nil {
path = tn.parent.GetLabelPath()
}
return append([]string{tn.Label()}, path...)
}
func (tn *TreeNode) getList() []string { func (tn *TreeNode) getList() []string {
ret := []string{tn.label} pre := strings.Repeat("-", tn.Depth())
ret := []string{fmt.Sprintf("%s%s", pre, tn.label)}
if tn.expanded { if tn.expanded {
for i := range tn.children { for i := range tn.children {
ret = append(ret, tn.children[i].getList()...) ret = append(ret, tn.children[i].getList()...)
@@ -338,3 +357,5 @@ func (tn *TreeNode) AddChild(t *TreeNode, rest ...*TreeNode) {
tn.children = append(tn.children, rest[i]) tn.children = append(tn.children, rest[i])
} }
} }
func (tn *TreeNode) HasChildren() bool { return len(tn.children) > 0 }