139 lines
3.0 KiB
Go
139 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/gui"
|
|
)
|
|
|
|
type patchesWindow struct {
|
|
once sync.Once // only init() the window once
|
|
win *gadgets.BasicWindow // the patches window
|
|
stack *gui.Node // the top box set as vertical
|
|
shelf *gui.Node // the first box in the stack, set as horizontal
|
|
grid *gui.Node // the list of available patches
|
|
summary *patchSummary // summary of current patches
|
|
setgrid *gui.Node // the list of each patchset
|
|
setlist map[string]*forgepb.Patchset // a map of the patch names to the protobuf
|
|
setwin map[string]*patchWindow // a map of the patch names to the protobuf
|
|
}
|
|
|
|
func (r *patchesWindow) Hidden() bool {
|
|
return r.win.Hidden()
|
|
}
|
|
|
|
func (r *patchesWindow) Toggle() {
|
|
if r.Hidden() {
|
|
r.Show()
|
|
} else {
|
|
r.Hide()
|
|
}
|
|
}
|
|
|
|
func (r *patchesWindow) Show() {
|
|
r.win.Show()
|
|
}
|
|
|
|
func (r *patchesWindow) Hide() {
|
|
r.win.Hide()
|
|
}
|
|
|
|
func (r *patchesWindow) Disable() {
|
|
r.stack.Disable()
|
|
}
|
|
|
|
func (r *patchesWindow) Enable() {
|
|
r.stack.Enable()
|
|
}
|
|
|
|
// you can only have one of these
|
|
func (r *patchesWindow) initWindow() {
|
|
// sync.Once()
|
|
r.win = gadgets.RawBasicWindow("Forge Patchesets")
|
|
r.win.Make()
|
|
|
|
r.stack = r.win.Box().NewBox("bw vbox", false)
|
|
// me.reposwin.Draw()
|
|
r.win.Custom = func() {
|
|
log.Warn("Patchset Window close. setting hidden=true")
|
|
// sets the hidden flag to false so Toggle() works
|
|
r.win.Hide()
|
|
}
|
|
|
|
r.grid = r.stack.NewGrid("", 0, 0)
|
|
|
|
/*
|
|
r.shelf = r.initGroup()
|
|
group1 := r.stack.NewGroup("stuff")
|
|
vbox := group1.Box()
|
|
vbox.Vertical()
|
|
*/
|
|
|
|
r.summary = r.submitPatchesBox(r.stack)
|
|
|
|
// update the stats about the repos and patches
|
|
r.summary.Update()
|
|
|
|
g := r.stack.NewGroup("PatchSet List")
|
|
|
|
// add the grid
|
|
r.setgrid = g.NewGrid("", 0, 0)
|
|
r.setlist = make(map[string]*forgepb.Patchset)
|
|
r.setwin = make(map[string]*patchWindow)
|
|
|
|
// query for current patchsets
|
|
lines, err := listPatches()
|
|
if err != nil {
|
|
log.Info(err)
|
|
return
|
|
}
|
|
slices.Reverse(lines)
|
|
count := 0
|
|
for i, line := range lines {
|
|
log.Info(i, line)
|
|
count += 1
|
|
if count < 10 {
|
|
r.addPatchset(line)
|
|
}
|
|
}
|
|
log.Info("Total patchsets:", count)
|
|
}
|
|
|
|
func (r *patchesWindow) addPatchset(line string) {
|
|
parts := strings.Split(line, "Author:")
|
|
author := parts[1]
|
|
parts = strings.Fields(parts[0])
|
|
name := parts[0]
|
|
subject := strings.Join(parts[1:], " ")
|
|
r.setgrid.NewLabel(name)
|
|
r.setgrid.NewLabel(subject)
|
|
r.setgrid.NewLabel(author)
|
|
|
|
r.setgrid.NewButton("View", func() {
|
|
// has the window already been created?
|
|
win := r.setwin[name]
|
|
if win != nil {
|
|
win.Toggle()
|
|
log.Info("TRYING TO TOGGLE WINDOW")
|
|
return
|
|
}
|
|
|
|
// get the patch and make the window
|
|
pset, err := getPatch(name)
|
|
if err != nil {
|
|
log.Info(name, "failed to download", err)
|
|
return
|
|
}
|
|
r.setlist[name] = pset
|
|
r.setwin[name] = makePatchWindow(pset)
|
|
r.setwin[name].Show()
|
|
})
|
|
r.setgrid.NextRow()
|
|
}
|