Trying to get keys to the treebrowser
This commit is contained in:
@@ -51,11 +51,9 @@ type ScreenHome struct {
|
|||||||
columns *w.LinearLayout
|
columns *w.LinearLayout
|
||||||
|
|
||||||
activePds *models.Pds
|
activePds *models.Pds
|
||||||
//pdsListing *w.SimpleListWithHelp
|
|
||||||
pdsListing *wd.TreeBrowser
|
pdsListing *wd.TreeBrowser
|
||||||
jsonContent *wd.JsonContent
|
jsonContent *wd.JsonContent
|
||||||
status *wd.StatusBar
|
status *wd.StatusBar
|
||||||
stTmBlock *wd.StatusBlock
|
|
||||||
stPathBlock *wd.StatusBlock
|
stPathBlock *wd.StatusBlock
|
||||||
|
|
||||||
pdsListingTypes []models.EntryType
|
pdsListingTypes []models.EntryType
|
||||||
@@ -105,13 +103,13 @@ func (s *ScreenHome) Init(a *App) {
|
|||||||
|
|
||||||
//s.pdsListing = w.NewSimpleListWithHelp("pdslisting", s.style)
|
//s.pdsListing = w.NewSimpleListWithHelp("pdslisting", s.style)
|
||||||
s.pdsListing = wd.NewTreeBrowser("pdslisting", s.style)
|
s.pdsListing = wd.NewTreeBrowser("pdslisting", s.style)
|
||||||
s.pdsListing.SetBorder(
|
s.pdsListing.SetBorder([]rune{'─', '┬', '│', '┴', '─', '└', '│', '┌', '├', '─', '┤', '┬', '│', '┴', '┼'})
|
||||||
[]rune{'─', '┬', '│', '┴', '─', '└', '│', '┌', '├', '─', '┤', '┬', '│', '┴', '┼'},
|
|
||||||
)
|
|
||||||
s.pdsListing.SetTitle(strings.Repeat(" ", 30))
|
s.pdsListing.SetTitle(strings.Repeat(" ", 30))
|
||||||
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()
|
||||||
@@ -148,8 +146,12 @@ func (s *ScreenHome) Init(a *App) {
|
|||||||
|
|
||||||
s.columns.AddAll(s.pdsListing, s.jsonContent)
|
s.columns.AddAll(s.pdsListing, s.jsonContent)
|
||||||
|
|
||||||
s.layout.AddAll(s.columns)
|
//s.layout.AddAll(s.columns)
|
||||||
s.layout.SetWeight(s.columns, 4)
|
//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)
|
s.menuLayout.SetWidget(s.layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,14 +184,12 @@ 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) {
|
||||||
s.menuLayout.HandleTime(ev)
|
s.menuLayout.HandleTime(ev)
|
||||||
s.loading.HandleTime(ev)
|
s.loading.HandleTime(ev)
|
||||||
s.status.HandleTime(ev)
|
s.status.HandleTime(ev)
|
||||||
//s.stTmBlock.SetText(time.Now().Format(time.TimeOnly))
|
|
||||||
}
|
}
|
||||||
func (s *ScreenHome) Draw() {
|
func (s *ScreenHome) Draw() {
|
||||||
if s.doOpen {
|
if s.doOpen {
|
||||||
@@ -348,23 +348,11 @@ func (s *ScreenHome) updatePdsListing() {
|
|||||||
t.AddChild(c)
|
t.AddChild(c)
|
||||||
}
|
}
|
||||||
s.pdsListing.Add(t)
|
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.layout.ActivateWidget(s.columns)
|
||||||
*/
|
s.columns.ActivateWidget(s.pdsListing)
|
||||||
}
|
s.pdsListing.SetActive(true)
|
||||||
//s.pdsListing.AddChild(wrk)
|
s.pdsListing.SetFocusable(true)
|
||||||
s.hideCli()
|
s.hideCli()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +369,7 @@ 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
|
s.stPathBlock.SetParts(tn.GetLabelPath())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,6 +378,7 @@ func (s *ScreenHome) updateJsonView(tn *wd.TreeNode) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (s *ScreenHome) o_selectPdsListingEntry(idx int, nm string) bool {
|
func (s *ScreenHome) o_selectPdsListingEntry(idx int, nm string) bool {
|
||||||
if !s.o_updateJsonView(idx, nm) {
|
if !s.o_updateJsonView(idx, nm) {
|
||||||
return false
|
return false
|
||||||
@@ -414,25 +403,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))
|
||||||
@@ -464,3 +434,4 @@ func (s *ScreenHome) o_updateJsonView(idx int, nm string) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package widgets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
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"
|
||||||
@@ -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) SetKeyMap(km *t.KeyMap) { w.keyMap = km }
|
||||||
|
|
||||||
func (w *TreeBrowser) HandleKey(ev *tcell.EventKey) bool {
|
func (w *TreeBrowser) HandleKey(ev *tcell.EventKey) bool {
|
||||||
|
w.Log("TreeBrowser Handling Key: %s", ev.Name())
|
||||||
if !w.active || !w.focusable {
|
if !w.active || !w.focusable {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -139,6 +141,7 @@ func (w *TreeBrowser) Draw(screen tcell.Screen) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
th.DrawText(x, y, fmt.Sprintf("Cursor: %d", w.cursor), w.style, screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TreeBrowser) SetStyle(s tcell.Style) { w.style = s }
|
func (w *TreeBrowser) SetStyle(s tcell.Style) { w.style = s }
|
||||||
@@ -290,6 +293,9 @@ func (w *TreeBrowser) updateList() {
|
|||||||
if w.cursor >= len(w.list) {
|
if w.cursor >= len(w.list) {
|
||||||
w.cursor = len(w.list) - 1
|
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])
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user