diff options
Diffstat (limited to 'andlabs/action.go')
| -rw-r--r-- | andlabs/action.go | 146 |
1 files changed, 106 insertions, 40 deletions
diff --git a/andlabs/action.go b/andlabs/action.go index b1046ba..28c78d5 100644 --- a/andlabs/action.go +++ b/andlabs/action.go @@ -1,47 +1,99 @@ package main import ( - "strconv" - "go.wit.com/dev/andlabs/ui" + "errors" "go.wit.com/log" "go.wit.com/gui/widget" + "go.wit.com/gui/toolkits/tree" ) +// this will check to make sure that the node +// is valid for making a New TK andlabs widget +// Basically, it makes sure there is a parent ID +// and that there already a widget created +func notNew(n *tree.Node) bool { + if n == nil { + log.Warn("ready() n = nil") + return true + } + if n.TK != nil { + log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName()) + return true + } + if n.Parent == nil { + log.Warn("ready() n.Parent = nil", n.WidgetId, n.GetProgName()) + return true + } + if n.Parent.TK == nil { + log.Warn("ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName()) + log.Warn("ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName()) + return true + } + // this means you can add a new widgets + return false +} + +func ready(n *tree.Node) bool { + if n == nil { + log.Warn("ready() n = nil") + return false + } + if n.TK == nil { + log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName()) + return false + } + if n.Parent == nil { + log.Warn("ready() n.Parent = nil", n.WidgetId, n.GetProgName()) + return false + } + if n.Parent.TK == nil { + log.Warn("ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName()) + log.Warn("ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName()) + return false + } + return true +} func (n *node) ready() bool { if n == nil { return false } if n.tk == nil { return false } return true } -func (n *node) show(b bool) { - if n.tk == nil { +func show(n *tree.Node, b bool) { + var tk *guiWidget + tk = n.TK.(*guiWidget) + // tk = getTK(n) + + if tk == nil { return } - if n.tk.uiControl == nil { + if tk.uiControl == nil { return } if (b) { - n.tk.uiControl.Show() + tk.uiControl.Show() } else { - n.tk.uiControl.Hide() + tk.uiControl.Hide() } } -func (n *node) enable(b bool) { +func enable(n *tree.Node, b bool) { + var tk *guiWidget + tk = n.TK.(*guiWidget) if n == nil { panic("WHAT? enable was passed nil. How does this even happen?") } - if n.tk == nil { + if tk == nil { return } - if n.tk.uiControl == nil { + if tk.uiControl == nil { return } if (b) { - n.tk.uiControl.Enable() + tk.uiControl.Enable() } else { - n.tk.uiControl.Disable() + tk.uiControl.Disable() } } @@ -152,73 +204,88 @@ func (n *node) Delete() { func rawAction(a *widget.Action) { log.Log(INFO, "rawAction() START a.ActionType =", a.ActionType, "a.Value", a.Value) - if (a.ActionType == widget.InitToolkit) { - // TODO: make sure to only do this once - // go uiMain.Do(func() { - // ui.Main(demoUI) - // go catchActionChannel() - // }) - // try doing this on toolkit load in init() + if (a.ActionType == widget.ToolkitInit) { + Init() + return + } + switch a.WidgetType { + case widget.Root: + me.treeRoot = me.myTree.AddNode(a) + log.Log(INFO, "doAction() found treeRoot") return } - log.Log(INFO, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) + log.Warn("andlabs rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId, a.ActionType) switch a.WidgetType { case widget.Flag: log.Log(ERROR, "rawAction() RE-IMPLEMENT LOG FLAGS") return } - n := me.rootNode.findWidgetId(a.WidgetId) + if me.treeRoot == nil { + panic("me.treeRoot == nil") + } + + n := me.treeRoot.FindWidgetId(a.WidgetId) if (a.ActionType == widget.Add) { - ui.QueueMain(func() { + me.treeRoot.ListWidgets() + // ui.QueueMain(func() { add(a) - }) + // }) // TODO: remove this artificial delay // sleep(.001) return } if (a.ActionType == widget.Dump) { - log.Log(NOW, "rawAction() Dump =", a.ActionType, a.WidgetType, n.progname) - me.rootNode.listChildren(true) + log.Log(NOW, "rawAction() Dump =", a.ActionType, a.WidgetType, n.State.ProgName) + // me.rootNode.listChildren(true) return } if (n == nil) { - me.rootNode.listChildren(true) - log.Log(NOW, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType) + log.Error(errors.New("andlabs rawAction() ERROR findWidgetId found nil"), a.ActionType, a.WidgetType) log.Log(NOW, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId) log.Log(NOW, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType) log.Log(NOW, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId) + me.treeRoot.ListWidgets() return - panic("findWidgetId found nil for id = " + strconv.Itoa(a.WidgetId)) + panic("findWidgetId found nil for id = " + string(a.WidgetId)) } switch a.ActionType { case widget.Show: - n.show(true) + show(n, true) + // n.show(true) case widget.Hide: - n.show(false) + show(n, false) + //n.show(false) case widget.Enable: - n.enable(true) + enable(n, true) + // n.enable(true) case widget.Disable: - log.Warn("andlabs got disable for", n.WidgetId, n.progname) - n.enable(false) + log.Warn("andlabs got disable for", n.WidgetId, n.State.ProgName) + enable(n, false) + // n.enable(false) case widget.Get: - n.setText(a) + // n.setText(a) + setText(n, a) case widget.GetText: switch a.WidgetType { case widget.Textbox: - a.Value = n.value + a.Value = n.State.Value } case widget.Set: - n.setText(a) + setText(n, a) + // n.setText(a) case widget.SetText: - n.setText(a) + setText(n, a) + // n.setText(a) case widget.AddText: - n.addText(a) + addText(n, a) + // n.addText(a) + /* case widget.Margin: n.pad(true) case widget.Unmargin: @@ -231,8 +298,7 @@ func rawAction(a *widget.Action) { n.Delete() case widget.Move: log.Log(NOW, "rawAction() attempt to move() =", a.ActionType, a.WidgetType) - newParent := me.rootNode.findWidgetId(a.ParentId) - n.move(newParent) + */ default: log.Log(ERROR, "rawAction() Unknown =", a.ActionType, a.WidgetType) } |
