forgepb/set.gui.pb.go

329 lines
7.5 KiB
Go

// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.5.6-1-g08dc949 2025.09.23_0925
// go install go.wit.com/apps/autogenpb@latest
//
// define which structs (messages) you want to use in the .proto file
// Then sort.pb.go and marshal.pb.go files are autogenerated
//
// autogenpb uses it and has an example .proto file with instructions
//
package forgepb
import (
"time"
"github.com/google/uuid"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"google.golang.org/protobuf/proto"
anypb "google.golang.org/protobuf/types/known/anypb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
// START GUI
func (x *Sets) NewTable(title string) *SetsTable {
t := new(SetsTable)
t.x = x
pb := new(guipb.Table)
pb.Title = title
t.pb = pb
return t
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *SetsTable) AddStringFunc(title string, f func(*Set) string) *SetAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(SetAnyFunc)
sf.title = title
sf.f = func(x *Set) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_STRING
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *SetsTable) AddButtonFunc(title string, f func(*Set) string) *SetAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(SetAnyFunc)
sf.title = title
sf.f = func(x *Set) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_STRING
sf.attr.Click = true
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *SetsTable) AddIntFunc(title string, f func(*Set) int) *SetAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(SetAnyFunc)
sf.title = title
sf.f = func(x *Set) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_INT
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
// force the application to choose the type of data. this allows the GUI plugin to be smarter
func (t *SetsTable) AddTimeFunc(title string, f func(*Set) time.Time) *SetAnyFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(SetAnyFunc)
sf.title = title
sf.f = func(x *Set) any {
return f(x)
}
sf.attr = new(guipb.ColAttr)
sf.attr.Width = int32(sf.Width)
sf.attr.Type = guipb.ColAttr_TIME
// t.timeFuncs = append(t.timeFuncs, sf)
t.anyFuncs = append(t.anyFuncs, sf)
return sf
}
func (sf *SetAnyFunc) SetTitle(title string) {
sf.title = title
}
func (mt *SetsTable) SetParent(p *gui.Node) {
mt.parent = p
}
func (mt *SetsTable) ShowTable() {
// log.Info("ShowTable() SENDING TO GUI")
mt.MakeTable()
mt.parent.ShowTable(mt.pb)
}
type SetAnyFunc struct {
title string
f func(*Set) any
Custom func(*Set)
Width int
attr *guipb.ColAttr
}
type SetsTable struct {
pb *guipb.Table
parent *gui.Node
x *Sets
hostnames []string
anyFuncs []*SetAnyFunc
CustomFunc func(*Set)
}
func (mt *SetsTable) doAnyFuncNew(sf *SetAnyFunc) bool {
r := new(guipb.AnyCol)
r.Header = new(guipb.Widget)
r.Header.Name = sf.title
r.Attr = proto.Clone(sf.attr).(*guipb.ColAttr)
r.Attr.Width = int32(sf.Width)
for m := range mt.x.IterAll() {
t := sf.f(m)
switch r.Attr.Type {
case guipb.ColAttr_STRING:
// anyProto, err := anypb.New(tsProto)
stringValue := wrapperspb.String(t.(string))
anyProto, err := anypb.New(stringValue)
_ = err // do something with err someday (?)
r.Vals = append(r.Vals, anyProto)
// return col.Vals[row] true
case guipb.ColAttr_INT:
var finalInt int
finalInt = t.(int)
intVal := wrapperspb.Int32(int32(finalInt))
anyProto, _ := anypb.New(intVal)
r.Vals = append(r.Vals, anyProto)
case guipb.ColAttr_DURATION:
case guipb.ColAttr_TIME:
var goTime time.Time
goTime = t.(time.Time)
tsProto := timestamppb.New(goTime)
anyProto, err := anypb.New(tsProto)
_ = err // do something with err someday (?)
r.Vals = append(r.Vals, anyProto)
default:
log.Info("cell unhandled type", r.Attr.Type)
}
// cellTime := r.Vals[row]
// s := shell.FormatDuration(time.Since(cellTime.AsTime()))
}
mt.pb.AnyCols = append(mt.pb.AnyCols, r)
return true
}
func (mt *SetsTable) MakeTable() {
for _, sf := range mt.anyFuncs {
mt.doAnyFuncNew(sf)
}
}
func (t *SetsTable) AddUuid() *SetAnyFunc {
sf := t.AddStringFunc("Uuid", func(m *Set) string {
return m.Uuid
})
return sf
}
func (t *SetsTable) AddSubmitter() *SetAnyFunc {
sf := t.AddStringFunc("Submitter", func(m *Set) string {
return m.Submitter
})
return sf
}
func (t *SetsTable) AddName() *SetAnyFunc {
sf := t.AddStringFunc("Name", func(m *Set) string {
return m.Name
})
return sf
}
func (t *SetsTable) AddGitAuthorName() *SetAnyFunc {
sf := t.AddStringFunc("GitAuthorName", func(m *Set) string {
return m.GitAuthorName
})
return sf
}
func (t *SetsTable) AddGitAuthorEmail() *SetAnyFunc {
sf := t.AddStringFunc("GitAuthorEmail", func(m *Set) string {
return m.GitAuthorEmail
})
return sf
}
func (t *SetsTable) AddHostname() *SetAnyFunc {
sf := t.AddStringFunc("Hostname", func(m *Set) string {
return m.Hostname
})
return sf
}
func (t *SetsTable) AddTmpDir() *SetAnyFunc {
sf := t.AddStringFunc("TmpDir", func(m *Set) string {
return m.TmpDir
})
return sf
}
func (t *SetsTable) AddStartBranchName() *SetAnyFunc {
sf := t.AddStringFunc("StartBranchName", func(m *Set) string {
return m.StartBranchName
})
return sf
}
func (t *SetsTable) AddEndBranchName() *SetAnyFunc {
sf := t.AddStringFunc("EndBranchName", func(m *Set) string {
return m.EndBranchName
})
return sf
}
func (t *SetsTable) AddStartBranchHash() *SetAnyFunc {
sf := t.AddStringFunc("StartBranchHash", func(m *Set) string {
return m.StartBranchHash
})
return sf
}
func (t *SetsTable) AddEndBranchHash() *SetAnyFunc {
sf := t.AddStringFunc("EndBranchHash", func(m *Set) string {
return m.EndBranchHash
})
return sf
}
func (t *SetsTable) AddComment() *SetAnyFunc {
sf := t.AddStringFunc("Comment", func(m *Set) string {
return m.Comment
})
return sf
}
func (t *SetsTable) AddState() *SetAnyFunc {
sf := t.AddStringFunc("State", func(m *Set) string {
return m.State
})
return sf
}
func (mt *SetsTable) NewUuid() {
mt.pb.Uuid = uuid.New().String()
}
// START TABLE UPDATE (doesn't work yet)
func (mt *SetsTable) dumpStringFunc(name string) {
for i, r := range mt.pb.StringCols {
// log.Info("could use", i, r.Header.Name, "for name =", name)
if r.Header.Name == name {
log.Info("dump Strings row", i, r.Header.Name, r.Vals)
break
}
}
}
func (mt *SetsTable) Delete() {
if mt == nil {
log.Info("mt == nil table already deleted")
return
}
// log.Info("table Delete here")
mt.parent.DeleteTable(mt.pb)
}
func (mt *SetsTable) setsCustom(w *guipb.Widget) {
row := mt.x.Sets[w.Location.Y-1]
// log.Info("got to setsCustom() with", w.Location.X, w.Location.Y-1)
for i, sf := range mt.anyFuncs {
if i == int(w.Location.X) {
if sf.Custom != nil {
log.Info("doing Custom() func for button")
sf.Custom(row)
return
}
}
}
mt.CustomFunc(row)
}
func (mt *SetsTable) Custom(f func(*Set)) {
mt.pb.RegisterCustom(mt.setsCustom)
mt.CustomFunc = f
}
func (mt *SetsTable) GetUuid() string {
return mt.pb.Uuid
}
// END TABLE UPDATE
// END GUI