/
value.go
70 lines (61 loc) · 1.94 KB
/
value.go
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
// Copyright (c) 2018, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package histyle
import (
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"cogentcore.org/core/icons"
"cogentcore.org/core/reflectx"
"cogentcore.org/core/views"
)
func init() {
views.AddValue(core.HiStyleName(""), func() views.Value { return &Value{} })
}
// Value represents a [core.HiStyleName] with a button.
type Value struct {
views.ValueBase[*core.Button]
}
func (v *Value) Config() {
v.Widget.SetType(core.ButtonTonal).SetIcon(icons.Brush)
views.ConfigDialogWidget(v, false)
}
func (v *Value) Update() {
txt := reflectx.ToString(v.Value.Interface())
v.Widget.SetText(txt).Update()
}
func (v *Value) ConfigDialog(d *core.Body) (bool, func()) {
d.SetTitle("Select a syntax highlighting style")
si := 0
cur := reflectx.ToString(v.Value.Interface())
views.NewSliceView(d).SetSlice(&StyleNames).SetSelectedValue(cur).BindSelect(&si)
return true, func() {
if si >= 0 {
hs := StyleNames[si]
v.SetValue(hs)
v.Update()
}
}
}
// View opens a view of highlighting styles
func View(st *Styles) {
if core.ActivateExistingMainWindow(st) {
return
}
d := core.NewBody("hi-styles").SetData(st)
d.AddTitle("Highlighting Styles: use ViewStd to see builtin ones -- can add and customize -- save ones from standard and load into custom to modify standards.")
mv := views.NewMapView(d).SetMap(st)
StylesChanged = false
mv.OnChange(func(e events.Event) {
StylesChanged = true
})
d.AddAppBar(func(tb *core.Toolbar) {
oj := views.NewFuncButton(tb, st.OpenJSON).SetText("Open from file").SetIcon(icons.Open)
oj.Args[0].SetTag(".ext", ".histy")
sj := views.NewFuncButton(tb, st.SaveJSON).SetText("Save from file").SetIcon(icons.Save)
sj.Args[0].SetTag(".ext", ".histy")
core.NewSeparator(tb)
mv.ConfigToolbar(tb)
})
d.NewWindow().Run() // note: no context here so not dialog
}