Closed karlredman closed 4 years ago
After digging around for a while I think I've narrowed it down to 1 of 3 options:
KeyEnter
event to the tree node after a SetCurrentNode()
callSetCurretNode()
that will trigger a "changed" callbacktreeview.go
and customize as needed (obviously least desirable)I'm not sure what the best option is... Option 2 seems like the best one relative to the 'most control' vs 'least intrusive' trade off.
I can submit a PR if you'd like me to demonstrate a public method that triggers the "changed" callback. I'm reluctant to code it if this kind of thing wouldn't be considered good for the library.
I am closing this ticket with an explanation.
As it turns out I was being silly about the expansion problem. I must have been tired. So, if anyone else thinks they are having this issue keep in mind that the original code doesn't walk the entire tree to add the nodes outright. The fix would be to move the add
variable to a plain old recursive function that would resemble something like the following. ...
func add(target *tview.TreeNode, path string, pathfs *vfs.PathFS) {
files, err := pathfs.ReadDir(path) // **using vfs here
if err != nil {
panic(err)
}
for _, file := range files {
ref := FileTreeNodeRef{ // **setup reference
false,
file.IsDir(),
filepath.Join(path, file.Name()),
}
node := tview.NewTreeNode(file.Name()).
// SetReference(filepath.Join(path, file.Name())).
SetReference(ref). // **replaces original SetReference()
SetSelectable(true) // **always selectable
if file.IsDir() {
node.SetExpanded(true) // **directories SHOULD expand by default
node.SetColor(tcell.ColorGreen)
add(node, ref.Path, pathfs) // ** RECURSIVELY ADD DIRECTORIES
}
target.AddChild(node)
}
}
@karlredman As for
2. Ask for a version of SetCurretNode() that will trigger a "changed" callback
When changing current selected node manually, sometimes it's essential to trigger a "changed" and a "selected" callback so that the relevant state updates according to the new current node.
Is there a way to do that?
Hi Great work! Thanks you. I'm having an issue whereby I think I'm missing something or that I would like clarification about if possible please.
Description:
What is hapening:
ExpandAll()
function only works on nodes that have been manually opened Previously.Expand()
doesn't seem to work at all (except for the root node)SetExpanded()
only seems to work on root nodeColapseAll()
andCollapse()
work as expected.Walk()
withnode.SetExpanded(true
) doesn't do anythingWhat is expected:
ExpandAll
should expand at least the 1st level of directories under the root nodeCode:
Sorry this is kind of a long example. Note that once the state changes on the tree, subsequent behavior of the tree changes -so restarting the application is probably necessary in order to see if/that things are working as expected/unexpectedly. I added kb input so you can fiddle with the behaviors a little easier.