forked from shw700/oztool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.go
More file actions
297 lines (214 loc) · 6.11 KB
/
Copy pathmenu.go
File metadata and controls
297 lines (214 loc) · 6.11 KB
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
package main
import (
"fmt"
"log"
"os"
"io/ioutil"
"github.com/gotk3/gotk3/gtk"
)
type menuVal struct {
Name string
Description string
Function interface{}
AccelStr string
}
var file_menu = []menuVal {
{ "_New Profile", "Create new Oz profile", menu_New, "<Ctrl>n" },
{ "_Open Profile", "Open oz profile JSON configuration file", menu_Open, "<Ctrl>o" },
{ "_Save As", "Save current oz profile to JSON configuration file", menu_Save, "<Ctrl>s" },
{ "-", "", nil, "" },
{ "E_xit", "Quit oztool", menu_Quit, "<Ctrl>q" },
}
var action_menu = []menuVal {
{ "_Run application", "Run the application in its oz sandbox", nil, "<Shift><Alt>F1" },
}
var sandbox_menu = []menuVal {
{ "Launch _shell", "Launch a shell inside its running oz sandbox", menu_Launch, "<Shift><Alt>S" },
{ "Browse _filesystem", "Browse the local filesystem visible to the sandbox", menu_BrowseFS, "<Shift><Alt>F" },
{ "View _logs", "View log files for running oz sandbox", menu_Logs, "<Shift><Alt>L" },
{ "_Kill", "Kill running sandbox", menu_Kill, "<Shift><Alt>K" },
{ "Relaunch _XPRA", "Relaunch XPRA for running sandbox", menu_RelaunchXPRA, "<Shift><Alt>X" },
}
var allMenus = map[string][]menuVal { "File": file_menu, "Action": action_menu, "Sandbox": sandbox_menu }
var allMenusOrdered = []string{ "File", "Action", "Sandbox" }
func menu_New() {
fmt.Println("NEW!")
Notebook.Destroy()
reset_configs()
empty_whitelist := make([][]configVal, 0)
allTabsA["whitelist"] = &empty_whitelist
empty_blacklist := make([][]configVal, 0)
allTabsA["blacklist"] = &empty_blacklist
empty_environment := make([][]configVal, 0)
allTabsA["environment"] = &empty_environment
empty_forwarders := make([][]configVal, 0)
allTabsA["forwarders"] = &empty_forwarders
notebookPages = make(map[string]*gtk.Box)
Notebook = createNotebook()
profileBox.Add(Notebook)
for t := 0; t < len(allTabsOrdered); t++ {
tname := allTabsOrdered[t]
tbox := get_vbox()
if _, failed := allTabsA[tname]; failed {
scrollbox := get_scrollbox()
scrollbox.SetSizeRequest(600, 500)
tmp := templates[tname]
populate_profile_tabA(tbox, *allTabsA[tname], &tmp, tname, nil, 0, nil, nil)
scrollbox.Add(tbox)
notebookPages[tname].Add(scrollbox)
continue
}
populate_profile_tab(tbox, *allTabs[tname], false)
notebookPages[tname].Add(tbox)
}
profileBox.ShowAll()
}
func menu_Open() {
ppath := pickJSONFile(false)
if ppath != "" {
Notebook.Destroy()
showProfileByPath(ppath)
}
}
func menu_Save() {
jstr := ""
for i := 0; i < len(allTabsOrdered); i++ {
tname := allTabsOrdered[i]
if _, failed := allTabsA[tname]; failed {
fmt.Println("Trying export of unsupported section: ", tname)
jstr += ", \"" + tname + "\": [\n"
if len(*allTabsA[tname]) == 0 {
jstr += "]\n"
continue
}
for j := 0; j < len(*allTabsA[tname]); j++ {
jappend, err := serializeConfigToJSON((*allTabsA[tname])[j], tname, 0, true)
if err != nil {
promptError(err.Error())
return
}
jstr += jappend
if j < len(*allTabsA[tname])-1 {
jstr += ",\n"
}
}
jstr += "]\n"
continue
}
jappend, err := serializeConfigToJSON(*allTabs[tname], tname, 1, false)
if err != nil {
promptError(err.Error())
return
}
jstr += jappend
}
jstr += "}"
fmt.Println(jstr)
ppath := pickJSONFile(true)
if ppath != "" {
err := ioutil.WriteFile(ppath, []byte(jstr+"\n"), 0644)
if err != nil {
promptError(err.Error())
}
}
}
func menu_Kill() {
fmt.Println("KILL!")
if promptChoice("Are you sure you want to kill this process?") {
launchOzCmd("kill", "")
}
}
func menu_RelaunchXPRA() {
fmt.Println("RELAUNCH XPRA")
launchOzCmd("relaunchxpra", "")
}
func menu_Logs() {
fmt.Println("LOGS")
launchOzCmd("logs", "")
}
func menu_BrowseFS() {
fmt.Println("BROWSE FS")
launchOzCmd("shell", "nautilus")
}
func menu_Launch() {
fmt.Println("LAUNCH!")
launchOzCmd("shell", "")
}
func menu_Quit() {
fmt.Println("Quitting on user instruction.")
gtk.MainQuit()
}
func popupContextMenu(button int, time uint32) {
const mname = "Sandbox"
menu, err := gtk.MenuNew()
if err != nil {
log.Fatal("Unable to create context menu:", err)
}
for i := 0; i < len(allMenus[mname]); i++ {
mi, err := gtk.MenuItemNewWithMnemonic(allMenus[mname][i].Name)
if err != nil {
log.Fatal("Unable to create menu item:", err)
}
if allMenus[mname][i].Function != nil {
mi.Connect("activate", allMenus[mname][i].Function)
}
menu.Append(mi)
}
menu.ShowAll()
menu.PopupAtMouseCursor(nil, nil, button, time)
}
func createMenu(box*gtk.Box) {
menuBar, err := gtk.MenuBarNew()
if err != nil {
log.Fatal("Unable to create menu bar:", err)
}
for m := 0; m < len(allMenusOrdered); m++ {
mname := allMenusOrdered[m]
menu, err := gtk.MenuNew()
if err != nil {
log.Fatal("Unable to create menu:", err)
}
mi, err := gtk.MenuItemNewWithMnemonic("_"+mname)
if err != nil {
log.Fatal("Unable to create menu item:", err)
}
mi.SetSubmenu(menu)
var ag *gtk.AccelGroup = nil
for i := 0; i < len(allMenus[mname]); i++ {
if allMenus[mname][i].Name == "-" {
mi2, err := gtk.SeparatorMenuItemNew()
if err != nil {
log.Fatal("Unable to create separator menu item:", err)
}
menu.Append(mi2)
} else {
mi2, err := gtk.MenuItemNewWithMnemonic(allMenus[mname][i].Name)
if err != nil {
log.Fatal("Unable to create menu item:", err)
}
if allMenus[mname][i].Function != nil {
mi2.Connect("activate", allMenus[mname][i].Function)
}
menu.Append(mi2)
}
if allMenus[mname][i].AccelStr != "" {
if allMenus[mname][i].Function == nil {
fmt.Fprintf(os.Stderr, "Skipping over empty menu item creation: %v\n", allMenus[mname][i].Name)
continue
}
key, mods := gtk.AcceleratorParse(allMenus[mname][i].AccelStr)
if ag == nil {
ag, err = gtk.AccelGroupNew()
if err != nil {
log.Fatal("Unable to create accelerator group:", err)
}
mainWin.AddAccelGroup(ag)
}
ag.Connect(key, mods, gtk.ACCEL_VISIBLE, allMenus[mname][i].Function)
menu.SetAccelGroup(ag)
}
}
menuBar.Append(mi)
}
box.PackStart(menuBar, false, false, 0)
}