summaryrefslogtreecommitdiff
path: root/listWindow.go
diff options
context:
space:
mode:
Diffstat (limited to 'listWindow.go')
-rw-r--r--listWindow.go124
1 files changed, 124 insertions, 0 deletions
diff --git a/listWindow.go b/listWindow.go
new file mode 100644
index 0000000..5bcb9d7
--- /dev/null
+++ b/listWindow.go
@@ -0,0 +1,124 @@
+// This is a simple example
+package main
+
+import (
+ "io/ioutil"
+ "net/http"
+ "strings"
+
+ "go.wit.com/gui"
+ "go.wit.com/log"
+
+ "go.wit.com/lib/gadgets"
+)
+
+var lw *gadgets.BasicWindow
+var allsections []*section
+
+type section struct {
+ name string
+ parent *gui.Node
+ box *gui.Node
+ group *gui.Node
+ checkbox *gui.Node
+ repos []*gui.Node
+}
+
+func listWindow() {
+ if lw != nil {
+ lw.Toggle()
+ return
+ }
+ lw = gadgets.NewBasicWindow(me.myGui, "go.wit.com repositories")
+ lw.Custom = func() {
+ log.Warn("got to close")
+ }
+
+ lw.Make()
+ lw.StandardClose()
+ lw.Draw()
+ box := lw.Box()
+ group := box.NewGroup("list")
+ group.NewButton("blah", func() {})
+
+ var lines []string
+ var curs *section
+
+ lines = dumpURL("https://go.wit.com/list")
+ for i, line := range lines {
+ if line == "" {
+ continue
+ }
+ if line[0] == '#' {
+ curs = NewSection(group, line)
+ log.Warn("new group:", line)
+ continue
+ }
+ log.Warn(i, line)
+ parts := strings.Split(line, " ")
+ if curs != nil {
+ curs.add(parts[0])
+ }
+ }
+}
+
+func (s *section) add(path string) {
+ if s == nil {
+ return
+ }
+ tmp := s.parent.NewLabel(path)
+ s.repos = append(s.repos, tmp)
+}
+
+func NewSection(parent *gui.Node, path string) *section {
+ news := new(section)
+ news.parent = parent
+ news.box = news.parent.NewBox("bw vbox", true)
+ news.group = news.box.NewGroup(path)
+ news.checkbox = news.box.NewCheckbox("hide")
+ news.checkbox.Custom = func() {
+ news.toggle()
+ }
+ allsections = append(allsections, news)
+ return news
+}
+
+func (s *section) toggle() {
+ log.Warn(s.name)
+ for i, n := range s.repos {
+ log.Warn(i, n.String())
+ n.Hide()
+ }
+}
+
+/*
+func dumpURL(url string) string {
+ resp, err := http.Get(url)
+ if err != nil {
+ return ""
+ }
+ defer resp.Body.Close()
+
+ return resp.Body.String()
+
+ _, err = io.Copy(os.Stdout, resp.Body)
+ if err != nil {
+ return ""
+ }
+}
+*/
+
+func dumpURL(url string) []string {
+ resp, err := http.Get(url)
+ if err != nil {
+ return nil
+ }
+ defer resp.Body.Close()
+
+ bodyBytes, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil
+ }
+
+ return strings.Split(string(bodyBytes), "\n")
+}