disable and enable doesn't crash

This commit is contained in:
Jeff Carr 2025-02-11 13:22:23 -06:00
parent 535646335a
commit 733c595c54
3 changed files with 93 additions and 49 deletions

View File

@ -68,12 +68,13 @@ func (tk *guiWidget) updateColor() {
if tk.v == nil {
return
}
tk.colorLast.frame = tk.color.frame
tk.colorLast.fg = tk.color.fg
tk.colorLast.bg = tk.color.bg
tk.colorLast.selFg = tk.color.selFg
tk.colorLast.selBg = tk.color.selBg
if tk.color != nil {
tk.colorLast.frame = tk.color.frame
tk.colorLast.fg = tk.color.fg
tk.colorLast.bg = tk.color.bg
tk.colorLast.selFg = tk.color.selFg
tk.colorLast.selBg = tk.color.selBg
}
tk.activateColor()
}

113
plugin.go
View File

@ -7,6 +7,7 @@ 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)
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
@ -224,27 +225,57 @@ func (tk *guiWidget) Disable() {
log.Log(NOW, "widget is nil")
return
}
tk.enable = false
tk.node.State.Enable = false
// log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType {
case widget.Box:
// log.Info("todo: blank out the window here", tk.String())
r := new(rectType)
// startW, startH := tk.Position()
r.w0 = 0
r.h0 = 0
r.w1 = r.w0 + 24
r.h1 = r.h0 + 2
me.textbox.tk.forceSizes(r)
showTextbox("Running...")
return
case widget.Button:
tk.setColorDisable()
return
default:
tk.dumpWidget("fixme: disable")
}
initTextbox()
tk.prepTextbox()
r := new(rectType)
r.w0 = 2
r.h0 = 1
r.w1 = r.w0 + 24
r.h1 = r.h0 + 2
me.textbox.tk.forceSizes(r)
me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
log.Info("textbox should be shown")
// showTextbox("Running...")
me.textbox.tk.dumpWidget("shown?")
me.textbox.tk.setColorModal()
me.textbox.tk.v.Clear()
me.textbox.tk.v.WriteString("Running...")
me.textbox.tk.v.Editable = true
me.textbox.tk.v.Wrap = true
me.baseGui.SetView(me.textbox.tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0)
me.baseGui.SetCurrentView(me.textbox.tk.v.Name())
// bind the enter key to a function so we can close the textbox
me.baseGui.SetKeybinding(me.textbox.tk.v.Name(), gocui.KeyEnter, gocui.ModNone, theCloseTheTextbox)
me.textbox.active = true
/*
tk.enable = false
tk.node.State.Enable = false
// log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType {
case widget.Box:
// log.Info("todo: blank out the window here", tk.String())
r := new(rectType)
// startW, startH := tk.Position()
r.w0 = 0
r.h0 = 0
r.w1 = r.w0 + 24
r.h1 = r.h0 + 2
me.textbox.tk.forceSizes(r)
showTextbox("Running...")
return
case widget.Button:
tk.setColorDisable()
return
default:
tk.dumpWidget("fixme: disable")
}
*/
}
func (tk *guiWidget) Enable() {
@ -252,20 +283,28 @@ func (tk *guiWidget) Enable() {
log.Log(NOW, "widget is nil")
return
}
tk.enable = true
tk.node.State.Enable = true
// log.Info("enable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType {
case widget.Box:
// log.Info("todo: un blank the window here")
me.textbox.tk.Hide()
me.textbox.active = false
// log.Info("escaped from textbox")
return
case widget.Button:
tk.restoreEnableColor()
return
default:
tk.dumpWidget("fixme: enable")
}
initTextbox()
tk.prepTextbox()
me.textbox.tk.Hide()
/*
initTextbox()
tk.enable = true
tk.node.State.Enable = true
// log.Info("enable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType {
case widget.Box:
// log.Info("todo: un blank the window here")
me.textbox.tk.Hide()
me.textbox.active = false
// log.Info("escaped from textbox")
return
case widget.Button:
tk.restoreEnableColor()
return
default:
tk.dumpWidget("fixme: enable")
}
*/
}

View File

@ -29,14 +29,18 @@ func (tk *guiWidget) forceSizes(r *rectType) {
tk.force.h1 = r.h1
}
func (callertk *guiWidget) prepTextbox() {
func initTextbox() {
if me.textbox.tk == nil {
// should only happen once
me.textbox.tk = makeNewFlagWidget(me.textbox.wId)
// me.textbox.tk.dumpWidget("init() textbox")
}
}
func (callertk *guiWidget) prepTextbox() {
initTextbox()
if me.textbox.tk == nil {
log.Log(GOCUI, "showTextbox() Is Broken")
log.Log(GOCUI, "prepTextbox() Is Broken")
return
}
@ -51,14 +55,14 @@ func (callertk *guiWidget) prepTextbox() {
me.textbox.callerTK = callertk
showTextbox(callertk.String())
// showTextbox(callertk.String())
}
func showTextbox(callertk string) {
func showTextbox(callers string) {
// tk := me.textbox.tk
// me.textbox.tk.dumpWidget("after sizes")
me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
// me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
if me.textbox.tk.v == nil {
log.Info("wtf went wrong")
@ -67,7 +71,7 @@ func showTextbox(callertk string) {
me.textbox.tk.setColorModal()
me.textbox.tk.v.Clear()
cur := strings.TrimSpace(callertk)
cur := strings.TrimSpace(callers)
// log.Info("setting textbox string to:", cur)
me.textbox.tk.v.WriteString(cur)