From 552bdeb1e6250065f553af16756e54f90092d86b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 12 Feb 2025 15:26:24 -0600 Subject: plugin related cleanups --- init.go | 27 +++++++-------------------- plugin.go | 14 +++++++------- table.go | 13 +++++++++++++ treeCallback.go | 32 -------------------------------- treeInit.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 table.go delete mode 100644 treeCallback.go create mode 100644 treeInit.go diff --git a/init.go b/init.go index 8eba6c6..0c649a5 100644 --- a/init.go +++ b/init.go @@ -16,19 +16,16 @@ import ( "github.com/awesome-gocui/gocui" "go.wit.com/log" - "go.wit.com/toolkits/tree" ) // sent via -ldflags var VERSION string var BUILDTIME string -func queueToolkitClose() { - me.baseGui.Close() -} +var PLUGIN string = "gocui" -func queueSetChecked(n *tree.Node, b bool) { - setChecked(n, b) +func toolkitClose() { + me.baseGui.Close() } // sets defaults and establishes communication @@ -62,8 +59,10 @@ func init() { me.mouse.clicktime = time.Millisecond * 200 me.mouse.doubletime = time.Millisecond * 400 - me.myTree = tree.New() - me.myTree.PluginName = "gocui" + me.myTree = initTree() + + me.newWindowTrigger = make(chan *guiWidget, 1) + go newWindowTrigger() go refreshGocui() // read in defaults from config protobuf @@ -86,18 +85,6 @@ func init() { } } - me.myTree.NodeAction = newaction - me.myTree.Add = newAdd - me.myTree.SetTitle = newSetTitle - me.myTree.SetLabel = newSetLabel - me.myTree.SetText = newSetText - me.myTree.AddText = newAddText - me.myTree.SetChecked = queueSetChecked - me.myTree.ToolkitClose = queueToolkitClose - - me.newWindowTrigger = make(chan *guiWidget, 1) - go newWindowTrigger() - log.Log(NOW, "Init() start pluginChan") // log.Sleep(.1) // probably not needed, but in here for now under development go mainGogui() diff --git a/plugin.go b/plugin.go index 30509ca..19af06f 100644 --- a/plugin.go +++ b/plugin.go @@ -42,18 +42,18 @@ func newAdd(n *tree.Node) { } // for gocui as a GUI plugin, SetTitle & SetLabel are identical to SetText -func newSetTitle(n *tree.Node, s string) { - newSetText(n, s) +func setTitle(n *tree.Node, s string) { + setText(n, s) } -func newSetLabel(n *tree.Node, s string) { - newSetText(n, s) +func setLabel(n *tree.Node, s string) { + setText(n, s) } -// newSetText() and newAddText() are simple. They take the event sent +// setText() and addText() are simple. They take the event sent // to the GO plugin from the application and lookup the plugin structure // then pass that event to gocui. This is the transfer point -func newSetText(n *tree.Node, s string) { +func setText(n *tree.Node, s string) { if n == nil { log.Warn("Tree Error: Add() sent n == nil") return @@ -66,7 +66,7 @@ func newSetText(n *tree.Node, s string) { w.SetText(s) } -func newAddText(n *tree.Node, s string) { +func addText(n *tree.Node, s string) { if n == nil { log.Warn("Tree Error: Add() sent n == nil") return diff --git a/table.go b/table.go new file mode 100644 index 0000000..e69c593 --- /dev/null +++ b/table.go @@ -0,0 +1,13 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + log "go.wit.com/log" + "go.wit.com/toolkits/tree" +) + +func showTable(t *tree.Node) { + log.Info("should show table here") +} diff --git a/treeCallback.go b/treeCallback.go deleted file mode 100644 index 1ead288..0000000 --- a/treeCallback.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is governed by the GPL 3.0 - -package main - -/* - This is reference code for toolkit developers - - This is how information is passed in GO back to the application - via the GO 'plugin' concept - - TODO: switch this to protocol buffers -*/ - -import ( - "go.wit.com/widget" -) - -// Other goroutines must use this to access the GUI -// -// You can not acess / process the GUI thread directly from -// other goroutines. This is due to the nature of how -// Linux, MacOS and Windows work (they all work differently. suprise. surprise.) -// -// this sets the channel to send user events back from the plugin -func Callback(guiCallback chan widget.Action) { - me.myTree.Callback(guiCallback) -} - -func PluginChannel() chan widget.Action { - return me.myTree.PluginChannel() -} diff --git a/treeInit.go b/treeInit.go new file mode 100644 index 0000000..55faaa6 --- /dev/null +++ b/treeInit.go @@ -0,0 +1,49 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +/* + This is reference code for toolkit developers + + This is how information is passed in GO back to the application + via the GO 'plugin' concept + + TODO: switch this to protocol buffers +*/ + +import ( + "go.wit.com/toolkits/tree" + "go.wit.com/widget" +) + +// Other goroutines must use this to access the GUI +// +// You can not acess / process the GUI thread directly from +// other goroutines. This is due to the nature of how +// Linux, MacOS and Windows work (they all work differently. suprise. surprise.) +// +// this sets the channel to send user events back from the plugin +func Callback(guiCallback chan widget.Action) { + me.myTree.Callback(guiCallback) +} + +func PluginChannel() chan widget.Action { + return me.myTree.PluginChannel() +} + +func initTree() *tree.TreeInfo { + t := tree.New() + t.PluginName = PLUGIN + t.NodeAction = newaction + t.Add = newAdd + t.SetTitle = setTitle + t.SetLabel = setLabel + t.SetText = setText + t.AddText = addText + t.SetChecked = setChecked + t.ToolkitClose = toolkitClose + t.ShowTable = showTable + + return t +} -- cgit v1.2.3