forge/windowViewPatch.go

147 lines
3.4 KiB
Go

package main
import (
"strings"
"sync"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
"go.wit.com/gui"
)
type patchWindow 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
pset *forgepb.Patchset // the patchset in question
}
// todo: autogenerate these or make them standared 'gui' package functions
// make this an go interface somehow
// is the window hidden right now?
func (w *patchWindow) Hidden() bool {
return w.win.Hidden()
}
// switches between the window being visable or hidden on the desktop
func (w *patchWindow) Toggle() {
if w.Hidden() {
w.Show()
} else {
w.Hide()
}
}
// hides the window completely
func (w *patchWindow) Show() {
w.win.Show()
}
func (w *patchWindow) Hide() {
w.win.Hide()
}
// should be the first box/widget in the window
// greys out the window to the user
func (w *patchWindow) Disable() {
w.stack.Disable()
}
func (w *patchWindow) Enable() {
w.stack.Enable()
}
// you can only have one of these
func makePatchWindow(pset *forgepb.Patchset) *patchWindow {
pw := new(patchWindow)
// sync.Once()
pw.win = gadgets.RawBasicWindow("Patcheset for " + pset.Name + " (" + pset.Comment + ")")
pw.win.Make()
pw.stack = pw.win.Box().NewBox("bw vbox", false)
// me.reposwin.Draw()
pw.win.Custom = func() {
// sets the hidden flag to false so Toggle() works
pw.win.Hide()
}
grid := pw.stack.NewGrid("", 0, 0)
grid.NewLabel(pset.GitAuthorName)
grid.NewLabel(pset.GitAuthorEmail)
grid.NextRow()
grid.NewLabel("start branch: " + pset.StartBranchName)
grid.NewLabel(pset.StartBranchHash)
grid.NextRow()
grid.NewLabel("end branch: " + pset.EndBranchName)
grid.NewLabel(pset.EndBranchHash)
grid.NextRow()
grid.NewButton("Extract", func() {
if err := savePatchset(pset); err != nil {
log.Info("Save err:", err)
return
}
})
grid.NewButton("Apply", func() {
if _, _, _, err := IsEverythingOnDevel(); err != nil {
log.Info("You can only apply patches to the devel branch")
return
}
if IsAnythingDirty() {
log.Info("You can't apply patches when repos are dirty")
me.forge.PrintHumanTable(me.found)
return
}
if argv.Force {
applyPatchset(pset)
}
})
g := pw.stack.NewGroup("PatchSet List")
// add the patch grid
filegrid := g.NewGrid("", 0, 0)
all := pset.Patches.SortByFilename()
for all.Scan() {
p := all.Next()
// if IsValidPatch(p) {
filegrid.NewLabel(p.RepoNamespace)
filegrid.NewLabel(p.Comment)
filegrid.NewLabel(p.Filename)
filegrid.NewLabel(p.RepoPath)
filegrid.NewLabel(p.BranchName)
filegrid.NewLabel(p.BranchHash)
filegrid.NewLabel(p.CommitHash)
filegrid.NewLabel(p.StartHash)
filegrid.NextRow()
}
return pw
}
func (r *patchWindow) 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("Download", func() {
})
r.setgrid.NewButton("Apply", func() {
})
r.setgrid.NextRow()
}