Compare commits

...

6 Commits

7 changed files with 91 additions and 9 deletions

View File

@ -19,3 +19,4 @@ toolkitConfig.pb.go: toolkitConfig.proto
clean:
rm -f go.* *.pb.go
go-mod-clean --purge

View File

@ -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)
}

39
date.go Normal file
View File

@ -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)
}

View File

@ -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
View File

@ -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)
}

View File

@ -28,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)
// }
@ -202,6 +200,7 @@ func (me *TreeInfo) makeTable(t *guipb.Table) {
return
}
me.Add(grid)
grid.State.ProgName = "TableGridPB"
// log.Info("tree: makeTable() finished add win & grid")
var h int = 0
var w int = 0
@ -309,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)

View File

@ -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"
}