149 lines
3.2 KiB
Go
149 lines
3.2 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"strings"
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/gui/gui"
|
|
"go.wit.com/gui/gadgets"
|
|
"go.wit.com/apps/control-panel-dns/smartwindow"
|
|
"go.wit.com/apps/myrepos/repostatus"
|
|
)
|
|
|
|
var myGui *gui.Node
|
|
|
|
var allrepos []*repo
|
|
|
|
type repo struct {
|
|
path string
|
|
lasttagrev string
|
|
lasttag string
|
|
tags []string
|
|
|
|
pLabel *gui.Node // path label
|
|
bLabel *gui.Node // branch label
|
|
lastLabel *gui.Node // last tagged version label
|
|
vLabel *gui.Node // version label
|
|
tagsDrop *gui.Node // list of all tags
|
|
dirtyLabel *gui.Node // git state (dirty or not?)
|
|
|
|
masterVersion *gui.Node // the master branch version
|
|
develVersion *gui.Node // the devel branch version
|
|
jcarrVersion *gui.Node // the jcarr branch version
|
|
|
|
cButton *gui.Node // commit button
|
|
pButton *gui.Node // push button
|
|
|
|
status *repostatus.RepoStatus
|
|
}
|
|
|
|
func main() {
|
|
myGui = gui.New().Default()
|
|
|
|
repoworld()
|
|
checkrepos()
|
|
gui.Watchdog()
|
|
}
|
|
|
|
func addRepo(grid *gui.Node, path string) *repo {
|
|
newRepo := new(repo)
|
|
|
|
newRepo.path = path
|
|
newRepo.pLabel = grid.NewLabel(path)
|
|
newRepo.bLabel = grid.NewLabel("")
|
|
newRepo.lastLabel = grid.NewLabel("")
|
|
newRepo.vLabel = grid.NewLabel("")
|
|
newRepo.tagsDrop = grid.NewDropdown("tags")
|
|
|
|
newRepo.masterVersion = grid.NewLabel("")
|
|
newRepo.develVersion = grid.NewLabel("")
|
|
newRepo.jcarrVersion = grid.NewLabel("")
|
|
newRepo.dirtyLabel = grid.NewLabel("")
|
|
|
|
newRepo.cButton = grid.NewButton("status", func () {
|
|
log.Println("repo status for", newRepo.path)
|
|
newRepo.scan()
|
|
if newRepo.status == nil {
|
|
newRepo.status = repostatus.New(myGui, newRepo.path)
|
|
newRepo.status.Vertical()
|
|
newRepo.status.Horizontal()
|
|
newRepo.status.Make()
|
|
newRepo.status.Draw()
|
|
newRepo.status.Draw2()
|
|
}
|
|
newRepo.status.Toggle()
|
|
})
|
|
newRepo.pButton = grid.NewButton("rescan", func () {
|
|
newRepo.scan()
|
|
})
|
|
if path == "" {
|
|
newRepo.cButton.Hide()
|
|
newRepo.pButton.Hide()
|
|
return newRepo
|
|
}
|
|
allrepos = append(allrepos, newRepo)
|
|
return newRepo
|
|
}
|
|
|
|
// This creates a window
|
|
func repoworld() {
|
|
win := gadgets.NewBasicWindow(myGui, "git autotypist. it types faster than you can.")
|
|
|
|
box := win.Box().NewBox("bw vbox", false)
|
|
// box2 := win.Box().NewBox("bw vbox", false)
|
|
group := box.NewGroup("go repositories (read from ~/.config/myrepolist)")
|
|
grid := group.NewGrid("test", 11, 1)
|
|
|
|
grid.NewLabel("")
|
|
grid.NewLabel("branch")
|
|
grid.NewLabel("last tag")
|
|
grid.NewLabel("Version")
|
|
grid.NewLabel("tags")
|
|
grid.NewLabel("master")
|
|
grid.NewLabel("devel")
|
|
grid.NewLabel("jcarr")
|
|
grid.NewLabel("Status")
|
|
grid.NewLabel("commit")
|
|
grid.NewLabel("push to")
|
|
|
|
repos := myrepolist()
|
|
for _, repo := range repos {
|
|
log.Warn("repo =", repo)
|
|
addRepo(grid, repo)
|
|
}
|
|
|
|
win.Draw()
|
|
}
|
|
|
|
// This creates a window
|
|
func hellosmart() {
|
|
win := smartwindow.New()
|
|
win.SetParent(myGui)
|
|
win.InitWindow()
|
|
win.Title("hellosmart test")
|
|
win.Vertical()
|
|
win.SetDraw(smartDraw)
|
|
win.Make()
|
|
|
|
win.Box().NewButton("test smartwindow", func () {
|
|
log.Println("smart")
|
|
})
|
|
}
|
|
|
|
func smartDraw(sw *smartwindow.SmartWindow) {
|
|
sw.Box().NewButton("hello", func () {
|
|
log.Println("smart")
|
|
})
|
|
}
|
|
|
|
func myrepolist() []string {
|
|
content, _ := ioutil.ReadFile("/home/jcarr/.config/myrepolist")
|
|
out := string(content)
|
|
out = strings.TrimSpace(out)
|
|
lines := strings.Split(out, "\n")
|
|
return lines
|
|
}
|