fix panic in Enable() and Disable()

This commit is contained in:
Jeff Carr 2025-02-09 06:45:01 -06:00
parent 70452bdaac
commit 4a009f79a2
2 changed files with 39 additions and 9 deletions

View File

@ -27,6 +27,9 @@ func (tk *guiWidget) restoreEnableColor() {
// DONE ON DISABLE() WIDGET // DONE ON DISABLE() WIDGET
// makes the button look disabled // makes the button look disabled
func (tk *guiWidget) setColorDisable() { func (tk *guiWidget) setColorDisable() {
if tk.color == nil {
tk.color = new(colorT)
}
// save the current color // save the current color
tk.color.frame = superLightGrey tk.color.frame = superLightGrey
tk.color.fg = gocui.ColorBlack tk.color.fg = gocui.ColorBlack

View File

@ -36,7 +36,6 @@ func newAdd(n *tree.Node) {
w = n.TK.(*guiWidget) w = n.TK.(*guiWidget)
} }
*/ */
// w.setColor(&colorDisabled)
w := n.TK.(*guiWidget) w := n.TK.(*guiWidget)
w.Show() w.Show()
} }
@ -115,15 +114,9 @@ func newaction(n *tree.Node, atype widget.ActionType) {
log.Log(NOW, "attempting to close the plugin and release stdout and stderr") log.Log(NOW, "attempting to close the plugin and release stdout and stderr")
standardClose() standardClose()
case widget.Enable: case widget.Enable:
w.enable = true w.Enable()
w.node.State.Enable = true
w.restoreEnableColor()
log.Info("enable widget in gocui", atype, n.WidgetType, n.ProgName())
case widget.Disable: case widget.Disable:
w.enable = false w.Disable()
w.node.State.Enable = false
w.setColorDisable()
log.Info("disable widget in gocui", atype, n.WidgetType, n.ProgName())
case widget.Delete: case widget.Delete:
if w == nil { if w == nil {
return return
@ -218,3 +211,37 @@ func (tk *guiWidget) GetText() string {
} }
return "" return ""
} }
func (tk *guiWidget) Disable() {
if tk == nil {
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.Button:
tk.setColorDisable()
return
default:
log.Log(INFO, "don't know how to disable", tk.node.WidgetId, "w.name", tk.String())
}
}
func (tk *guiWidget) Enable() {
if tk == nil {
log.Log(NOW, "widget is nil")
return
}
tk.enable = true
tk.node.State.Enable = true
log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
switch tk.node.WidgetType {
case widget.Button:
tk.restoreEnableColor()
return
default:
log.Log(INFO, "don't know how to disable", tk.node.WidgetId, "w.name", tk.String())
}
}