summaryrefslogtreecommitdiff
path: root/tagWindow.go
blob: 745ab62c939b90b2afd148a261a2027d0c9d1607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main

import (
	"go.wit.com/gui"
	"go.wit.com/log"

	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/repostatus"
)

var tagW *tagWindow

type tagWindow struct {
	win     *gadgets.BasicWindow
	box     *gui.Node
	grid    *gui.Node
	group   *gui.Node
	allTags []*gitTag
}

type gitTag struct {
	rs     *repostatus.RepoStatus
	hidden bool
}

func makeTagWindow() *tagWindow {
	if tagW != nil {
		tagW.win.Toggle()
		return tagW
	}
	tagW = new(tagWindow)
	tagW.win = gadgets.NewBasicWindow(me.myGui, "git tag tasks")
	tagW.win.Custom = func() {
		log.Warn("got to close")
	}

	tagW.win.Make()
	tagW.win.StandardClose()
	tagW.win.Draw()

	tagW.box = tagW.win.Box()
	tagW.group = tagW.box.NewGroup("tags")
	tagW.grid = tagW.box.RawGrid()

	tagW.group.NewButton("list all tags", func() {
		me.autotypistWindow.Disable()
		defer me.autotypistWindow.Enable()
		for _, repo := range me.allrepos {
			tagsW := repo.status.TagsW
			if tagsW == nil {
				repo.status.TagWindow()
				tagsW = repo.status.TagsW
				// tagsW.Prune()
				continue
			}
			allTags := tagsW.ListAll()
			for _, t := range allTags {
				log.Info("found tag:", t.TagString(), "from", repo.status.String())
			}
		}
	})

	tagW.group.NewButton("delete all dup tags", func() {
		me.autotypistWindow.Disable()
		defer me.autotypistWindow.Enable()
		for _, repo := range me.allrepos {
			if repo.String() == "go.wit.com/lib/gadgets" {
				// only do log for now
			} else {
				// continue
			}
			tagsW := repo.status.TagsW
			if tagsW == nil {
				repo.status.TagWindow()
				tagsW = repo.status.TagsW
				continue
			}
			tagsW.PruneSmart()
			deleteTags := tagsW.List()
			for _, t := range deleteTags {
				tagW.grid.NewLabel(t.TagString())
				tagW.grid.NewLabel(repo.status.String())
				tagW.grid.NewButton("delete", func() {
					tagsW.Delete(t)
				})
				tagW.grid.NextRow()
				if me.autoDryRun.Checked() {
					log.Info("delete tag --dry-run:", t.TagString(), "from", repo.status.String())
				} else {
					log.Info("Deleting tag:", t.TagString(), "from", repo.status.String())
					go tagsW.Delete(t)
					log.Sleep(1)
				}
			}
		}
	})

	return tagW
}

func (t *gitTag) Hide() {
	t.hidden = true
}