diff --git a/colorNew.go b/colorNew.go index f537c5c..76dcab6 100644 --- a/colorNew.go +++ b/colorNew.go @@ -27,6 +27,9 @@ func (tk *guiWidget) restoreEnableColor() { // DONE ON DISABLE() WIDGET // makes the button look disabled func (tk *guiWidget) setColorDisable() { + if tk.color == nil { + tk.color = new(colorT) + } // save the current color tk.color.frame = superLightGrey tk.color.fg = gocui.ColorBlack diff --git a/plugin.go b/plugin.go index 2cec989..5660e65 100644 --- a/plugin.go +++ b/plugin.go @@ -36,7 +36,6 @@ func newAdd(n *tree.Node) { w = n.TK.(*guiWidget) } */ - // w.setColor(&colorDisabled) w := n.TK.(*guiWidget) 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") standardClose() case widget.Enable: - w.enable = true - w.node.State.Enable = true - w.restoreEnableColor() - log.Info("enable widget in gocui", atype, n.WidgetType, n.ProgName()) + w.Enable() case widget.Disable: - w.enable = false - w.node.State.Enable = false - w.setColorDisable() - log.Info("disable widget in gocui", atype, n.WidgetType, n.ProgName()) + w.Disable() case widget.Delete: if w == nil { return @@ -218,3 +211,37 @@ func (tk *guiWidget) GetText() string { } 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()) + } +}