general code and gui reorg

This commit is contained in:
Jeff Carr 2025-03-04 04:29:14 -06:00
parent 6cb34ae52c
commit cad5321516
5 changed files with 272 additions and 244 deletions

184
doGui.go
View File

@ -11,7 +11,6 @@ import (
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/debugger"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
@ -217,114 +216,7 @@ func drawWindow(win *gadgets.GenericWindow) {
hackWin.Toggle() hackWin.Toggle()
return return
} }
hackWin := gadgets.NewGenericWindow("Hack / User Mode Window", "Things that might be wrong") hackWin = makeHackModeWindow()
grid := hackWin.Group.RawGrid()
grid.NewButton("git pull", func() {
log.Info("todo: run git pull on each repo")
})
me.repoDevelMergeB = grid.NewButton("merge", func() {
found := findMergeToDevel()
_, box := makeStandardReposWindow("repos to merge from user to devel", found)
hbox := box.Box().Horizontal()
hbox.NewButton("merge all", func() {
win.Disable()
defer win.Enable()
all := found.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.CheckDirty() {
log.Info("repo is dirty", repo.GetGoPath())
continue
}
log.Info("Starting merge on", repo.GetGoPath())
if repo.CheckoutDevel() {
log.Info("checkout devel failed", repo.GetGoPath())
return
}
if _, err := repo.MergeToDevel(); err != nil {
log.Info("merge from user failed", repo.GetGoPath(), err)
// log.Info(strings.Join(r.Stdout, "\n"))
// log.Info(strings.Join(r.Stderr, "\n"))
return
}
if repo.CheckoutMaster() {
log.Info("checkout master failed", repo.GetGoPath())
return
}
if _, err := repo.MergeToMaster(); err != nil {
log.Info("merge from devel failed", repo.GetGoPath(), err)
return
}
}
})
})
var problemsWin *repoProblemsWindow
grid.NewButton("Repo Problems", func() {
if problemsWin != nil {
problemsWin.Toggle()
return
}
problemsWin = makeRepoProblemsWindow()
})
grid.NextRow()
// grid := hackWin.Group.RawGrid()
group2 := hackWin.Stack.NewGroup("Merge")
grid = group2.RawGrid()
grid.NewButton("merge to devel", func() {
win.Disable()
defer win.Enable()
mergeUserToDevel(true)
})
grid.NewButton("merge to master", func() {
win.Disable()
defer win.Enable()
mergeDevelToMaster(true)
})
grid.NewButton("merge all", func() {
win.Disable()
defer win.Enable()
me.argvCheckoutUser = false
me.argvCheckoutDevel = true
me.argvCheckoutMaster = false
if err := doCheckoutShared(); err != nil {
log.Info("checkout error:", err)
} else {
log.Info("checkout was ok")
}
mergeUserToDevel(true)
me.argvCheckoutUser = false
me.argvCheckoutDevel = false
me.argvCheckoutMaster = true
if err := doCheckoutShared(); err != nil {
log.Info("checkout error:", err)
} else {
log.Info("checkout was ok")
}
mergeDevelToMaster(true)
})
group3 := hackWin.Stack.NewGroup("work in progress")
grid = group3.RawGrid()
grid.NewButton("forge ConfigSave()", func() {
me.forge.ConfigSave()
})
grid.NewButton("debugger()", func() {
debugger.DebugWindow()
})
}) })
var reposWin *gadgets.GenericWindow var reposWin *gadgets.GenericWindow
@ -352,80 +244,6 @@ func drawWindow(win *gadgets.GenericWindow) {
forgeSwitchMode(me.forge.Config.Mode) forgeSwitchMode(me.forge.Config.Mode)
} }
func makeReposWin() *gadgets.GenericWindow {
win := gadgets.NewGenericWindow("git repos", "All about git repos")
grid := win.Group.RawGrid()
me.repoDirtyB = grid.NewButton("dirty", func() {
doCheckDirtyAndConfigSave()
found := findDirty()
tb, box := makeStandardReposWindow("dirty repos", found)
hbox := box.Box().Horizontal()
hbox.NewButton("commit all", func() {
all := found.SortByFullPath()
for all.Scan() {
repo := all.Next()
log.Info("do commit here on", repo.GetGoPath())
}
log.Info("TODO: fix this")
log.Info("run 'forge commit --all'")
})
hbox.NewButton("update table", func() {
me.forge.PrintHumanTable(found)
found2 := findDirty()
me.forge.PrintHumanTable(found2)
tb.Update()
tb.UpdateTable(found2)
})
hbox.NewButton("delete table", func() {
tb.Delete()
})
})
var writeWin *gadgets.GenericWindow
me.repoWritableB = grid.NewButton("writable", func() {
// if the window exists, just toggle it open or closed
if writeWin != nil {
writeWin.Toggle()
return
}
// make the window for the first time
found := new(gitpb.Repos)
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
continue
}
found.AppendByGoPath(repo)
}
writeWin, _ = makeWritableWindow(found)
writeWin.Win.Custom = func() {
log.Info("closing window. could do somethine here")
}
})
me.repoAllB = grid.NewButton("All", func() {
me.found = new(gitpb.Repos)
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
me.found.AppendByGoPath(repo)
}
makeStandardReposWindow("All repos", me.found)
})
grid.NewButton("Configure", func() {
log.Info("add a forge config window here")
})
return win
}
// verify the GUI button disable/enable settings // verify the GUI button disable/enable settings
func forgeVerifyGuiState() { func forgeVerifyGuiState() {
me.forgeMode.SetText(me.forge.GetMode()) me.forgeMode.SetText(me.forge.GetMode())

View File

@ -12,7 +12,6 @@ import (
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui" "go.wit.com/gui"
@ -79,9 +78,6 @@ func (r *patchesWindow) submitPatchesBox() {
// make the header table for repo stats // make the header table for repo stats
r.totalOL = gadgets.NewOneLiner(grid, "Total") r.totalOL = gadgets.NewOneLiner(grid, "Total")
grid.NewButton("reset user branches", func() {
resetUserBranchesWindow()
})
grid.NextRow() grid.NextRow()
r.dirtyOL = gadgets.NewOneLiner(grid, "dirty") r.dirtyOL = gadgets.NewOneLiner(grid, "dirty")
@ -232,60 +228,3 @@ func (r *patchesWindow) Update() {
r.readonlyOL.SetText(strconv.Itoa(readonly) + " repos") r.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")
r.rw.SetText(fmt.Sprintf("%d repos", rw)) r.rw.SetText(fmt.Sprintf("%d repos", rw))
} }
func resetUserBranchesWindow() {
found := gitpb.NewRepos()
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
uname := repo.GetUserBranchName()
dname := repo.GetDevelBranchName()
if repo.GetCurrentBranchName() == uname {
log.Info("Repo is on the user branch. Can't delete it.", repo.GetGoPath())
continue
}
b1 := repo.CountDiffObjects(uname, dname)
b2 := repo.CountDiffObjects(dname, uname)
log.Info("user vs devel count", b1, b2)
if b1 == 0 && b2 == 0 {
cmd := []string{"git", "branch", "-D", uname}
log.Info(repo.GetGoPath(), cmd)
repo.RunVerbose(cmd)
repo.Reload()
continue
}
found.Append(repo)
}
win := gadgets.RawBasicWindow("reset user branches")
win.Make()
win.Show()
win.Custom = func() {
// sets the hidden flag to false so Toggle() works
win.Hide()
}
box := win.Box().NewBox("bw vbox", false)
group := box.NewGroup("test buttons")
hbox := group.Box().Horizontal()
hbox.NewButton("force delete user branch", func() {
win.Disable()
defer win.Enable()
all := found.SortByFullPath()
for all.Scan() {
repo := all.Next()
brname := repo.GetUserBranchName()
cmd := []string{"git", "branch", "-D", brname}
log.Info(repo.GetGoPath(), cmd)
repo.RunVerbose(cmd)
repo.Reload()
}
me.forge.SetConfigSave(true)
me.forge.ConfigSave()
})
t := makeStandardReposGrid(found)
t.SetParent(box)
t.ShowTable()
}

123
windowHackMode.go Normal file
View File

@ -0,0 +1,123 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// An app to submit patches for the 30 GO GUI repos
import (
"go.wit.com/lib/debugger"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
)
func makeHackModeWindow() *gadgets.GenericWindow {
win := gadgets.NewGenericWindow("git user branch / Hack Mode Window", "This is a work in progress")
grid := win.Group.RawGrid()
grid.NewButton("git pull", func() {
log.Info("todo: run git pull on each repo")
})
me.repoDevelMergeB = grid.NewButton("merge", func() {
found := findMergeToDevel()
_, box := makeStandardReposWindow("repos to merge from user to devel", found)
hbox := box.Box().Horizontal()
hbox.NewButton("merge all", func() {
win.Disable()
defer win.Enable()
all := found.SortByFullPath()
for all.Scan() {
repo := all.Next()
if repo.CheckDirty() {
log.Info("repo is dirty", repo.GetGoPath())
continue
}
log.Info("Starting merge on", repo.GetGoPath())
if repo.CheckoutDevel() {
log.Info("checkout devel failed", repo.GetGoPath())
return
}
if _, err := repo.MergeToDevel(); err != nil {
log.Info("merge from user failed", repo.GetGoPath(), err)
// log.Info(strings.Join(r.Stdout, "\n"))
// log.Info(strings.Join(r.Stderr, "\n"))
return
}
if repo.CheckoutMaster() {
log.Info("checkout master failed", repo.GetGoPath())
return
}
if _, err := repo.MergeToMaster(); err != nil {
log.Info("merge from devel failed", repo.GetGoPath(), err)
return
}
}
})
})
var problemsWin *repoProblemsWindow
grid.NewButton("Repo Problems", func() {
if problemsWin != nil {
problemsWin.Toggle()
return
}
problemsWin = makeRepoProblemsWindow()
})
grid.NextRow()
group2 := win.Stack.NewGroup("Merge")
grid = group2.RawGrid()
grid.NewButton("merge to devel", func() {
win.Disable()
defer win.Enable()
mergeUserToDevel(true)
})
grid.NewButton("merge to master", func() {
win.Disable()
defer win.Enable()
mergeDevelToMaster(true)
})
grid.NewButton("merge all", func() {
win.Disable()
defer win.Enable()
me.argvCheckoutUser = false
me.argvCheckoutDevel = true
me.argvCheckoutMaster = false
if err := doCheckoutShared(); err != nil {
log.Info("checkout error:", err)
} else {
log.Info("checkout was ok")
}
mergeUserToDevel(true)
me.argvCheckoutUser = false
me.argvCheckoutDevel = false
me.argvCheckoutMaster = true
if err := doCheckoutShared(); err != nil {
log.Info("checkout error:", err)
} else {
log.Info("checkout was ok")
}
mergeDevelToMaster(true)
})
group3 := win.Stack.NewGroup("work in progress")
grid = group3.RawGrid()
grid.NewButton("forge ConfigSave()", func() {
me.forge.ConfigSave()
})
grid.NewButton("debugger()", func() {
debugger.DebugWindow()
})
return win
}

View File

@ -5,6 +5,7 @@ package main
import ( import (
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -82,5 +83,66 @@ func makeModeMasterWin() *gadgets.GenericWindow {
f() f()
}) })
grid.NewButton("reset user branches (?)", func() {
resetUserBranchesWindow()
})
return win return win
} }
func resetUserBranchesWindow() {
found := gitpb.NewRepos()
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
uname := repo.GetUserBranchName()
dname := repo.GetDevelBranchName()
if repo.GetCurrentBranchName() == uname {
log.Info("Repo is on the user branch. Can't delete it.", repo.GetGoPath())
continue
}
b1 := repo.CountDiffObjects(uname, dname)
b2 := repo.CountDiffObjects(dname, uname)
log.Info("user vs devel count", b1, b2)
if b1 == 0 && b2 == 0 {
cmd := []string{"git", "branch", "-D", uname}
log.Info(repo.GetGoPath(), cmd)
repo.RunVerbose(cmd)
repo.Reload()
continue
}
found.Append(repo)
}
win := gadgets.RawBasicWindow("reset user branches")
win.Make()
win.Show()
win.Custom = func() {
// sets the hidden flag to false so Toggle() works
win.Hide()
}
box := win.Box().NewBox("bw vbox", false)
group := box.NewGroup("test buttons")
hbox := group.Box().Horizontal()
hbox.NewButton("force delete user branch", func() {
win.Disable()
defer win.Enable()
all := found.SortByFullPath()
for all.Scan() {
repo := all.Next()
brname := repo.GetUserBranchName()
cmd := []string{"git", "branch", "-D", brname}
log.Info(repo.GetGoPath(), cmd)
repo.RunVerbose(cmd)
repo.Reload()
}
me.forge.SetConfigSave(true)
me.forge.ConfigSave()
})
t := makeStandardReposGrid(found)
t.SetParent(box)
t.ShowTable()
}

