From 152a25591d5288c7a2391ddc640bf6a689988b29 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 29 Jan 2025 11:31:42 -0600 Subject: make a seperate window to maintain the patches --- windowViewPatch.go | 161 -------------------------------------------- windowViewPatchset.go | 169 +++++++++++++++++++++++++++++++++++++++++++++++ windowViewRepoPatches.go | 135 +++++++++++++++++++++++++++++++++++++ 3 files changed, 304 insertions(+), 161 deletions(-) delete mode 100644 windowViewPatch.go create mode 100644 windowViewPatchset.go create mode 100644 windowViewRepoPatches.go diff --git a/windowViewPatch.go b/windowViewPatch.go deleted file mode 100644 index d4b9689..0000000 --- a/windowViewPatch.go +++ /dev/null @@ -1,161 +0,0 @@ -package main - -import ( - "sync" - - "go.wit.com/lib/gadgets" - "go.wit.com/lib/protobuf/forgepb" - "go.wit.com/lib/protobuf/gitpb" - "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 files to disk", func() { - if err := savePatchset(pset); err != nil { - log.Info("Save err:", err) - return - } - }) - grid.NewButton("Apply with git am", 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") - - // make a grid and a header - filegrid := g.NewGrid("", 0, 0) - filegrid.NewLabel("repo") - filegrid.NewLabel("patch name") - filegrid.NewLabel("Applied in current branch?") - filegrid.NewLabel("start hash") - filegrid.NextRow() - - // add the patches to the grid - pw.addPatchset(filegrid, pset) - return pw -} - -func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) { - repomap := make(map[*gitpb.Repo][]*forgepb.Patch) - repohash := make(map[*gitpb.Repo]string) - - // sort patches by repo namespace - all := pset.Patches.SortByFilename() - for all.Scan() { - p := all.Next() - s := p.RepoNamespace - repo := me.forge.FindByGoPath(s) - if repo == nil { - log.Info("COULD NOT FIND", s) - continue - } - repomap[repo] = append(repomap[repo], p) - repohash[repo] = p.StartHash - } - - // var repo *gitpb.Repo - - for repo, patches := range repomap { - log.Info(repo.GetGoPath()) - grid.NewLabel(repo.GetGoPath()) - - for i, p := range patches { - log.Info(i, p.Filename) - grid.NewLabel(p.Comment) - grid.NewLabel("in current branch?") - break - } - hash := repohash[repo] - grid.NewLabel(hash) - grid.NewButton("View", func() { - log.Info("todo: show patches for repo", repo.GetGoPath()) - }) - grid.NextRow() - } -} diff --git a/windowViewPatchset.go b/windowViewPatchset.go new file mode 100644 index 0000000..3e4f374 --- /dev/null +++ b/windowViewPatchset.go @@ -0,0 +1,169 @@ +package main + +import ( + "sync" + + "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" + "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 files to disk", func() { + if err := savePatchset(pset); err != nil { + log.Info("Save err:", err) + return + } + }) + grid.NewButton("Apply with git am", 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") + + // make a grid and a header + filegrid := g.NewGrid("", 0, 0) + filegrid.NewLabel("repo") + filegrid.NewLabel("patch name") + filegrid.NewLabel("Applied in current branch?") + filegrid.NewLabel("start hash") + filegrid.NextRow() + + // add the patches to the grid + pw.addPatchset(filegrid, pset) + return pw +} + +func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) { + repomap := make(map[*gitpb.Repo][]*forgepb.Patch) + repohash := make(map[*gitpb.Repo]string) + + // sort patches by repo namespace + all := pset.Patches.SortByFilename() + for all.Scan() { + p := all.Next() + s := p.RepoNamespace + repo := me.forge.FindByGoPath(s) + if repo == nil { + log.Info("COULD NOT FIND", s) + continue + } + repomap[repo] = append(repomap[repo], p) + repohash[repo] = p.StartHash + } + + // var repo *gitpb.Repo + + for repo, patches := range repomap { + log.Info(repo.GetGoPath()) + grid.NewLabel(repo.GetGoPath()) + + for i, p := range patches { + log.Info(i, p.Filename) + grid.NewLabel(p.Comment) + grid.NewLabel("in current branch?") + break + } + hash := repohash[repo] + grid.NewLabel(hash) + var win *repoPatchWindow + grid.NewButton("View", func() { + if win != nil { + win.Toggle() + log.Info("TRYING TO TOGGLE WINDOW") + return + } + + win = makeRepoPatchWindow(repo, patches) + win.Show() + }) + grid.NextRow() + } +} diff --git a/windowViewRepoPatches.go b/windowViewRepoPatches.go new file mode 100644 index 0000000..dcab4ab --- /dev/null +++ b/windowViewRepoPatches.go @@ -0,0 +1,135 @@ +package main + +import ( + "sync" + + "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" + + "go.wit.com/gui" +) + +type repoPatchWindow 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 *repoPatchWindow) Hidden() bool { + return w.win.Hidden() +} + +// switches between the window being visable or hidden on the desktop +func (w *repoPatchWindow) Toggle() { + if w.Hidden() { + w.Show() + } else { + w.Hide() + } +} + +// hides the window completely +func (w *repoPatchWindow) Show() { + w.win.Show() +} + +func (w *repoPatchWindow) Hide() { + w.win.Hide() +} + +// should be the first box/widget in the window +// greys out the window to the user +func (w *repoPatchWindow) Disable() { + w.stack.Disable() +} + +func (w *repoPatchWindow) Enable() { + w.stack.Enable() +} + +// you can only have one of these +func makeRepoPatchWindow(repo *gitpb.Repo, fset []*forgepb.Patch) *repoPatchWindow { + pw := new(repoPatchWindow) + + // sync.Once() + pw.win = gadgets.RawBasicWindow("Patcheset for " + repo.GetGoPath()) + 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.NewButton("Extract files to disk", func() { + }) + grid.NewButton("Apply with git am", func() { + }) + + g := pw.stack.NewGroup("PatchSet List") + + // make a grid and a header + filegrid := g.NewGrid("", 0, 0) + filegrid.NewLabel("repo") + filegrid.NewLabel("patch name") + filegrid.NewLabel("Applied in current branch?") + filegrid.NewLabel("start hash") + filegrid.NextRow() + + // add the patches to the grid + // pw.addPatchset(filegrid, pset) + return pw +} + +func (r *repoPatchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) { + repomap := make(map[*gitpb.Repo][]*forgepb.Patch) + repohash := make(map[*gitpb.Repo]string) + + // sort patches by repo namespace + all := pset.Patches.SortByFilename() + for all.Scan() { + p := all.Next() + s := p.RepoNamespace + repo := me.forge.FindByGoPath(s) + if repo == nil { + log.Info("COULD NOT FIND", s) + continue + } + repomap[repo] = append(repomap[repo], p) + repohash[repo] = p.StartHash + } + + // var repo *gitpb.Repo + + for repo, patches := range repomap { + log.Info(repo.GetGoPath()) + grid.NewLabel(repo.GetGoPath()) + + for i, p := range patches { + log.Info(i, p.Filename) + grid.NewLabel(p.Comment) + grid.NewLabel("in current branch?") + break + } + hash := repohash[repo] + grid.NewLabel(hash) + grid.NewButton("View", func() { + log.Info("todo: show patches for repo", repo.GetGoPath()) + }) + grid.NextRow() + } +} -- cgit v1.2.3