diff options
Diffstat (limited to 'toolkit')
| -rw-r--r-- | toolkit/gocui/click.go | 19 | ||||
| -rw-r--r-- | toolkit/gocui/main.go | 6 | ||||
| -rw-r--r-- | toolkit/gocui/structs.go | 2 | ||||
| -rw-r--r-- | toolkit/widget.go | 1 |
4 files changed, 27 insertions, 1 deletions
diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go index 0dadc8b..a43dab4 100644 --- a/toolkit/gocui/click.go +++ b/toolkit/gocui/click.go @@ -34,6 +34,7 @@ func (w *cuiWidget) doWidgetClick() { } else { w.setCheckbox(true) } + w.doUserEvent() case toolkit.Grid: me.rootNode.hideWidgets() w.placeGrid() @@ -47,10 +48,28 @@ func (w *cuiWidget) doWidgetClick() { } w.placeWidgets() w.toggleTree() + case toolkit.Button: + w.doUserEvent() default: } } +// this passes the user event back from the plugin +func (w *cuiWidget) doUserEvent() { + if (me.callback == nil) { + log(logError, "doUserEvent() no callback channel was configured") + return + } + var a toolkit.Action + a.WidgetId = w.id + a.Name = w.name + a.Text = w.text + a.B = w.b + a.ActionType = toolkit.User + me.callback <- a + log(logNow, "END: sent a button click callback()") +} + var toggle bool = true func (w *cuiWidget) toggleTree() { if (toggle) { diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index ab50237..6821a82 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -6,6 +6,7 @@ package main import ( "os" + "git.wit.org/wit/gui/toolkit" ) func Init() { @@ -27,6 +28,11 @@ func Init() { me.padH = 3 } +// this sets the channel to send user events back from the plugin +func Callback(guiCallback chan toolkit.Action) { + me.callback = guiCallback +} + func Exit() { // TODO: exit correctly me.baseGui.Close() diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index f83622a..8170416 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -23,7 +23,7 @@ type config struct { rootNode *cuiWidget // the base of the binary tree. it should have id == 0 ctrlDown *cuiWidget // shown if you click the mouse when the ctrl key is pressed - callback func(int) + callback chan toolkit.Action helpLabel *gocui.View defaultBehavior bool diff --git a/toolkit/widget.go b/toolkit/widget.go index 01215ed..09fd962 100644 --- a/toolkit/widget.go +++ b/toolkit/widget.go @@ -110,6 +110,7 @@ const ( const ( Add ActionType = iota + User // the user did something (mouse, keyboard, etc) Delete Get Set |
