From 3474f20ce1b22e0368df9dc00529239f0d9f1ba2 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Fri, 30 Jan 2026 16:59:26 -0600 Subject: [PATCH] Trying to get keys to the treebrowser --- app/screen_home.go | 63 +++++++++++------------------------------ widgets/tree_browser.go | 21 ++++++++++++++ 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/app/screen_home.go b/app/screen_home.go index eb177d2..05ee20f 100644 --- a/app/screen_home.go +++ b/app/screen_home.go @@ -50,12 +50,10 @@ type ScreenHome struct { layout *w.LinearLayout columns *w.LinearLayout - activePds *models.Pds - //pdsListing *w.SimpleListWithHelp + activePds *models.Pds pdsListing *wd.TreeBrowser jsonContent *wd.JsonContent status *wd.StatusBar - stTmBlock *wd.StatusBlock stPathBlock *wd.StatusBlock pdsListingTypes []models.EntryType @@ -105,13 +103,13 @@ func (s *ScreenHome) Init(a *App) { //s.pdsListing = w.NewSimpleListWithHelp("pdslisting", s.style) s.pdsListing = wd.NewTreeBrowser("pdslisting", s.style) - s.pdsListing.SetBorder( - []rune{'─', '┬', '│', '┴', '─', '└', '│', '┌', '├', '─', '┤', '┬', '│', '┴', '┼'}, - ) + s.pdsListing.SetBorder([]rune{'─', '┬', '│', '┴', '─', '└', '│', '┌', '├', '─', '┤', '┬', '│', '┴', '┼'}) + s.pdsListing.SetTitle(strings.Repeat(" ", 30)) s.pdsListing.SetOnSelect(s.selectPdsListingEntry) s.pdsListing.SetOnChange(s.changePdsList) s.pdsListing.SetVimMode(viper.GetBool(data.KeyVimMode)) + s.pdsListing.SetLogger(s.Log) s.jsonContent = wd.NewJsonContent("jsoncontent", s.style) km := s.jsonContent.GetKeyMap() @@ -148,8 +146,12 @@ func (s *ScreenHome) Init(a *App) { s.columns.AddAll(s.pdsListing, s.jsonContent) - s.layout.AddAll(s.columns) - s.layout.SetWeight(s.columns, 4) + //s.layout.AddAll(s.columns) + //s.layout.SetLogger(s.Log) + //s.layout.SetWeight(s.columns, 4) + s.layout.Add(s.pdsListing) + s.layout.SetLogger(s.Log) + s.layout.SetWeight(s.pdsListing, 4) s.menuLayout.SetWidget(s.layout) } @@ -182,14 +184,12 @@ func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool { } return s.openPdsEntry.HandleKey(ev) } - return s.menuLayout.HandleKey(ev) } func (s *ScreenHome) HandleTime(ev *tcell.EventTime) { s.menuLayout.HandleTime(ev) s.loading.HandleTime(ev) s.status.HandleTime(ev) - //s.stTmBlock.SetText(time.Now().Format(time.TimeOnly)) } func (s *ScreenHome) Draw() { if s.doOpen { @@ -348,23 +348,11 @@ func (s *ScreenHome) updatePdsListing() { t.AddChild(c) } s.pdsListing.Add(t) - - /* - wrk = append(wrk, t) - wrk = append(wrk, v) - s.pdsListingTypes = append(s.pdsListingTypes, models.TypeNSID) - if _, ok := s.expandedEntries[v]; ok { - nsid := s.activePds.NSIDs[i] - rIds := s.activePds.GetRecordIdsFor(nsid) - for j := range rIds { - wrk = append(wrk, fmt.Sprintf("• %s", rIds[j])) - s.pdsListingTypes = append(s.pdsListingTypes, models.TypeRecord) - s.recordIdsToNSIDs[rIds[j]] = nsid - } - } - */ } - //s.pdsListing.AddChild(wrk) + s.layout.ActivateWidget(s.columns) + s.columns.ActivateWidget(s.pdsListing) + s.pdsListing.SetActive(true) + s.pdsListing.SetFocusable(true) s.hideCli() } @@ -381,7 +369,7 @@ func (s *ScreenHome) changePdsList(tn *wd.TreeNode) bool { return upd } func (s *ScreenHome) updateStatusPathBlock(tn *wd.TreeNode) bool { - // TODO: UpdateStatusPathBlock + s.stPathBlock.SetParts(tn.GetLabelPath()) return true } @@ -390,6 +378,7 @@ func (s *ScreenHome) updateJsonView(tn *wd.TreeNode) bool { return true } +/* func (s *ScreenHome) o_selectPdsListingEntry(idx int, nm string) bool { if !s.o_updateJsonView(idx, nm) { return false @@ -414,25 +403,6 @@ func (s *ScreenHome) o_selectPdsListingEntry(idx int, nm string) bool { 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 { if len(s.pdsListingTypes) < idx { s.Log("error finding pds listing type (idx: %d >= list length: %d", idx, len(s.pdsListingTypes)) @@ -464,3 +434,4 @@ func (s *ScreenHome) o_updateJsonView(idx int, nm string) bool { return false } +*/ diff --git a/widgets/tree_browser.go b/widgets/tree_browser.go index 430d199..e4f3c78 100644 --- a/widgets/tree_browser.go +++ b/widgets/tree_browser.go @@ -2,6 +2,7 @@ package widgets import ( "errors" + "fmt" h "git.bullercodeworks.com/brian/expds/helpers" t "git.bullercodeworks.com/brian/tcell-widgets" @@ -104,6 +105,7 @@ func (w *TreeBrowser) GetKeyMap() *t.KeyMap { return w.keyMap } func (w *TreeBrowser) SetKeyMap(km *t.KeyMap) { w.keyMap = km } func (w *TreeBrowser) HandleKey(ev *tcell.EventKey) bool { + w.Log("TreeBrowser Handling Key: %s", ev.Name()) if !w.active || !w.focusable { return false } @@ -139,6 +141,7 @@ func (w *TreeBrowser) Draw(screen tcell.Screen) { break } } + th.DrawText(x, y, fmt.Sprintf("Cursor: %d", w.cursor), w.style, screen) } func (w *TreeBrowser) SetStyle(s tcell.Style) { w.style = s } @@ -290,6 +293,9 @@ func (w *TreeBrowser) updateList() { if w.cursor >= len(w.list) { w.cursor = len(w.list) - 1 } + if w.cursor <= 0 { + w.cursor = 0 + } } /* @@ -338,3 +344,18 @@ func (tn *TreeNode) AddChild(t *TreeNode, rest ...*TreeNode) { tn.children = append(tn.children, rest[i]) } } + +func (tn *TreeNode) GetPath() []string { + var path []string + if tn.parent != nil { + path = tn.parent.GetPath() + } + return append(path, tn.value) +} +func (tn *TreeNode) GetLabelPath() []string { + var path []string + if tn.parent != nil { + path = tn.parent.GetLabelPath() + } + return append(path, tn.label) +}