2024-01-09 15:34:53 -06:00
|
|
|
package repostatus
|
|
|
|
|
2024-01-18 00:57:43 -06:00
|
|
|
import (
|
2024-01-23 10:52:17 -06:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2024-01-18 05:01:54 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-18 00:57:43 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/log"
|
2024-01-09 15:34:53 -06:00
|
|
|
)
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
var windowMap map[string]*RepoStatus
|
|
|
|
|
|
|
|
func ListAll() {
|
|
|
|
for path, rs := range windowMap {
|
|
|
|
log.Warn(rs.GetMasterVersion(), path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRepoStatusWindow(path string) *RepoStatus {
|
|
|
|
if windowMap[path] == nil {
|
2024-01-23 10:52:17 -06:00
|
|
|
log.Log(INFO, "NewRepoStatusWindow() adding new", path)
|
2024-01-21 03:18:07 -06:00
|
|
|
} else {
|
|
|
|
log.Warn("This already exists yet for path", path)
|
|
|
|
log.Warn("should return windowMap[path] here")
|
2024-01-23 10:52:17 -06:00
|
|
|
return windowMap[path]
|
|
|
|
}
|
|
|
|
|
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "Error getting home directory:", err)
|
|
|
|
return nil
|
2024-01-21 03:18:07 -06:00
|
|
|
}
|
2024-01-23 10:52:17 -06:00
|
|
|
|
|
|
|
goSrcDir := filepath.Join(homeDir, "go/src")
|
|
|
|
|
|
|
|
realpath := filepath.Join(goSrcDir, path)
|
|
|
|
filename := filepath.Join(realpath, ".git/config")
|
|
|
|
gitConfig, err := readGitConfig(filename)
|
|
|
|
|
|
|
|
// if the .git/config file fails to load, just nil out man
|
|
|
|
if err != nil {
|
|
|
|
log.Log(WARN, "Error reading .git/config:", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
rs := New(gui.TreeRoot(), path)
|
2024-01-23 15:20:54 -06:00
|
|
|
rs.draw(goSrcDir, realpath)
|
2024-01-23 10:52:17 -06:00
|
|
|
|
|
|
|
// save ~/go/src & the whole path strings
|
|
|
|
rs.goSrcPath.SetValue(goSrcDir)
|
|
|
|
rs.realPath.SetValue(realpath)
|
|
|
|
|
|
|
|
// save .git/config
|
|
|
|
rs.gitConfig = gitConfig
|
|
|
|
|
2024-01-21 03:18:07 -06:00
|
|
|
windowMap[path] = rs
|
|
|
|
|
|
|
|
// todo check if a window already exists for this path
|
|
|
|
return rs
|
|
|
|
}
|
|
|
|
|
2024-01-09 15:34:53 -06:00
|
|
|
func New(p *gui.Node, path string) *RepoStatus {
|
2024-01-18 00:57:43 -06:00
|
|
|
rs := &RepoStatus{
|
2024-01-23 15:20:54 -06:00
|
|
|
hidden: true,
|
|
|
|
ready: false,
|
|
|
|
parent: p,
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
|
|
|
rs.tags = make(map[string]string)
|
2024-01-18 00:57:43 -06:00
|
|
|
rs.window = gadgets.NewBasicWindow(p, "GO Repo Details "+path)
|
2024-01-14 10:00:42 -06:00
|
|
|
rs.window.Horizontal()
|
|
|
|
rs.window.Make()
|
2024-01-09 15:34:53 -06:00
|
|
|
rs.ready = true
|
2024-01-14 22:14:02 -06:00
|
|
|
rs.window.Custom = func() {
|
2024-01-15 00:17:01 -06:00
|
|
|
// rs.hidden = true
|
|
|
|
rs.Hide()
|
2024-01-14 22:14:02 -06:00
|
|
|
log.Warn("repostatus user closed the window()")
|
|
|
|
}
|
2024-01-21 03:18:07 -06:00
|
|
|
windowMap[path] = rs
|
2024-01-11 15:56:50 -06:00
|
|
|
return rs
|
2024-01-09 15:34:53 -06:00
|
|
|
}
|
2024-01-21 03:18:07 -06:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
windowMap = make(map[string]*RepoStatus)
|
|
|
|
}
|