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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
|
// SPDX-License-Identifier: GPL-3.0-or-later
package ui
import (
"fmt"
"strings"
"github.com/diamondburned/gotk4/pkg/glib/v2"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"krino/gui/internal/model"
"krino/internal/config"
"krino/internal/sexp"
)
// condKinds are the tests a condition row offers, plus the three operators
// that hold other conditions. A row's entry holds that form's arguments
// exactly as they are written, so no test is out of reach of the form
// editor and none is silently rewritten (see docs/gui-design.md §5.1 and
// the deviation noted in plan 17).
var condKinds = []string{"type", "name", "path", "content", "size", "age",
"duplicate", "matched", "and", "or", "not"}
// condHints is the example shown beside a row, by kind.
var condHints = map[string]string{
"type": `pdf doc (extensions or a group)`,
"name": `"^faktura" "^fv" (regexes, any may match)`,
"path": `"work/" (regex against the path under the root)`,
"content": `"invoice" "faktura" (keywords, any may match)`,
"size": `> 10M`,
"age": `> 90d`,
"duplicate": `"~/docs" (or empty: the directory's own tree)`,
"matched": `(no arguments)`,
"and": `(type pdf) (content "invoice")`,
"or": `(type doc) (type docx)`,
"not": `(duplicate)`,
}
// actionKinds are the actions a rule can carry, in the order the form
// offers them.
var actionKinds = []string{"copy", "move", "rename", "delete", "delete permanent"}
// formsView is the Forms half of the Rules tab: the directory's excludes
// and rules on the left, the selected one as a form in the middle.
type formsView struct {
w *Window
owner *rulesView
root *gtk.Box
list *gtk.ListBox
add, del, up, down *gtk.Button
place *gtk.Box
note *gtk.Label
forms []model.Form
sel int
editor *formEditor
pending glib.SourceHandle
quiet bool
commentsAcknowledged map[string]bool
}
func newFormsView(w *Window, owner *rulesView) *formsView {
f := &formsView{w: w, owner: owner, sel: -1, commentsAcknowledged: map[string]bool{}}
f.root = gtk.NewBox(gtk.OrientationHorizontal, 0)
f.list = gtk.NewListBox()
f.list.SetSelectionMode(gtk.SelectionSingle)
listScroll := gtk.NewScrolledWindow()
listScroll.SetChild(f.list)
listScroll.SetVExpand(true)
f.add = gtk.NewButtonWithLabel("Add rule")
f.del = gtk.NewButtonWithLabel("Delete")
f.up = gtk.NewButtonWithLabel("Up")
f.down = gtk.NewButtonWithLabel("Down")
buttons := gtk.NewBox(gtk.OrientationHorizontal, 4)
buttons.SetMarginStart(6)
buttons.SetMarginEnd(6)
buttons.SetMarginTop(4)
buttons.SetMarginBottom(4)
for _, b := range []*gtk.Button{f.add, f.del, f.up, f.down} {
buttons.Append(b)
}
left := gtk.NewBox(gtk.OrientationVertical, 0)
left.Append(listScroll)
left.Append(gtk.NewSeparator(gtk.OrientationHorizontal))
left.Append(buttons)
left.SetSizeRequest(260, -1)
f.note = gtk.NewLabel("")
f.note.SetXAlign(0)
f.note.SetWrap(true)
f.note.SetMarginStart(8)
f.note.SetMarginEnd(8)
f.note.SetMarginTop(6)
f.place = gtk.NewBox(gtk.OrientationVertical, 0)
f.place.SetVExpand(true)
placeScroll := gtk.NewScrolledWindow()
placeScroll.SetChild(f.place)
placeScroll.SetVExpand(true)
placeScroll.SetHExpand(true)
right := gtk.NewBox(gtk.OrientationVertical, 0)
right.Append(f.note)
right.Append(placeScroll)
f.root.Append(left)
f.root.Append(gtk.NewSeparator(gtk.OrientationVertical))
f.root.Append(right)
f.list.ConnectRowSelected(func(row *gtk.ListBoxRow) {
if row != nil && !f.quiet {
f.show(row.Index())
}
})
f.add.ConnectClicked(f.onAdd)
f.del.ConnectClicked(f.onDelete)
f.up.ConnectClicked(func() { f.move(-1) })
f.down.ConnectClicked(func() { f.move(1) })
return f
}
// reload re-reads the text in the editor and rebuilds the list. Text that
// does not parse has no forms: the caller keeps the Text tab (GUI design
// §5.2).
func (f *formsView) reload() error {
forms, err := f.owner.formsOf()
if err != nil {
return err
}
f.forms = forms
keep := f.sel
f.quiet = true
clearList(f.list)
for _, form := range forms {
row := gtk.NewListBoxRow()
label := gtk.NewLabel(escape(formLabel(form)))
label.SetXAlign(0)
label.SetMarginStart(6)
label.SetMarginEnd(6)
label.SetMarginTop(2)
label.SetMarginBottom(2)
label.SetEllipsize(3) // end
label.SetMaxWidthChars(30)
label.SetTooltipText(escape(form.Label))
row.SetChild(label)
f.list.Append(row)
}
f.quiet = false
if keep >= 0 && keep < len(forms) {
f.list.SelectRow(f.list.RowAtIndex(keep))
f.show(keep)
} else {
f.sel = -1
f.clearEditor("Select a rule to edit it, or Add rule.")
}
return nil
}
// formLabel is one line of the list: what the form is, and what it does.
func formLabel(f model.Form) string {
if f.Kind == model.ExcludeForm {
return "exclude: " + f.Label
}
var what []string
for _, a := range f.Rule.Actions {
what = append(what, a.Kind.String())
}
if len(what) == 0 {
return f.Label
}
return f.Label + " (" + strings.Join(what, ", ") + ")"
}
// show builds the editor for form i.
func (f *formsView) show(i int) {
if i < 0 || i >= len(f.forms) {
return
}
f.sel = i
form := f.forms[i]
f.note.SetText("")
if has, err := f.owner.rules.FormHasComments(i); err == nil && has {
f.note.SetText("This form has comments inside it. The form editor writes it back from what krino parsed, so those comments would be dropped - the Text tab keeps them.")
}
f.editor = newFormEditor(form, f.armApply)
if child := f.place.FirstChild(); child != nil {
f.place.Remove(child)
}
f.place.Append(f.editor.root)
}
// clearEditor empties the middle pane.
func (f *formsView) clearEditor(text string) {
f.editor = nil
if child := f.place.FirstChild(); child != nil {
f.place.Remove(child)
}
f.note.SetText(text)
}
// armApply writes the form back after a pause, so typing in a field does
// not rewrite the file on every keystroke.
func (f *formsView) armApply() {
if f.pending != 0 {
glib.SourceRemove(f.pending)
}
f.pending = glib.TimeoutAdd(checkDelay, func() bool {
f.pending = 0
f.apply()
return false
})
}
// apply replaces the selected form's text with what the editor holds.
func (f *formsView) apply() {
if f.editor == nil || f.sel < 0 {
return
}
text, err := f.editor.text()
if err != nil {
f.owner.setCheck("form: " + err.Error())
return
}
if !f.confirmComments() {
return
}
if err := f.owner.rules.ReplaceForm(f.sel, text); err != nil {
f.owner.setCheck("form: " + err.Error())
return
}
f.owner.textChangedByForm()
f.refreshLabels()
}
// confirmComments asks once per form before an edit drops the comments
// inside it (GUI design §5.1).
func (f *formsView) confirmComments() bool {
has, err := f.owner.rules.FormHasComments(f.sel)
if err != nil || !has {
return true
}
key := fmt.Sprintf("%d:%s", f.sel, f.forms[f.sel].Label)
if f.commentsAcknowledged[key] {
return true
}
d := gtk.NewMessageDialog(&f.w.win.Window, gtk.DialogModal|gtk.DialogDestroyWithParent,
gtk.MessageWarning, gtk.ButtonsNone)
d.SetObjectProperty("text", "This form has comments inside it")
d.SetObjectProperty("secondary-text",
"Editing it here writes it back from what krino parsed, which drops those comments. The Text tab keeps them.")
d.AddButton("Go to the Text tab", int(gtk.ResponseCancel))
d.AddButton("Edit here anyway", int(gtk.ResponseAccept))
d.ConnectResponse(func(response int) {
d.Destroy()
if response == int(gtk.ResponseAccept) {
f.commentsAcknowledged[key] = true
f.apply()
return
}
f.owner.showText()
})
d.Show()
return false
}
// refreshLabels re-reads the forms so the list shows what the edit did,
// keeping the selection.
func (f *formsView) refreshLabels() {
forms, err := f.owner.formsOf()
if err != nil || len(forms) != len(f.forms) {
return
}
f.forms = forms
for i, form := range forms {
if row := f.list.RowAtIndex(i); row != nil {
if label, ok := row.Child().(*gtk.Label); ok {
label.SetText(escape(formLabel(form)))
}
}
}
}
// onAdd puts a new rule after the selected one and opens it.
func (f *formsView) onAdd() {
name := "new rule"
for i := 2; f.nameTaken(name); i++ {
name = fmt.Sprintf("new rule %d", i)
}
i, err := f.owner.rules.AddRuleAfter(f.sel, name)
if err != nil {
f.owner.setCheck("add: " + err.Error())
return
}
f.owner.textChangedByForm()
f.sel = i
if err := f.reload(); err != nil {
f.owner.setCheck("add: " + err.Error())
}
}
// nameTaken reports whether a rule of that name is already in the file.
func (f *formsView) nameTaken(name string) bool {
for _, form := range f.forms {
if form.Kind == model.RuleForm && form.Label == name {
return true
}
}
return false
}
// onDelete removes the selected form, after asking.
func (f *formsView) onDelete() {
if f.sel < 0 || f.sel >= len(f.forms) {
return
}
form := f.forms[f.sel]
d := gtk.NewMessageDialog(&f.w.win.Window, gtk.DialogModal|gtk.DialogDestroyWithParent,
gtk.MessageQuestion, gtk.ButtonsNone)
d.SetObjectProperty("text", "Delete "+escape(formLabel(form))+"?")
d.SetObjectProperty("secondary-text",
"It goes from the text in the editor, with the comment lines directly above it. Nothing is written until you press Save.")
d.AddButton("Cancel", int(gtk.ResponseCancel))
del := d.AddButton("Delete", int(gtk.ResponseAccept))
if b, ok := del.(*gtk.Button); ok {
b.AddCSSClass("destructive-action")
}
d.ConnectResponse(func(response int) {
d.Destroy()
if response != int(gtk.ResponseAccept) {
return
}
if err := f.owner.rules.DeleteForm(f.sel); err != nil {
f.owner.setCheck("delete: " + err.Error())
return
}
f.owner.textChangedByForm()
if f.sel >= len(f.forms)-1 {
f.sel = len(f.forms) - 2
}
if err := f.reload(); err != nil {
f.owner.setCheck("delete: " + err.Error())
}
})
d.Show()
}
// move shifts the selected form one place up or down, with its comments.
func (f *formsView) move(delta int) {
if f.sel < 0 {
return
}
to := f.sel + delta
if to < 0 || to >= len(f.forms) {
return
}
if err := f.owner.rules.MoveForm(f.sel, delta); err != nil {
f.owner.setCheck("move: " + err.Error())
return
}
f.owner.textChangedByForm()
f.sel = to
if err := f.reload(); err != nil {
f.owner.setCheck("move: " + err.Error())
}
}
// formEditor is the widgets of one form, and can write it back.
type formEditor struct {
kind model.FormKind
root *gtk.Box
name *gtk.Entry
conds *gtk.Box
rows []*condRow
acts *gtk.Box
arows []*actionRow
stop *gtk.CheckButton
cse *gtk.DropDown
fold *gtk.DropDown
onConf *gtk.DropDown
changed func()
}
func newFormEditor(form model.Form, changed func()) *formEditor {
fe := &formEditor{kind: form.Kind, changed: changed}
fe.root = gtk.NewBox(gtk.OrientationVertical, 6)
fe.root.SetMarginStart(8)
fe.root.SetMarginEnd(8)
fe.root.SetMarginTop(6)
fe.root.SetMarginBottom(6)
if form.Kind == model.RuleForm {
fe.name = gtk.NewEntry()
fe.name.SetText(form.Rule.Name)
fe.name.SetHExpand(true)
fe.name.ConnectChanged(func() { changed() })
fe.root.Append(field("Name", fe.name))
}
fe.conds = gtk.NewBox(gtk.OrientationVertical, 4)
fe.root.Append(heading("Conditions - all of these must hold"))
fe.root.Append(fe.conds)
addCond := gtk.NewButtonWithLabel("+ test")
addCond.ConnectClicked(func() {
fe.addCond(nil)
changed()
})
fe.root.Append(leftAligned(addCond))
when := form.Rule.When
if form.Kind == model.ExcludeForm {
when = form.Exclude.When
} else if !form.Rule.HasWhen {
when = nil
}
for _, c := range when {
fe.addCond(c)
}
if form.Kind == model.RuleForm {
fe.acts = gtk.NewBox(gtk.OrientationVertical, 4)
fe.root.Append(heading("Actions - in order"))
fe.root.Append(fe.acts)
addAct := gtk.NewButtonWithLabel("+ action")
addAct.ConnectClicked(func() {
fe.addAction(config.Action{Kind: config.Move})
changed()
})
fe.root.Append(leftAligned(addAct))
for _, a := range form.Rule.Actions {
fe.addAction(a)
}
fe.stop = gtk.NewCheckButtonWithLabel("(stop) - a file this rule matches takes no later rule")
fe.stop.SetActive(form.Rule.Stop)
fe.stop.ConnectToggled(func() { changed() })
fe.root.Append(fe.stop)
fe.root.Append(heading("Settings for this rule"))
fe.cse = dropDown([]string{"default", "ignore", "strict"}, caseIndex(form.Rule.Settings), changed)
fe.fold = dropDown([]string{"default", "yes", "no"}, foldIndex(form.Rule.Settings), changed)
fe.onConf = dropDown([]string{"default", "suffix", "skip", "overwrite"}, conflictIndex(form.Rule.Settings), changed)
fe.root.Append(field("case", fe.cse))
fe.root.Append(field("fold", fe.fold))
fe.root.Append(field("on-conflict", fe.onConf))
}
return fe
}
// text is the form as the printer writes it, from what the widgets hold.
func (fe *formEditor) text() (string, error) {
var when []*sexp.Node
for _, row := range fe.rows {
if row.gone {
continue
}
text := row.text()
nodes, err := sexp.Parse("form", []byte(text))
if err != nil {
return "", fmt.Errorf("%s: %v", text, err)
}
if len(nodes) != 1 {
return "", fmt.Errorf("%s is not one condition", text)
}
when = append(when, nodes[0])
}
if fe.kind == model.ExcludeForm {
if len(when) == 0 {
return "", fmt.Errorf("an exclude needs a condition")
}
return config.PrintExclude(&config.Exclude{When: when}), nil
}
rule := &config.Rule{
Name: fe.name.Text(),
HasWhen: len(when) > 0,
When: when,
Stop: fe.stop.Active(),
}
for _, row := range fe.arows {
if row.gone {
continue
}
rule.Actions = append(rule.Actions, row.action())
}
rule.Settings = settingsFrom(fe.cse, fe.fold, fe.onConf)
return config.PrintRule(rule), nil
}
// addCond adds a condition row, filled in from n when there is one.
func (fe *formEditor) addCond(n *sexp.Node) {
row := newCondRow(n, fe.changed)
fe.rows = append(fe.rows, row)
fe.conds.Append(row.root)
}
// addAction adds an action row.
func (fe *formEditor) addAction(a config.Action) {
row := newActionRow(a, fe.changed)
fe.arows = append(fe.arows, row)
fe.acts.Append(row.root)
}
// condRow is one condition: its kind, and its arguments as written.
type condRow struct {
root *gtk.Box
kind *gtk.DropDown
args *gtk.Entry
gone bool
}
func newCondRow(n *sexp.Node, changed func()) *condRow {
c := &condRow{}
c.root = gtk.NewBox(gtk.OrientationHorizontal, 6)
c.kind = gtk.NewDropDownFromStrings(condKinds)
c.args = gtk.NewEntry()
c.args.SetHExpand(true)
if n != nil {
head, args := splitNode(n)
if i := indexOf(condKinds, head); i >= 0 {
c.kind.SetSelected(uint(i))
}
c.args.SetText(args)
}
c.showHint()
remove := gtk.NewButtonWithLabel("-")
remove.ConnectClicked(func() {
c.gone = true
c.root.SetVisible(false)
changed()
})
c.kind.Connect("notify::selected", func() {
c.showHint()
changed()
})
c.args.ConnectChanged(func() { changed() })
c.root.Append(c.kind)
c.root.Append(c.args)
c.root.Append(remove)
return c
}
// text is the condition as it will be written.
func (c *condRow) text() string {
kind := condKinds[c.kind.Selected()]
args := strings.TrimSpace(c.args.Text())
if args == "" {
return "(" + kind + ")"
}
return "(" + kind + " " + args + ")"
}
// showHint puts the example for the chosen kind in the entry, where it
// shows while the row is empty and as its tooltip once it is not.
func (c *condRow) showHint() {
hint := condHints[condKinds[c.kind.Selected()]]
c.args.SetPlaceholderText(hint)
c.args.SetTooltipText(hint)
}
// actionRow is one action: what it does, and its argument.
type actionRow struct {
root *gtk.Box
kind *gtk.DropDown
arg *gtk.Entry
gone bool
}
func newActionRow(a config.Action, changed func()) *actionRow {
r := &actionRow{}
r.root = gtk.NewBox(gtk.OrientationHorizontal, 6)
r.kind = gtk.NewDropDownFromStrings(actionKinds)
r.kind.SetSelected(uint(actionIndex(a.Kind)))
r.arg = gtk.NewEntry()
r.arg.SetText(a.Arg)
r.arg.SetHExpand(true)
r.arg.SetPlaceholderText("Invoices/{mtime:%Y} - {name} {ext} {1} {mtime:FMT} {now:FMT}")
r.setArgSensitive()
remove := gtk.NewButtonWithLabel("-")
remove.ConnectClicked(func() {
r.gone = true
r.root.SetVisible(false)
changed()
})
r.kind.Connect("notify::selected", func() {
r.setArgSensitive()
changed()
})
r.arg.ConnectChanged(func() { changed() })
r.root.Append(r.kind)
r.root.Append(r.arg)
r.root.Append(remove)
return r
}
// setArgSensitive turns the argument off for the two deletes, which take
// none.
func (r *actionRow) setArgSensitive() {
kind := actionKinds[r.kind.Selected()]
r.arg.SetSensitive(kind != "delete" && kind != "delete permanent")
}
// action is the action the row holds.
func (r *actionRow) action() config.Action {
switch actionKinds[r.kind.Selected()] {
case "copy":
return config.Action{Kind: config.Copy, Arg: r.arg.Text()}
case "rename":
return config.Action{Kind: config.Rename, Arg: r.arg.Text()}
case "delete":
return config.Action{Kind: config.Delete}
case "delete permanent":
return config.Action{Kind: config.DeletePermanent}
}
return config.Action{Kind: config.Move, Arg: r.arg.Text()}
}
// settingsFrom reads the three rule settings; "default" leaves one out.
func settingsFrom(cse, fold, onConf *gtk.DropDown) config.Settings {
var s config.Settings
switch cse.Selected() {
case 1:
m := config.CaseIgnore
s.Case = &m
case 2:
m := config.CaseStrict
s.Case = &m
}
switch fold.Selected() {
case 1:
yes := true
s.Fold = &yes
case 2:
no := false
s.Fold = &no
}
switch onConf.Selected() {
case 1:
c := config.ConflictSuffix
s.OnConflict = &c
case 2:
c := config.ConflictSkip
s.OnConflict = &c
case 3:
c := config.ConflictOverwrite
s.OnConflict = &c
}
return s
}
func caseIndex(s config.Settings) int {
if s.Case == nil {
return 0
}
if *s.Case == config.CaseStrict {
return 2
}
return 1
}
func foldIndex(s config.Settings) int {
if s.Fold == nil {
return 0
}
if *s.Fold {
return 1
}
return 2
}
func conflictIndex(s config.Settings) int {
if s.OnConflict == nil {
return 0
}
switch *s.OnConflict {
case config.ConflictSkip:
return 2
case config.ConflictOverwrite:
return 3
}
return 1
}
func actionIndex(k config.ActionKind) int {
switch k {
case config.Copy:
return 0
case config.Rename:
return 2
case config.Delete:
return 3
case config.DeletePermanent:
return 4
}
return 1
}
// splitNode is a condition's head and the rest of it as written, which is
// what a row's entry holds.
func splitNode(n *sexp.Node) (head, args string) {
if n.Kind != sexp.List || len(n.Children) == 0 {
return "", n.String()
}
parts := make([]string, 0, len(n.Children)-1)
for _, c := range n.Children[1:] {
parts = append(parts, c.String())
}
return n.Head(), strings.Join(parts, " ")
}
func indexOf(ss []string, s string) int {
for i, v := range ss {
if v == s {
return i
}
}
return -1
}
// field is a labelled row of the form.
func field(label string, child gtk.Widgetter) *gtk.Box {
box := gtk.NewBox(gtk.OrientationHorizontal, 6)
l := gtk.NewLabel(label)
l.SetXAlign(0)
l.SetSizeRequest(90, -1)
box.Append(l)
box.Append(child)
return box
}
// heading is a section title inside the form.
func heading(text string) *gtk.Label {
l := gtk.NewLabel(text)
l.SetXAlign(0)
l.SetMarginTop(6)
l.AddCSSClass("heading")
return l
}
// leftAligned keeps a button from stretching across the form.
func leftAligned(w gtk.Widgetter) *gtk.Box {
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
box.Append(w)
return box
}
// dropDown is a combo with its starting choice and change handler.
func dropDown(items []string, selected int, changed func()) *gtk.DropDown {
d := gtk.NewDropDownFromStrings(items)
d.SetSelected(uint(selected))
d.Connect("notify::selected", func() { changed() })
return d
}
|