-
Notifications
You must be signed in to change notification settings - Fork 0
/
histyleview.go
161 lines (138 loc) · 4.36 KB
/
histyleview.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
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
// Copyright (c) 2018, The GoKi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package giv
import (
"fmt"
"reflect"
"github.com/goki/gi/gi"
"github.com/goki/gi/gist"
"github.com/goki/gi/histyle"
"github.com/goki/gi/oswin"
"github.com/goki/gi/units"
"github.com/goki/ki/ki"
"github.com/goki/ki/kit"
)
////////////////////////////////////////////////////////////////////////////////////////
// HiStyleValueView
// HiStyleValueView presents an action for displaying a mat32.Y and selecting
// from styles
type HiStyleValueView struct {
ValueViewBase
}
var KiT_HiStyleValueView = kit.Types.AddType(&HiStyleValueView{}, nil)
func (vv *HiStyleValueView) WidgetType() reflect.Type {
vv.WidgetTyp = gi.KiT_Action
return vv.WidgetTyp
}
func (vv *HiStyleValueView) UpdateWidget() {
if vv.Widget == nil {
return
}
ac := vv.Widget.(*gi.Action)
txt := kit.ToString(vv.Value.Interface())
ac.SetText(txt)
}
func (vv *HiStyleValueView) ConfigWidget(widg gi.Node2D) {
vv.Widget = widg
vv.StdConfigWidget(widg)
ac := vv.Widget.(*gi.Action)
ac.SetProp("border-radius", units.NewPx(4))
ac.ActionSig.ConnectOnly(vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
vvv, _ := recv.Embed(KiT_HiStyleValueView).(*HiStyleValueView)
ac := vvv.Widget.(*gi.Action)
vvv.Activate(ac.ViewportSafe(), nil, nil)
})
vv.UpdateWidget()
}
func (vv *HiStyleValueView) HasAction() bool {
return true
}
func (vv *HiStyleValueView) Activate(vp *gi.Viewport2D, dlgRecv ki.Ki, dlgFunc ki.RecvFunc) {
if vv.IsInactive() {
return
}
cur := kit.ToString(vv.Value.Interface())
desc, _ := vv.Tag("desc")
SliceViewSelectDialog(vp, &histyle.StyleNames, cur, DlgOpts{Title: "Select a HiStyle Highlighting Style", Prompt: desc}, nil,
vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if sig == int64(gi.DialogAccepted) {
ddlg, _ := send.(*gi.Dialog)
si := SliceViewSelectDialogValue(ddlg)
if si >= 0 {
hs := histyle.StyleNames[si]
vv.SetValue(hs)
vv.UpdateWidget()
}
}
if dlgRecv != nil && dlgFunc != nil {
dlgFunc(dlgRecv, send, sig, data)
}
})
}
//////////////////////////////////////////////////////////////////////////////////////
// HiStylesView
// HiStylesView opens a view of highlighting styles
func HiStylesView(st *histyle.Styles) {
winm := "hi-styles"
width := 1280
height := 800
win, recyc := gi.RecycleMainWindow(st, winm, "Syntax Hilighting Styles", width, height)
if recyc {
return
}
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
mfr.Lay = gi.LayoutVert
title := mfr.AddNewChild(gi.KiT_Label, "title").(*gi.Label)
title.SetText("Hilighting Styles: use ViewStd to see builtin ones -- can add and customize -- save ones from standard and load into custom to modify standards.")
title.SetProp("width", units.NewCh(30)) // need for wrap
title.SetStretchMaxWidth()
title.SetProp("white-space", gist.WhiteSpaceNormal) // wrap
tv := mfr.AddNewChild(KiT_MapView, "tv").(*MapView)
tv.Viewport = vp
tv.SetMap(st)
tv.SetStretchMax()
histyle.StylesChanged = false
tv.ViewSig.Connect(mfr.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
histyle.StylesChanged = true
})
mmen := win.MainMenu
MainMenuView(st, win, mmen)
inClosePrompt := false
win.OSWin.SetCloseReqFunc(func(w oswin.Window) {
if !histyle.StylesChanged || st != &histyle.CustomStyles { // only for main avail map..
win.Close()
return
}
if inClosePrompt {
return
}
inClosePrompt = true
gi.ChoiceDialog(vp, gi.DlgOpts{Title: "Save Styles Before Closing?",
Prompt: "Do you want to save any changes to std preferences styles file before closing, or Cancel the close and do a Save to a different file?"},
[]string{"Save and Close", "Discard and Close", "Cancel"},
win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
switch sig {
case 0:
st.SavePrefs()
fmt.Printf("Preferences Saved to %v\n", histyle.PrefsStylesFileName)
win.Close()
case 1:
st.OpenPrefs() // revert
win.Close()
case 2:
inClosePrompt = false
// default is to do nothing, i.e., cancel
}
})
})
win.MainMenuUpdated()
if !win.HasGeomPrefs() { // resize to contents
vpsz := vp.PrefSize(win.OSWin.Screen().PixSize)
win.SetSize(vpsz)
}
vp.UpdateEndNoSig(updt)
win.GoStartEventLoop()
}