Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
|
1127b96570 | |
|
308543c02c | |
|
d141b4d308 | |
|
3420aee291 | |
|
5ef3364bf1 | |
|
0288d05f2d | |
|
e640db7eb6 | |
|
531a31e4b3 | |
|
154c750e02 |
1
Makefile
1
Makefile
|
@ -19,3 +19,4 @@ toolkitConfig.pb.go: toolkitConfig.proto
|
|||
|
||||
clean:
|
||||
rm -f go.* *.pb.go
|
||||
go-mod-clean --purge
|
||||
|
|
25
action.go
25
action.go
|
@ -13,27 +13,28 @@ import (
|
|||
// everything from the application goes through here
|
||||
func (me *TreeInfo) doAction(a widget.Action) {
|
||||
if a.ActionType == widget.ToolkitInit {
|
||||
log.Log(TREEWARN, "tree.doAction() trapped ToolkitInit finally!")
|
||||
log.Log(TREE, "tree.doAction() trapped ToolkitInit finally!")
|
||||
a.WidgetType = widget.Root
|
||||
n := addNode(&a)
|
||||
me.Add(n)
|
||||
log.Log(TREEWARN, "tree.doAction() init() me.treeRoot")
|
||||
if me.ToolkitInit != nil {
|
||||
log.Log(TREEWARN, "tree.doAction() doing ToolkitInit()")
|
||||
me.ToolkitInit()
|
||||
} else {
|
||||
log.Log(TREEWARN, "tree.doAction() me.ToolkitInit() == nil")
|
||||
log.Log(TREE, "tree.doAction() init() me.treeRoot")
|
||||
if me.ToolkitInit == nil {
|
||||
log.Log(TREE, "tree.doAction() ToolkitInit() was called before plugin had a chance to initialize")
|
||||
log.Log(TREE, "tree.doAction() TODO: fix channel to pause")
|
||||
return
|
||||
}
|
||||
log.Log(TREE, "tree.doAction() doing ToolkitInit()")
|
||||
me.ToolkitInit()
|
||||
return
|
||||
}
|
||||
if a.TablePB != nil {
|
||||
log.Log(TREEWARN, "tree: got a TablePB")
|
||||
log.Log(TREE, "tree: got a TablePB")
|
||||
me.doTable(a)
|
||||
return
|
||||
}
|
||||
if a.WidgetId == 0 {
|
||||
if treeRoot == nil {
|
||||
log.Log(TREEWARN, "tree.doAction() yes, treeRoot is nil. add here")
|
||||
log.Log(TREE, "tree.doAction() yes, treeRoot is nil. add here")
|
||||
}
|
||||
}
|
||||
n := treeRoot.FindWidgetId(a.WidgetId)
|
||||
|
@ -44,6 +45,11 @@ func (me *TreeInfo) doAction(a widget.Action) {
|
|||
me.Add(n)
|
||||
return
|
||||
}
|
||||
if a.WidgetId == 0 {
|
||||
// this is ok. This is the binary tree base and it's already initialized. This happens on startup
|
||||
return
|
||||
}
|
||||
// this shouldn't really happen. It's good to print a warning so the plugin code can be debugged
|
||||
log.Log(TREEWARN, "attempting to re-add widget", a.WidgetId, a.WidgetType, a.ActionType)
|
||||
return
|
||||
}
|
||||
|
@ -133,7 +139,6 @@ func (me *TreeInfo) doAction(a widget.Action) {
|
|||
} else {
|
||||
me.Hide(n)
|
||||
}
|
||||
log.Info("tree: todo: remove child from parent")
|
||||
me.DeleteNode(n)
|
||||
// now remove the child from the parent
|
||||
default:
|
||||
|
|
20
addNode.go
20
addNode.go
|
@ -9,7 +9,7 @@ func (me *TreeInfo) AddNode(a *widget.Action) *Node {
|
|||
if me.TryLock() {
|
||||
defer me.Unlock()
|
||||
} else {
|
||||
log.Info("TREE: mutex lock was already held before AddNode()")
|
||||
log.Log(TREE, "mutex lock was already held before AddNode()")
|
||||
}
|
||||
return addNode(a)
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ func addNode(a *widget.Action) *Node {
|
|||
}
|
||||
|
||||
if treeRoot.FindWidgetId(a.WidgetId) != nil {
|
||||
log.Log(TREEWARN, "AddNode() WidgetId already exists", a.WidgetId)
|
||||
log.Log(TREEWARN, "probably this is a Show() / Hide() issue")
|
||||
log.Log(TREEWARN, "TODO: figure out what to do here")
|
||||
// ignore these errors for now
|
||||
log.Log(TREE, "AddNode() WidgetId already exists", a.WidgetId)
|
||||
log.Log(TREE, "TODO: figure out what to do here probably this is a Show() / Hide() issue")
|
||||
return treeRoot.FindWidgetId(a.WidgetId)
|
||||
}
|
||||
|
||||
|
@ -60,23 +60,23 @@ func addNode(a *widget.Action) *Node {
|
|||
}
|
||||
|
||||
func (me *TreeInfo) DeleteNode(n *Node) {
|
||||
log.Log(TREEWARN, "DeleteNode() before lock n =", n.WidgetId, n.GetProgName())
|
||||
log.Log(TREE, "DeleteNode() before lock n =", n.WidgetId, n.GetProgName())
|
||||
if me.TryLock() {
|
||||
defer me.Unlock()
|
||||
} else {
|
||||
log.Info("TREE: mutex lock was already held before DeleteNode()")
|
||||
}
|
||||
p := n.Parent
|
||||
log.Log(TREEWARN, "DeleteNode() parent =", p.WidgetId, p.GetProgName())
|
||||
log.Log(TREE, "DeleteNode() parent =", p.WidgetId, p.GetProgName())
|
||||
for i, child := range p.children {
|
||||
log.Log(TREEWARN, "parent has child:", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREE, "parent has child:", i, child.WidgetId, child.GetProgName())
|
||||
if n == child {
|
||||
log.Log(TREEWARN, "Found child ==", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREEWARN, "Found n ==", i, n.WidgetId, n.GetProgName())
|
||||
log.Log(TREE, "Found child ==", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREE, "Found n ==", i, n.WidgetId, n.GetProgName())
|
||||
p.children = append(p.children[:i], p.children[i+1:]...)
|
||||
}
|
||||
}
|
||||
for i, child := range p.children {
|
||||
log.Log(TREEWARN, "parent now has child:", i, child.WidgetId, child.GetProgName())
|
||||
log.Log(TREE, "parent now has child:", i, child.WidgetId, child.GetProgName())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package tree
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO; let the user choose the date format
|
||||
func MakeDatestamp(t time.Time) string {
|
||||
/*
|
||||
// Get system locale from the environment
|
||||
locale := os.Getenv("LANG")
|
||||
if locale == "" {
|
||||
locale = "en_US" // Default to English (US) if not set
|
||||
}
|
||||
|
||||
// Parse the language tag
|
||||
tag, err := language.Parse(locale)
|
||||
if err != nil {
|
||||
log.Fatalf("Invalid locale: %v", err)
|
||||
}
|
||||
|
||||
// Create a date formatter
|
||||
formatter := date.NewFormatter(date.OrderDefault, catalog.NewBuilder())
|
||||
|
||||
// Get the current timestamp
|
||||
now := time.Now()
|
||||
|
||||
// Format the date based on the locale
|
||||
p := message.NewPrinter(tag)
|
||||
formattedDate := formatter.Format(tag, now)
|
||||
|
||||
// Print the formatted date
|
||||
fmt.Println("Formatted Date:", formattedDate)
|
||||
|
||||
// Alternative: Use predefined time formats
|
||||
fmt.Println("Localized Date (fallback):", p.Sprintf("%v", now.Format(time.RFC1123)))
|
||||
*/
|
||||
return t.Format(time.RFC1123)
|
||||
}
|
4
find.go
4
find.go
|
@ -10,6 +10,10 @@ func FindWidgetId(id int) *Node {
|
|||
return treeRoot.FindWidgetId(id)
|
||||
}
|
||||
|
||||
func FindWidgetById(id int) *Node {
|
||||
return treeRoot.FindWidgetId(id)
|
||||
}
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *Node) FindWidgetId(id int) *Node {
|
||||
if n == nil {
|
||||
|
|
25
init.go
25
init.go
|
@ -68,7 +68,30 @@ func (t *TreeInfo) ConfigFind(n string) (string, error) {
|
|||
if n == r.Name {
|
||||
return r.Value, nil
|
||||
}
|
||||
log.Info("toolkit config", r.Plugin, r.Name, r.Value, n)
|
||||
// log.Info("toolkit config no-match on", r.Plugin, r.Name, r.Value, n)
|
||||
}
|
||||
return "", fmt.Errorf("toolkit config %s not found", n)
|
||||
}
|
||||
|
||||
func (t *TreeInfo) ConfigSave(o *ToolkitConfig) {
|
||||
t.configInsert(o)
|
||||
t.config.configSave()
|
||||
}
|
||||
|
||||
// update the config option value (or append if new record)
|
||||
func (t *TreeInfo) configInsert(newr *ToolkitConfig) {
|
||||
all := t.config.All() // get the list of repos
|
||||
for all.Scan() {
|
||||
r := all.Next()
|
||||
if t.PluginName != r.Plugin {
|
||||
// option isn't for this plugin
|
||||
continue
|
||||
}
|
||||
if newr.Name == r.Name {
|
||||
// found the record!
|
||||
r.Value = newr.Value
|
||||
return
|
||||
}
|
||||
}
|
||||
t.config.Append(newr)
|
||||
}
|
||||
|
|
82
table.go
82
table.go
|
@ -17,12 +17,6 @@ import (
|
|||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// repeated string order = 1;
|
||||
//
|
||||
// repeated StringRow StringRows = 2;
|
||||
// repeated IntRow IntRows = 3;
|
||||
// repeated TimeRow TimeRows = 4;
|
||||
// repeated BoolRow BoolRows = 5;
|
||||
func (me *TreeInfo) doTable(a widget.Action) {
|
||||
if a.TablePB == nil {
|
||||
log.Log(TREE, "tree: action didn't have a Table PB")
|
||||
|
@ -34,9 +28,7 @@ func (me *TreeInfo) doTable(a widget.Action) {
|
|||
return
|
||||
}
|
||||
log.Info("tree.doTables() start. # of tables:", len(pb.Tables))
|
||||
all := pb.All()
|
||||
for all.Scan() {
|
||||
t := all.Next()
|
||||
for t := range pb.IterAll() {
|
||||
// for i, o := range t.Order {
|
||||
// log.Info("got order:", t.Title, i, o)
|
||||
// }
|
||||
|
@ -46,19 +38,19 @@ func (me *TreeInfo) doTable(a widget.Action) {
|
|||
for i, ot := range me.currentTables {
|
||||
// log.Info("TREE already has UUID", i, ot.Uuid)
|
||||
if t.Uuid == ot.Uuid {
|
||||
log.Info("TREE found UUID! update table here", i, ot.Uuid)
|
||||
log.Log(TREE, "TREE found UUID! update table here", i, ot.Uuid)
|
||||
if ot.Grid == nil {
|
||||
log.Info("TREE found UUID! ot.grid.Id = nil. need to find grid id here")
|
||||
log.Log(TREE, "TREE found UUID! ot.grid.Id = nil. need to find grid id here")
|
||||
return
|
||||
} else {
|
||||
log.Info("TREE found UUID! grid.Id =", ot.Grid.Id)
|
||||
log.Log(TREE, "TREE found UUID! grid.Id =", ot.Grid.Id)
|
||||
t.Grid = ot.Grid
|
||||
}
|
||||
if t.Grid == nil {
|
||||
log.Info("TREE found UUID! grid.Id = nil. need to find grid id here")
|
||||
log.Log(TREE, "TREE found UUID! grid.Id = nil. need to find grid id here")
|
||||
return
|
||||
}
|
||||
log.Info("TREE found UUID! update table here", i, ot.Uuid, "grid.Id =", t.Grid.Id)
|
||||
log.Log(TREE, "TREE found UUID! update table here", i, ot.Uuid, "grid.Id =", t.Grid.Id)
|
||||
me.updateTable(t)
|
||||
return
|
||||
}
|
||||
|
@ -66,9 +58,9 @@ func (me *TreeInfo) doTable(a widget.Action) {
|
|||
|
||||
me.currentTables = append(me.currentTables, t)
|
||||
if t.Grid == nil {
|
||||
log.Info("NEW TREE ERROR: grid.Id = nil need to set grid id here")
|
||||
log.Log(TREEWARN, "new table error: grid.Id = nil need to set grid id here")
|
||||
} else {
|
||||
log.Info("NEW TREE: grid.Id =", t.Grid.Id)
|
||||
// log.Info("NEW TREE: grid.Id =", t.Grid.Id)
|
||||
}
|
||||
me.makeTable(t)
|
||||
}
|
||||
|
@ -89,6 +81,21 @@ func (grid *Node) makeGridLabel(pb *guipb.Widget, w int, h int) *Node {
|
|||
return addNode(a)
|
||||
}
|
||||
|
||||
func (grid *Node) makeGridButton(pb *guipb.Widget, w int, h int) *Node {
|
||||
a := new(widget.Action)
|
||||
a.WidgetType = widget.Button
|
||||
a.WidgetId = int(pb.Id)
|
||||
a.ParentId = grid.WidgetId
|
||||
a.State.Enable = true
|
||||
a.State.Label = pb.Name
|
||||
a.State.AtW = w
|
||||
a.State.AtH = h
|
||||
a.State.GridOffset.X = w
|
||||
a.State.GridOffset.Y = h
|
||||
// log.Info("makeGridLabel()", a.State)
|
||||
return addNode(a)
|
||||
}
|
||||
|
||||
func (me *TreeInfo) updateTable(t *guipb.Table) {
|
||||
grid := FindWidgetId(int(t.Grid.Id))
|
||||
if grid == nil {
|
||||
|
@ -114,6 +121,7 @@ func (me *TreeInfo) updateTable(t *guipb.Table) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (me *TreeInfo) updateRow(t *guipb.Table, name string) {
|
||||
for _, r := range t.StringRows {
|
||||
if name == r.Header.Name {
|
||||
|
@ -175,6 +183,7 @@ func (me *TreeInfo) updateRow(t *guipb.Table, name string) {
|
|||
return
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func (me *TreeInfo) makeTable(t *guipb.Table) {
|
||||
var grid *Node
|
||||
|
@ -187,11 +196,12 @@ func (me *TreeInfo) makeTable(t *guipb.Table) {
|
|||
grid = addNode(a)
|
||||
}
|
||||
if grid == nil {
|
||||
log.Info("tree: makeTable() failed to make grid")
|
||||
log.Log(TREEWARN, "tree: makeTable() failed to make grid")
|
||||
return
|
||||
}
|
||||
me.Add(grid)
|
||||
log.Info("tree: makeTable() finished add win & grid")
|
||||
grid.State.ProgName = "TableGridPB"
|
||||
// log.Info("tree: makeTable() finished add win & grid")
|
||||
var h int = 0
|
||||
var w int = 0
|
||||
for _, name := range t.Order {
|
||||
|
@ -199,7 +209,7 @@ func (me *TreeInfo) makeTable(t *guipb.Table) {
|
|||
if me.addTableRow(t, grid, name, w) {
|
||||
// log.Info("tree:row() COLUMN GOOD", t.Title, name, w, h)
|
||||
} else {
|
||||
log.Info("tree:row() COLOMN FAIL", t.Title, name, w, h)
|
||||
log.Log(TREEWARN, "tree:row() COLOMN FAIL", t.Title, name, w, h)
|
||||
}
|
||||
|
||||
w += 1
|
||||
|
@ -226,6 +236,24 @@ func (me *TreeInfo) addTableRow(t *guipb.Table, grid *Node, name string, w int)
|
|||
return true
|
||||
}
|
||||
|
||||
for _, r := range t.ButtonRows {
|
||||
if name != r.Header.Name {
|
||||
// log.Info("skip string row:", r.Header.Name, "!=", name)
|
||||
continue
|
||||
}
|
||||
// log.Info("tree: Add()ing to grid here", r.Header.Id, r.Header.Name, w, h)
|
||||
head := grid.makeGridLabel(r.Header, w, h)
|
||||
me.Add(head)
|
||||
h += 1
|
||||
for _, v := range r.Widgets {
|
||||
// log.Info("tree: Add()ing to grid here", v.Id, v.Name, w, h)
|
||||
lab := grid.makeGridButton(v, w, h)
|
||||
me.Add(lab)
|
||||
h += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
for _, r := range t.IntRows {
|
||||
if name != r.Header.Name {
|
||||
// log.Info("skip sint row:", r.Header.Name, "!=", name)
|
||||
|
@ -280,6 +308,22 @@ func (me *TreeInfo) addTableRow(t *guipb.Table, grid *Node, name string, w int)
|
|||
return false
|
||||
}
|
||||
|
||||
// returns true if widget is in a table
|
||||
func (n *Node) InTable() bool {
|
||||
// log.Info("InTable() parent id =", n.ParentId)
|
||||
grid := FindWidgetById(int(n.ParentId))
|
||||
if grid != nil {
|
||||
if grid.WidgetType == widget.Grid {
|
||||
if grid.State.ProgName == "TableGridPB" {
|
||||
// this is a protobuf table
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func dumpTable(t *guipb.Table) {
|
||||
for i, o := range t.Order {
|
||||
log.Info("got order:", t.Title, i, o)
|
||||
|
|
|
@ -7,8 +7,8 @@ package forgepb;
|
|||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||
|
||||
message ToolkitConfig { //
|
||||
string plugin = 1; // 'gocui', 'andlabs', etc
|
||||
string name = 2; // variable name 'fullscreen'
|
||||
string plugin = 1; // 'gocui', 'andlabs', etc `autogenpb:unique`
|
||||
string name = 2; // variable name 'fullscreen' `autogenpb:unique`
|
||||
string value = 3; // value "true"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue