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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
package main
import (
"fmt"
"strconv"
"sync"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
"go.wit.com/gui"
)
type patchesWindow struct {
once sync.Once // only init() the window once
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
summary *patchSummary // summary of current patches
setgrid *gui.Node // the list of each patchset
// setlist map[string]*forgepb.Patchset // a map of the patch names to the protobuf
// setwin map[string]*patchWindow // a map of the patch names to the protobuf
}
func (r *patchesWindow) Hidden() bool {
return r.win.Hidden()
}
func (r *patchesWindow) Toggle() {
if r.Hidden() {
r.Show()
} else {
r.Hide()
}
}
func (r *patchesWindow) Show() {
r.win.Show()
}
func (r *patchesWindow) Hide() {
r.win.Hide()
}
func (r *patchesWindow) Disable() {
r.stack.Disable()
}
func (r *patchesWindow) Enable() {
r.stack.Enable()
}
// you can only have one of these
func (r *patchesWindow) initWindow() {
// sync.Once()
r.win = gadgets.RawBasicWindow("Forge Patchesets")
r.win.Make()
r.stack = r.win.Box().NewBox("bw vbox", false)
// me.reposwin.Draw()
r.win.Custom = func() {
log.Warn("Patchset Window close. setting hidden=true")
// sets the hidden flag to false so Toggle() works
r.win.Hide()
}
r.grid = r.stack.NewGrid("", 0, 0)
/*
r.shelf = r.initGroup()
group1 := r.stack.NewGroup("stuff")
vbox := group1.Box()
vbox.Vertical()
*/
r.summary = r.submitPatchesBox(r.stack)
// update the stats about the repos and patches
r.summary.Update()
g := r.stack.NewGroup("Patchset List")
// add the grid
r.setgrid = g.NewGrid("", 0, 0)
}
type patchSummary struct {
grid *gui.Node
updateB *gui.Node
docsB *gui.Node
gitPushB *gui.Node
gitPullB *gui.Node
checkB *gui.Node
totalOL *gadgets.OneLiner
dirtyOL *gadgets.OneLiner
readonlyOL *gadgets.OneLiner
rw *gadgets.OneLiner
totalPatchesOL *gadgets.OneLiner
// totalUserRepos *gui.Node
// totalDevelRepos *gui.Node
// totalMasterRepos *gui.Node
// totalUserPatches *gui.Node
// totalDevelPatches *gui.Node
// totalMasterPatches *gui.Node
// fileCount *gui.Node
unknownOL *gadgets.BasicEntry
unknownSubmitB *gui.Node
reason *gadgets.BasicEntry
submitB *gui.Node
// allp []*repolist.Patch
}
func (r *patchesWindow) submitPatchesBox(box *gui.Node) *patchSummary {
s := new(patchSummary)
group1 := box.NewGroup("Repo Summary")
s.grid = group1.RawGrid()
s.totalOL = gadgets.NewOneLiner(s.grid, "Total")
s.grid.NextRow()
s.dirtyOL = gadgets.NewOneLiner(s.grid, "dirty")
// _ = s.grid.NewLabel("") // skip a column
// s.totalUserRepos = s.grid.NewLabel("x go repos")
s.grid.NextRow()
s.readonlyOL = gadgets.NewOneLiner(s.grid, "read-only")
// _ = s.grid.NewLabel("") // skip a column
s.grid.NextRow()
s.rw = gadgets.NewOneLiner(s.grid, "r/w")
// _ = s.grid.NewLabel("") // skip a column
s.grid.NextRow()
group1 = box.NewGroup("Patchset Create")
s.grid = group1.RawGrid()
s.grid.NewButton("current patch summary", func() {
s.Update()
pset, err := me.forge.MakeDevelPatchSet("current patches")
if err != nil {
log.Info("patchset creation failed", err)
return
}
if pset == nil {
log.Info("you have no current patches")
return
}
win := makePatchWindow(pset)
win.Show()
})
s.reason = gadgets.NewBasicEntry(s.grid, "Patchset name:")
s.reason.Custom = func() {
if s.reason.String() != "" {
s.submitB.Enable()
} else {
s.submitB.Disable()
}
}
s.submitB = s.grid.NewButton("Submit", func() {
pset, err := me.forge.SubmitDevelPatchSet(s.reason.String())
if err != nil {
log.Info(err)
return
}
// line := "somedate " + s.reason.String() + " Author: me" + pset.GitAuthorEmail
r.addPatchsetNew(pset)
})
s.grid.NewButton("Get Patchset List", func() {
if psets, err := me.forge.GetPatchesets(); err != nil {
log.Info("Get Patchsets failed", err)
return
} else {
log.Info("got psets len", len(psets.Patchsets))
// all := psets.All()
all := psets.SortByName()
for all.Scan() {
pset := all.Next()
r.addPatchsetNew(pset)
}
}
})
s.submitB.Disable()
s.grid.NextRow()
return s
}
func (r *patchesWindow) addPatchsetNew(pset *forgepb.Patchset) {
r.setgrid.NewLabel(pset.Name)
r.setgrid.NewLabel(pset.Comment)
r.setgrid.NewLabel(pset.GitAuthorName)
var win *patchWindow
r.setgrid.NewButton("View", func() {
// has the window already been created?
if win != nil {
// it has been already created. just show it
win.Toggle()
log.Info("TRYING TO TOGGLE WINDOW")
return
}
win = makePatchWindow(pset)
win.Show()
})
r.setgrid.NextRow()
}
// does not run any commands
func (s *patchSummary) Update() {
var total, dirty, readonly, rw int
// var userT int // , develT, masterT int
// var userP, develP, masterP int
// broken after move to forge protobuf
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
total += 1
if repo.IsDirty() {
dirty += 1
}
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
readonly += 1
} else {
rw += 1
}
}
s.totalOL.SetText(strconv.Itoa(total) + " repos")
s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos")
s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos")
s.rw.SetText(fmt.Sprintf("%d repos", rw))
// s.totalUserRepos.SetText(strconv.Itoa(userT) + " repos")
}
|