summaryrefslogtreecommitdiff
path: root/setText.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-17 23:54:19 -0600
committerJeff Carr <[email protected]>2024-01-17 23:54:19 -0600
commitb25f15ea7803e172204432082740d081e5f19f81 (patch)
tree025146f42287e7b5d91850366f7fccf49d8ced9b /setText.go
the golang way. everything in it's own repov0.0.1
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'setText.go')
-rw-r--r--setText.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/setText.go b/setText.go
new file mode 100644
index 0000000..2e4b97b
--- /dev/null
+++ b/setText.go
@@ -0,0 +1,76 @@
+package main
+
+import (
+ "go.wit.com/lib/widget"
+ "go.wit.com/log"
+ "go.wit.com/toolkits/tree"
+)
+
+// func (n *node) setText(a *widget.Action) {
+func setText(n *tree.Node, a *widget.Action) {
+ name := widget.GetString(a.Value)
+ var tk *guiWidget
+ tk = n.TK.(*guiWidget)
+
+ log.Log(CHANGE, "setText() START with text =", name)
+ if tk == nil {
+ log.Log(ERROR, "setText error. tk == nil", n.GetProgName(), n.WidgetId)
+ return
+ }
+ log.Log(CHANGE, "setText() Attempt on", n.WidgetType, "with", name)
+
+ switch n.WidgetType {
+ case widget.Window:
+ log.Warn("setText() Attempt to set the title to", name)
+ tk.uiWindow.SetTitle(name)
+ case widget.Tab:
+ case widget.Group:
+ tk.uiGroup.SetTitle(name)
+ case widget.Checkbox:
+ tk.uiCheckbox.SetText(name)
+ case widget.Textbox:
+ if tk.uiEntry != nil {
+ tk.uiEntry.SetText(name)
+ }
+ if tk.uiMultilineEntry != nil {
+ tk.uiMultilineEntry.SetText(name)
+ }
+ case widget.Label:
+ tk.uiLabel.SetText(name)
+ case widget.Button:
+ tk.uiButton.SetText(name)
+ case widget.Slider:
+ log.Log(ERROR, "setText() on slider unknown", a.ActionType, "on checkbox", n.GetProgName())
+ case widget.Spinner:
+ log.Log(ERROR, "setText() on spinner unknown", a.ActionType, "on checkbox", n.GetProgName())
+ case widget.Dropdown:
+ var orig int
+ var i int = -1
+ var s string
+ orig = tk.uiCombobox.Selected()
+ log.Log(CHANGE, "try to set the Dropdown to", name, "from", orig)
+ // try to find the string
+ for i, s = range tk.val {
+ log.Log(CHANGE, "i, s", i, s)
+ if name == s {
+ tk.uiCombobox.SetSelected(i)
+ log.Log(CHANGE, "setText() Dropdown worked.", name)
+ return
+ }
+ }
+ log.Log(ERROR, "setText() Dropdown did not find:", name)
+ // if i == -1, then there are not any things in the menu to select
+ if i == -1 {
+ return
+ }
+ // if the string was never set, then set the dropdown to the last thing added to the menu
+ if orig == -1 {
+ tk.uiCombobox.SetSelected(i)
+ }
+ case widget.Combobox:
+ tk.uiEditableCombobox.SetText(name)
+ default:
+ log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType)
+ }
+ log.Log(CHANGE, "setText() END with name =")
+}