diff --git a/click.go b/click.go index 6d2614b..10606b0 100644 --- a/click.go +++ b/click.go @@ -11,14 +11,14 @@ import ( func (w *guiWidget) doWidgetClick() { switch w.WidgetType { /* - case widget.Root: - // THIS IS THE BEGINING OF THE LAYOUT - log.Log(NOW, "doWidgetClick()", w.String()) - wRoot := me.treeRoot.TK.(*guiWidget) - wRoot.redoWindows(0, 0) - case widget.Flag: - log.Log(NOW, "doWidgetClick() FLAG widget name =", w.String()) - log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") + case widget.Root: + // THIS IS THE BEGINING OF THE LAYOUT + log.Log(NOW, "doWidgetClick()", w.String()) + wRoot := me.treeRoot.TK.(*guiWidget) + wRoot.redoWindows(0, 0) + case widget.Flag: + log.Log(NOW, "doWidgetClick() FLAG widget name =", w.String()) + log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") */ case widget.Window: log.Log(NOW, "doWidgetClick() START on window", w.String()) diff --git a/main.go b/main.go index 0a73e49..46cb848 100644 --- a/main.go +++ b/main.go @@ -27,12 +27,14 @@ func init() { me.myTree = tree.New() me.myTree.PluginName = "gocui" me.myTree.ActionFromChannel = action - // me.myTree.NodeAction = nodeaction - - // pluginChan = make(chan widget.Action) + me.myTree.NodeAction = newaction + me.myTree.Add = newAdd + me.myTree.SetTitle = newSetTitle + me.myTree.SetLabel = newSetLabel + me.myTree.SetText = newSetText + me.myTree.AddText = newAddText log.Log(NOW, "Init() start pluginChan") - // go catchActionChannel() log.Sleep(.1) // probably not needed, but in here for now under development go mainGogui() log.Sleep(.1) // probably not needed, but in here for now under development diff --git a/plugin.go b/plugin.go index 673f184..d5176a5 100644 --- a/plugin.go +++ b/plugin.go @@ -4,15 +4,119 @@ import ( // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) "go.wit.com/log" + "go.wit.com/toolkits/tree" "go.wit.com/widget" ) -/* -func newaction(n *tree.Node, atype widget.ActionType) { - switch a.ActionType { - case widget.Add: +func newAdd(n *tree.Node) { + if n == nil { + log.Warn("Tree Error: Add() sent n == nil") + return + } + if n.TK != nil { + log.Warn("Tree Add() sent a widget we aleady seem to have") + // this is done to protect the plugin being 'refreshed' with the + // widget binary tree. TODO: find a way to keep them in sync + return + } + n.TK = initWidget(n) + if n.WidgetType == widget.Root { + me.treeRoot = n + } + addWidget(n) + /* + TODO: removed while refactoring tree + if w.enable { + // don't change the color + } else { + w = n.TK.(*guiWidget) + } + */ + // w.setColor(&colorDisabled) + w := n.TK.(*guiWidget) + w.Show() +} + +func newSetTitle(n *tree.Node, s string) { + newSetText(n, s) +} + +func newSetLabel(n *tree.Node, s string) { + newSetText(n, s) +} + +func newSetText(n *tree.Node, s string) { + if n == nil { + log.Warn("Tree Error: Add() sent n == nil") + return + } + if n.TK == nil { + log.Warn("Tree sent an action on a widget we didn't seem to have.") + return + } + w := n.TK.(*guiWidget) + w.SetText(s) +} + +func newAddText(n *tree.Node, s string) { + if n == nil { + log.Warn("Tree Error: Add() sent n == nil") + return + } + if n.TK == nil { + log.Warn("Tree sent an action on a widget we didn't seem to have.") + return + } + w := n.TK.(*guiWidget) + w.AddText(s) +} + +func newaction(n *tree.Node, atype widget.ActionType) { + log.Log(INFO, "newaction() START", atype) + if n == nil { + log.Warn("Tree Error: Add() sent n == nil") + return + } + if n.TK == nil { + log.Warn("Tree sent an action on a widget we didn't seem to have.") + // do this init here again? Probably something + // went wrong and we should reset the our while gocui.View tree + n.TK = initWidget(n) + } + w := n.TK.(*guiWidget) + switch atype { + case widget.Show: + log.Log(NOW, "Show() HERE. a.Hidden() was =", n.Hidden()) + w.Show() + case widget.Hide: + log.Log(NOW, "Hide() HERE. a.State.Hidden was =", n.Hidden()) + w.Hide() + case widget.Move: + log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName()) + case widget.ToolkitClose: + log.Log(NOW, "attempting to close the plugin and release stdout and stderr") + standardClose() + case widget.Enable: + w.enable = true + w.enableColor() + case widget.Disable: + w.enable = false + w.disableColor() + case widget.Delete: + if w == nil { + return + } else { + w.hideWidgets() + w.deleteNode() + } + n.DeleteNode() + wRoot := me.treeRoot.TK.(*guiWidget) + wRoot.redoWindows(0, 0) + default: + log.Log(ERROR, "newaction() UNHANDLED Action Type =", atype, "WidgetType =", n.WidgetType, "Name =", n.ProgName()) + } + log.Log(INFO, "newaction() END", atype, n.String()) } -*/ func action(a widget.Action) { log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)