summaryrefslogtreecommitdiff
path: root/windowBook.go
blob: 32ca20f5c198a56ab786d9be50091d1e2deab7c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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()
	// t.AddVersion()

	// 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())
		book.GeminiRequest.PrintGeminiTable()
	}

	// draw the tabel (send the gui protobuf to the GO plugin)
	t.ShowTable()
	return t
}