126 lines
2.8 KiB
Go
126 lines
2.8 KiB
Go
package repostatus
|
|
|
|
import (
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/gui"
|
|
)
|
|
|
|
type repoBranchesWindow struct {
|
|
repo *gitpb.Repo // the repo protobuf
|
|
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
|
|
//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 *repoBranchesWindow) Hidden() bool {
|
|
return w.win.Hidden()
|
|
}
|
|
|
|
// switches between the window being visable or hidden on the desktop
|
|
func (w *repoBranchesWindow) Toggle() {
|
|
if w.Hidden() {
|
|
w.Show()
|
|
} else {
|
|
w.Hide()
|
|
}
|
|
}
|
|
|
|
// hides the window completely
|
|
func (w *repoBranchesWindow) Show() {
|
|
w.win.Show()
|
|
}
|
|
|
|
func (w *repoBranchesWindow) Hide() {
|
|
w.win.Hide()
|
|
}
|
|
|
|
// should be the first box/widget in the window
|
|
// greys out the window to the user
|
|
func (w *repoBranchesWindow) Disable() {
|
|
w.stack.Disable()
|
|
}
|
|
|
|
func (w *repoBranchesWindow) Enable() {
|
|
w.stack.Enable()
|
|
}
|
|
|
|
// you can only have one of these
|
|
func MakeRepoBranchesWindow(repo *gitpb.Repo) *repoBranchesWindow {
|
|
pw := new(repoBranchesWindow)
|
|
|
|
// sync.Once()
|
|
pw.win = gadgets.RawBasicWindow("Branches for " + repo.GetGoPath())
|
|
pw.win.Make()
|
|
|
|
pw.stack = pw.win.Box().NewBox("bw vbox", false)
|
|
// me.reposwin.Draw()
|
|
pw.win.Custom = func() {
|
|
log.Info("Got close. setting win.Hide()")
|
|
// sets the hidden flag to false so Toggle() works
|
|
pw.win.Hide()
|
|
}
|
|
|
|
grid := pw.stack.NewGrid("", 0, 0)
|
|
|
|
grid.NewGroup("Branches")
|
|
grid.NextRow()
|
|
|
|
grid.NewGroup("Name")
|
|
grid.NewGroup("Forge use")
|
|
grid.NewGroup("Ref Version")
|
|
grid.NewGroup("Type")
|
|
grid.NewGroup("Hash")
|
|
grid.NextRow()
|
|
|
|
for _, b := range repo.GetLocalBranches() {
|
|
hash := repo.GetBranchHash(b)
|
|
grid.NewLabel(b)
|
|
grid.NewLabel(repo.GetBranchVersion(b))
|
|
if s, err := repo.GetHashName(hash); err == nil {
|
|
grid.NewLabel(s)
|
|
} else {
|
|
grid.NewLabel("err")
|
|
}
|
|
grid.NewLabel("local")
|
|
|
|
grid.NewLabel(hash)
|
|
grid.NewButton("Delete", func() {
|
|
repo.RunVerbose([]string{"git", "branch", "-D", b})
|
|
})
|
|
grid.NextRow()
|
|
}
|
|
|
|
for _, b := range repo.GetRemoteBranches() {
|
|
hash := repo.GetBranchHash(b)
|
|
grid.NewLabel(b)
|
|
forgeuse := repo.GetBranchVersion(b)
|
|
grid.NewLabel(forgeuse)
|
|
if s, err := repo.GetHashName(hash); err == nil {
|
|
grid.NewLabel(s)
|
|
} else {
|
|
grid.NewLabel("")
|
|
}
|
|
grid.NewLabel("remote")
|
|
|
|
grid.NewLabel(hash)
|
|
if b == "origin/HEAD" || forgeuse == "remote master" {
|
|
// can't delete these
|
|
} else {
|
|
grid.NewButton("Delete Remote", func() {
|
|
})
|
|
}
|
|
grid.NextRow()
|
|
}
|
|
|
|
return pw
|
|
}
|