86
windowRepos.go Normal file
View File

@ -0,0 +1,86 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// An app to submit patches for the 30 GO GUI repos
import (
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func makeReposWin() *gadgets.GenericWindow {
win := gadgets.NewGenericWindow("git repos", "All about git repos")
grid := win.Group.RawGrid()
me.repoDirtyB = grid.NewButton("dirty", func() {
doCheckDirtyAndConfigSave()
found := findDirty()
tb, box := makeStandardReposWindow("dirty repos", found)
hbox := box.Box().Horizontal()
hbox.NewButton("commit all", func() {
all := found.SortByFullPath()
for all.Scan() {
repo := all.Next()
log.Info("do commit here on", repo.GetGoPath())
}
log.Info("TODO: fix this")
log.Info("run 'forge commit --all'")
})
hbox.NewButton("update table", func() {
me.forge.PrintHumanTable(found)
found2 := findDirty()
me.forge.PrintHumanTable(found2)
tb.Update()
tb.UpdateTable(found2)
})
hbox.NewButton("delete table", func() {
tb.Delete()
})
})
var writeWin *gadgets.GenericWindow
me.repoWritableB = grid.NewButton("writable", func() {
// if the window exists, just toggle it open or closed
if writeWin != nil {
writeWin.Toggle()
return
}
// make the window for the first time
found := new(gitpb.Repos)
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
continue
}
found.AppendByGoPath(repo)
}
writeWin, _ = makeWritableWindow(found)
writeWin.Win.Custom = func() {
log.Info("closing window. could do somethine here")
}
})
me.repoAllB = grid.NewButton("All", func() {
me.found = new(gitpb.Repos)
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
me.found.AppendByGoPath(repo)
}
makeStandardReposWindow("All repos", me.found)
})
grid.NewButton("Configure", func() {
log.Info("add a forge config window here")
})
return win
}