From 4484b0b84d88fbad86ca6d202d3edfa9bb4946d0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 30 Jan 2025 13:35:22 -0600 Subject: [PATCH] new window for merge on a single repo --- Makefile | 3 + branchesBox.go | 59 +++------- windowMain.go | 53 ++++----- windowMerge.go | 197 ++++++++++++++++++++++++++++++++ modifyBox.go => windowModify.go | 0 5 files changed, 245 insertions(+), 67 deletions(-) create mode 100644 windowMerge.go rename modifyBox.go => windowModify.go (100%) diff --git a/Makefile b/Makefile index 07684a3..441b940 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,6 @@ redomod: GO111MODULE= go mod init GO111MODULE= go mod tidy +clean: + rm -f go.* + go-mod-clean --purge diff --git a/branchesBox.go b/branchesBox.go index 8849fb0..a14a5b2 100644 --- a/branchesBox.go +++ b/branchesBox.go @@ -2,59 +2,36 @@ package repostatus import ( "go.wit.com/gui" - "go.wit.com/lib/gadgets" "go.wit.com/log" ) func (rs *RepoStatus) makeBranchesBox(parent *gui.Node) { + repo := rs.pb rs.gitBranchesGroup = parent.NewGroup("branches") // `progname:"BRANCHES"` // can the toolkits use these for i18n support? - newgrid := rs.gitBranchesGroup.NewGrid("gridnuts", 0, 0) - - rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag") // `progname:"LASTTAG"` - newgrid.NextRow() - - rs.mainBranchVersion = gadgets.NewOneLiner(newgrid, "master") // `progname:"MASTERBRANCH"` - newgrid.NextRow() - rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel") // `progname:"DEVELBRANCH"` - newgrid.NextRow() - rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user") // `progname:"USERBRANCH"` - newgrid.NextRow() - - rs.currentBranch = gadgets.NewOneLiner(newgrid, "current branch") // `progname:"CURRENTBRANCH"` - newgrid.NextRow() - rs.currentVersion = gadgets.NewOneLiner(newgrid, "current version") // `progname:"CURRENTVERSION"` - newgrid.NextRow() - - /* - rs.switchBranchB = newgrid.NewButton("Switch Branch", func() { // `progname:"SWITCH"` - }) - - rs.targetBranch = newgrid.NewDropdown() // `progname:"TARGET"` - newgrid.NextRow() - - rs.showBranchesButton = newgrid.NewButton("find user and devel", func() { - log.Info("redo this") - }) - newgrid.NextRow() - - rs.checkBranchesButton = newgrid.NewButton("CheckBranches()", func() { - log.Info("redo this") - }) - newgrid.NextRow() - - newgrid.NewButton("Revert master to devel", func() { - log.Info("redo this") - }) - */ + grid := rs.gitBranchesGroup.RawGrid() var win *repoBranchesWindow - newgrid.NewButton("Branches Window", func() { + grid.NewButton("Branches Window", func() { if win != nil { win.Toggle() return } log.Info("redo this") - win = MakeRepoBranchesWindow(rs.pb) + win = MakeRepoBranchesWindow(repo) win.Show() }) + grid.NextRow() + + var mergeWin *repoMergeWindow + grid.NewButton("Merge Window", func() { + if mergeWin != nil { + mergeWin.Toggle() + return + } + log.Info("redo this") + mergeWin = rs.MakeRepoMergeWindow(repo) + mergeWin.Show() + }) + grid.NextRow() + } diff --git a/windowMain.go b/windowMain.go index 3a5f9da..6b075e3 100644 --- a/windowMain.go +++ b/windowMain.go @@ -1,8 +1,6 @@ package repostatus import ( - "os" - "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" @@ -55,39 +53,42 @@ func NewRepoStatusWindow(repo *gitpb.Repo) (*RepoStatus, error) { // display the git branches and options rs.makeBranchesBox(primarybox) + // var win *gadgets.BasicWindow // show standard git commit and merge controls rs.drawGitCommands(primarybox) - // save ~/go/src & the whole path strings - rs.path.SetValue(path) - rs.goSrcPath.SetValue(os.Getenv("FORGE_GOSRC")) - rs.realPath.SetValue(rs.pb.GetFullPath()) + /* + // save ~/go/src & the whole path strings + rs.path.SetValue(path) + rs.goSrcPath.SetValue(os.Getenv("FORGE_GOSRC")) + rs.realPath.SetValue(rs.pb.GetFullPath()) - // add all the tags - // rs.makeTagBox(box2) + // add all the tags + // rs.makeTagBox(box2) - // rs.readGitConfig() + // rs.readGitConfig() - if rs.pb.GetReadOnly() { - rs.readOnly.SetValue("true") - } else { - rs.readOnly.SetValue("false") - } - rs.mainWorkingName.SetText(rs.pb.GetMasterBranchName()) - rs.mainBranchVersion.SetLabel(rs.pb.GetMasterBranchName()) + if rs.pb.GetReadOnly() { + rs.readOnly.SetValue("true") + } else { + rs.readOnly.SetValue("false") + } + rs.mainWorkingName.SetText(rs.pb.GetMasterBranchName()) + rs.mainBranchVersion.SetLabel(rs.pb.GetMasterBranchName()) - rs.develWorkingName.SetText(rs.pb.GetDevelBranchName()) - rs.develBranchVersion.SetLabel(rs.pb.GetDevelBranchName()) + rs.develWorkingName.SetText(rs.pb.GetDevelBranchName()) + rs.develBranchVersion.SetLabel(rs.pb.GetDevelBranchName()) - rs.userWorkingName.SetText(rs.pb.GetUserBranchName()) - rs.userBranchVersion.SetLabel(rs.pb.GetUserBranchName()) + rs.userWorkingName.SetText(rs.pb.GetUserBranchName()) + rs.userBranchVersion.SetLabel(rs.pb.GetUserBranchName()) - if rs.pb.GetGoPath() == "" { - // not golang repo - } else { - rs.isGoLang.SetText("true") - rs.goPath.SetText(rs.pb.GetGoPath()) - } + if rs.pb.GetGoPath() == "" { + // not golang repo + } else { + rs.isGoLang.SetText("true") + rs.goPath.SetText(rs.pb.GetGoPath()) + } + */ windowMap[path] = rs return rs, nil } diff --git a/windowMerge.go b/windowMerge.go new file mode 100644 index 0000000..ee10586 --- /dev/null +++ b/windowMerge.go @@ -0,0 +1,197 @@ +package repostatus + +import ( + "go.wit.com/lib/gadgets" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" + + "go.wit.com/gui" +) + +type repoMergeWindow struct { + repo *gitpb.Repo // the repo protobuf + win *gadgets.BasicWindow // the patches window + stack *gui.Node // the top box set as vertical + lasttag *gadgets.OneLiner // the last tag version + mainBranchVersion *gadgets.OneLiner // the primary branch version + develBranchVersion *gadgets.OneLiner // the devel branch version + userBranchVersion *gadgets.OneLiner // the user branch version + + currentVersion *gadgets.OneLiner // the devel branch version + currentBranch *gadgets.OneLiner // the user branch version + + //shelf *gui.Node // the first box in the stack, set as horizontal + //grid *gui.Node // the list of available patches + //setgrid *gui.Node // the list of each patchset +} + +// todo: autogenerate these or make them standared 'gui' package functions +// make this an go interface somehow + +// is the window hidden right now? +func (w *repoMergeWindow) Hidden() bool { + return w.win.Hidden() +} + +// switches between the window being visable or hidden on the desktop +func (w *repoMergeWindow) Toggle() { + if w.Hidden() { + w.Show() + } else { + w.Hide() + } +} + +// hides the window completely +func (w *repoMergeWindow) Show() { + w.win.Show() + w.Update() +} + +func (w *repoMergeWindow) Hide() { + w.win.Hide() +} + +// should be the first box/widget in the window +// greys out the window to the user +func (w *repoMergeWindow) Disable() { + w.stack.Disable() +} + +func (w *repoMergeWindow) Enable() { + w.stack.Enable() +} + +func (w *repoMergeWindow) Update() { + w.lasttag.SetText(w.repo.GetLastTag()) + w.mainBranchVersion.SetText(w.repo.GetMasterVersion()) + w.develBranchVersion.SetText(w.repo.GetDevelVersion()) + w.userBranchVersion.SetText(w.repo.GetUserVersion()) + + w.currentBranch.SetText(w.repo.GetCurrentBranchName()) + w.currentVersion.SetText(w.repo.GetCurrentVersion()) +} + +func (rs *RepoStatus) MakeRepoMergeWindow(repo *gitpb.Repo) *repoMergeWindow { + w := new(repoMergeWindow) + w.repo = repo + + // sync.Once() + w.win = gadgets.RawBasicWindow("Merge controls for " + repo.GetGoPath()) + w.win.Make() + + w.stack = w.win.Box().NewBox("bw vbox", false) + // me.reposwin.Draw() + w.win.Custom = func() { + log.Info("Got close. setting win.Hide()") + // sets the hidden flag to false so Toggle() works + w.win.Hide() + } + + grid := w.stack.NewGrid("", 0, 0) + + grid.NewGroup("Merge Options") + grid.NextRow() + + grid.NewButton("checkout user", func() { + if err := repo.CheckoutUser(); err != nil { + log.Info(repo.GetFullPath(), err) + } + w.repo.Reload() + w.Update() + }) + grid.NextRow() + grid.NewButton("checkout devel", func() { + repo.CheckoutDevel() + w.repo.Reload() + w.Update() + }) + grid.NewButton("merge to devel", func() { + log.Info("repo:", repo.GetGoPath()) + if result, err := repo.MergeToDevel(); err == nil { + log.Warn("THINGS SEEM OK", repo.GetFullPath()) + for _, line := range result.Stdout { + log.Warn("stdout:", line) + } + for _, line := range result.Stderr { + log.Warn("stderr:", line) + } + } else { + log.Warn("THINGS FAILED ", repo.GetFullPath()) + log.Warn("err", err) + for _, line := range result.Stdout { + log.Warn("stdout:", line) + } + for _, line := range result.Stderr { + log.Warn("stderr:", line) + } + } + w.repo.Reload() + w.Update() + }) + grid.NextRow() + grid.NewButton("checkout master", func() { + repo.CheckoutMaster() + w.repo.Reload() + w.Update() + }) + grid.NewButton("merge to master", func() { + log.Info("repo:", repo.GetGoPath()) + if result, err := repo.MergeToMaster(); err == nil { + log.Warn("THINGS SEEM OK", repo.GetFullPath()) + for _, line := range result.Stdout { + log.Warn("stdout:", line) + } + for _, line := range result.Stderr { + log.Warn("stderr:", line) + } + } else { + log.Warn("THINGS FAILED ", repo.GetFullPath()) + log.Warn("err", err) + for _, line := range result.Stdout { + log.Warn("stdout:", line) + } + for _, line := range result.Stderr { + log.Warn("stderr:", line) + } + } + w.repo.Reload() + w.Update() + }) + grid.NextRow() + + w.lasttag = gadgets.NewOneLiner(grid, "last tag") // `progname:"LASTTAG"` + grid.NextRow() + + w.mainBranchVersion = gadgets.NewOneLiner(grid, "master") // `progname:"MASTERBRANCH"` + grid.NextRow() + w.develBranchVersion = gadgets.NewOneLiner(grid, "devel") // `progname:"DEVELBRANCH"` + grid.NextRow() + w.userBranchVersion = gadgets.NewOneLiner(grid, "user") // `progname:"USERBRANCH"` + grid.NextRow() + + w.currentBranch = gadgets.NewOneLiner(grid, "current branch") // `progname:"CURRENTBRANCH"` + grid.NextRow() + w.currentVersion = gadgets.NewOneLiner(grid, "current version") // `progname:"CURRENTVERSION"` + grid.NextRow() + + w.Update() + + return w +} + +/* + rs.showBranchesButton = newgrid.NewButton("find user and devel", func() { + log.Info("redo this") + }) + newgrid.NextRow() + + rs.checkBranchesButton = newgrid.NewButton("CheckBranches()", func() { + log.Info("redo this") + }) + newgrid.NextRow() + + newgrid.NewButton("Revert master to devel", func() { + log.Info("redo this") + }) +*/ diff --git a/modifyBox.go b/windowModify.go similarity index 100% rename from modifyBox.go rename to windowModify.go