summaryrefslogtreecommitdiff
path: root/windowBranches.go
blob: 3aba4e86a6c85eaa5cd1064559ad27305050d015 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
}