diff options
Diffstat (limited to 'windowBook.go')
| -rw-r--r-- | windowBook.go | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/windowBook.go b/windowBook.go new file mode 100644 index 0000000..b90e91a --- /dev/null +++ b/windowBook.go @@ -0,0 +1,95 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "time" + + "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/chatpb" + "go.wit.com/log" +) + +func makeBookWindow(all *chatpb.Books) *gadgets.GenericWindow { + bookWin := gadgets.NewGenericWindow("regex Books", "Display Books") + bookWin.Win.Custom = func() { + log.Info("test delete window here") + } + grid := bookWin.Group.RawGrid() + + var t *chatpb.BooksTable + grid.NewButton("show", func() { + if t != nil { + log.Info("Delete the table first") + return + } + // display the protobuf + t = addBooksPB(bookWin, all) + f := func(chat *chatpb.Book) { + log.Info("got to BookTable.Custom() id =", chat.GetUuid(), chat.GetTitle()) + } + t.Custom(f) + log.Info("table has uuid", t.GetUuid()) + }) + + grid.NewButton("delete PB table", func() { + if t != nil { + t.Delete() + t = nil + log.Info("Table should have been deleted") + } + }) + // display the protobuf + t = addBooksPB(bookWin, all) + f := func(chat *chatpb.Book) { + log.Info("got to BookTable.Custom() id =", chat.GetUuid(), chat.GetTitle()) + } + t.Custom(f) + log.Info("table has uuid", t.GetUuid()) + + return bookWin +} + +func addBooksPB(win *gadgets.GenericWindow, pb *chatpb.Books) *chatpb.BooksTable { + t := pb.NewTable("testForgeRepos") + t.NewUuid() + tbox := win.Bottom.Box().SetProgName("TBOX") + t.SetParent(tbox) + + sf := t.AddStringFunc("uuid", func(r *chatpb.Book) string { + return r.GetUuid() + }) + sf.Custom = func(r *chatpb.Book) { + log.Info("todo: fix mouseClick() on stringFunc in GUI table", r.GetUuid()) + } + + // add a general show button + bf := t.AddButtonFunc("cur version", func(chat *chatpb.Book) string { return "show" }) + bf.Custom = func(r *chatpb.Book) { + log.Info("todo: show a chat window here", r.GetUuid()) + } + + // show the age of the chat + t.AddTimeFunc("age", func(book *chatpb.Book) time.Time { + return book.GetCtime().AsTime() + }) + t.AddTitle() + + // make a button to show content in the *genai.GeminiRequest structures + genaiButton := t.AddButtonFunc("# of parts", func(book *chatpb.Book) string { + if book.GeminiRequest == nil { + return "nil" + } + var req = book.GeminiRequest + return fmt.Sprintf("%d", len(req.Contents)) + }) + genaiButton.Custom = func(book *chatpb.Book) { + log.Info("show *genai.GeminiRequsts for", book.GetUuid()) + } + + // draw the tabel (send the gui protobuf to the GO plugin) + t.ShowTable() + return t +} |
