-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefsview.go
179 lines (151 loc) · 4 KB
/
prefsview.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// 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"
"github.com/goki/gi/gi"
"github.com/goki/gi/oswin"
"github.com/goki/ki/ki"
)
// PrefsView opens a view of user preferences
func PrefsView(pf *gi.Preferences) *gi.Window {
winm := "gogi-prefs"
width := 1280
height := 500
win, recyc := gi.RecycleMainWindow(pf, winm, "GoGi Preferences", width, height)
if recyc {
return win
}
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
mfr.Lay = gi.LayoutVert
sv := AddNewStructView(mfr, "sv")
sv.Viewport = vp
sv.SetStruct(pf)
sv.SetStretchMax()
mmen := win.MainMenu
MainMenuView(pf, win, mmen)
inClosePrompt := false
win.OSWin.SetCloseReqFunc(func(w oswin.Window) {
if !pf.Changed {
win.Close()
return
}
if inClosePrompt {
return
}
inClosePrompt = true
gi.ChoiceDialog(vp, gi.DlgOpts{Title: "Save Prefs Before Closing?",
Prompt: "Do you want to save any changes to preferences before closing?"},
[]string{"Save and Close", "Discard and Close", "Cancel"},
win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
switch sig {
case 0:
pf.Save()
fmt.Println("Preferences Saved to prefs.json")
win.Close()
case 1:
pf.Open() // if we don't do this, then it actually remains in edited state
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()
return win
}
// PrefsDetView opens a view of user detailed preferences
func PrefsDetView(pf *gi.PrefsDetailed) *gi.Window {
winm := "gogi-prefs-det"
width := 800
height := 800
win, recyc := gi.RecycleMainWindow(pf, winm, "GoGi Detailed Preferences", width, height)
if recyc {
return win
}
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
mfr.Lay = gi.LayoutVert
sv := AddNewStructView(mfr, "sv")
sv.Viewport = vp
sv.SetStruct(pf)
sv.SetStretchMax()
mmen := win.MainMenu
MainMenuView(pf, win, mmen)
inClosePrompt := false
win.OSWin.SetCloseReqFunc(func(w oswin.Window) {
if !pf.Changed {
win.Close()
return
}
if inClosePrompt {
return
}
inClosePrompt = true
gi.ChoiceDialog(vp, gi.DlgOpts{Title: "Save Prefs Before Closing?",
Prompt: "Do you want to save any changes to detailed preferences before closing?"},
[]string{"Save and Close", "Discard and Close", "Cancel"},
win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
switch sig {
case 0:
pf.Save()
fmt.Println("Preferences Saved to prefs_det.json")
win.Close()
case 1:
pf.Open() // if we don't do this, then it actually remains in edited state
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()
return win
}
// PrefsDbgView opens a view of user debugging preferences
func PrefsDbgView(pf *gi.PrefsDebug) *gi.Window {
winm := "gogi-prefs-dbg"
width := 800
height := 800
win, recyc := gi.RecycleMainWindow(pf, winm, "GoGi Debugging Preferences", width, height)
if recyc {
return win
}
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
mfr.Lay = gi.LayoutVert
sv := AddNewStructView(mfr, "sv")
sv.Viewport = vp
sv.SetStruct(pf)
sv.SetStretchMaxWidth()
sv.SetStretchMax()
// mmen := win.MainMenu
// MainMenuView(pf, win, mmen)
// win.MainMenuUpdated()
if !win.HasGeomPrefs() { // resize to contents
vpsz := vp.PrefSize(win.OSWin.Screen().PixSize)
win.SetSize(vpsz)
}
vp.UpdateEndNoSig(updt)
win.GoStartEventLoop()
return win
}