diff --git a/send.go b/send.go index 745426a..6067baf 100644 --- a/send.go +++ b/send.go @@ -96,7 +96,28 @@ func doRegister(newurl string) error { return nil } +// gets the patch +// todo: move to forgepb func getPatch(pbfile string) (*forgepb.Patchset, error) { + url := me.urlbase + "/patchsetget?filename=" + pbfile + log.Info("getPatch() url", url) + body, err := me.forge.HttpPost(url, nil) + if err != nil { + log.Info("httpPost() failed:", err) + return nil, err + } + log.Info("getPatch() len(body)", len(body)) + var pset *forgepb.Patchset + pset = new(forgepb.Patchset) + err = pset.Unmarshal(body) + if err != nil { + log.Info("Unmarshal failed", err) + return nil, err + } + return pset, nil +} + +func savePatch(pbfile string) (*forgepb.Patchset, error) { url := me.urlbase + "/patchsetget?filename=" + pbfile log.Info("getPatch() url", url) body, err := me.forge.HttpPost(url, nil) diff --git a/windowPatches.go b/windowPatches.go index ad14e7f..4839f3d 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -13,14 +13,15 @@ import ( ) 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 + 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 { @@ -84,6 +85,7 @@ func (r *patchesWindow) initWindow() { // 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() @@ -108,12 +110,30 @@ func (r *patchesWindow) addPatchset(line string) { r.setgrid.NewLabel(subject) r.setgrid.NewLabel(author) r.setgrid.NewButton("Download", func() { + pset, err := savePatch(name) + if err != nil { + log.Info(name, "failed to download", err) + return + } + r.setlist[name] = pset + }) + 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.setgrid.NewButton("Dump", func() { pset := r.setlist[name] diff --git a/windowPatchesSummary.go b/windowPatchesSubmit.go similarity index 87% rename from windowPatchesSummary.go rename to windowPatchesSubmit.go index 5be64f7..518e7e1 100644 --- a/windowPatchesSummary.go +++ b/windowPatchesSubmit.go @@ -85,26 +85,6 @@ func (r *patchesWindow) submitPatchesBox(box *gui.Node) *patchSummary { me.patchWin.addPatchset(line) }) - /* - s.grid.NewButton("Apply Latest Patchset", func() { - lastp := lastPatch() - pset, err := getPatch(lastp) - if err != nil { - return - } - 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 - } - applyPatchset(pset) - }) - */ - // disable these until there are not dirty repos // s.reason.Disable() s.submitB.Disable() diff --git a/windowViewPatch.go b/windowViewPatch.go new file mode 100644 index 0000000..a59baa7 --- /dev/null +++ b/windowViewPatch.go @@ -0,0 +1,114 @@ +package main + +import ( + "strings" + "sync" + + "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/forgepb" + + "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") + 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) + + /* + r.shelf = r.initGroup() + group1 := r.stack.NewGroup("stuff") + vbox := group1.Box() + vbox.Vertical() + */ + + g := pw.stack.NewGroup("PatchSet List") + + // add the patch grid + g.NewGrid("", 0, 0) + + /* + for i, line := range lines { + log.Info(i, line) + r.addFile(line) + } + */ + 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() +}