-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.go
193 lines (176 loc) · 4.72 KB
/
menu.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package main
import (
"fmt"
"net/url"
"os"
"path/filepath"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func (h *hgui) setOffline() {
if h.offlineMode {
return
} else {
if h.Filter.Ready {
h.offlineMode = true
h.offlineTool.SetIcon(theme.VisibilityOffIcon())
h.toolBar.Refresh()
dialog.ShowInformation("Offline Mode", "Offline mode enabled", h.win)
} else {
dialog.ShowInformation("Offline Mode", "No Filter loaded", h.win)
}
}
}
func (h *hgui) switchOffline() {
if h.offlineMode {
h.offlineMode = false
h.offlineTool.SetIcon(theme.VisibilityIcon())
h.toolBar.Refresh()
dialog.ShowInformation("Offline Mode", "Offline mode disabled", h.win)
} else if !h.offlineMode {
if h.Filter.Ready {
h.offlineMode = true
h.offlineTool.SetIcon(theme.VisibilityOffIcon())
h.toolBar.Refresh()
dialog.ShowInformation("Offline Mode", "Offline mode enabled", h.win)
} else {
dialog.ShowInformation("Offline Mode", "No Filter loaded", h.win)
}
}
}
func (h *hgui) loadFilterFromRemote() {
h.Filter = NewHashlookupBloom("it's in your RAM dude.", h)
h.OpenBloomFilter("remote")
}
func (h *hgui) loadFilterFromFile() {
dialog.ShowFileOpen(func(u fyne.URIReadCloser, err error) {
if err != nil {
dialog.ShowError(err, h.win)
return
}
if u == nil {
return
}
h.Filter = NewHashlookupBloom(u.URI().Path(), h)
if err != nil {
dialog.ShowError(err, h.win)
} else {
h.OpenBloomFilter("load")
}
}, h.win)
}
func (h *hgui) showSaveBloomDialog() {
parent := widget.NewButton("Choose directory", nil)
dir := defaultDir()
if dir != nil {
parent.SetText(dir.Name())
}
parent.OnTapped = func() {
dialog.ShowFolderOpen(func(u fyne.ListableURI, err error) {
if err != nil {
dialog.ShowError(err, h.win)
return
}
if u == nil {
return
}
dir = u
parent.SetText(u.Name())
}, h.win)
}
name := widget.NewEntry()
dialog.ShowForm("Save Filter", "Download", "Cancel", []*widget.FormItem{
widget.NewFormItem("Parent directory", parent),
widget.NewFormItem("File name", name),
}, func(ok bool) {
if !ok {
return
}
var err error
h.Filter = NewHashlookupBloom(filepath.Join(dir.Path(), name.Text), h)
if err != nil {
dialog.ShowError(err, h.win)
} else {
h.OpenBloomFilter("download")
}
}, h.win)
}
func (h *hgui) menuActionRunOffline() {
fmt.Println("Menu action run offline hashlookup analysis")
}
func (h *hgui) menuActionRunOnline() {
fmt.Println("Menu action run online hashlookup analysis")
}
func (h *hgui) menuActionSave() {
fmt.Println("Menu action save")
}
func (h *hgui) changeProjectDir() {
dialog.ShowFolderOpen(func(u fyne.ListableURI, err error) {
if err != nil {
dialog.ShowError(err, h.win)
return
}
if u == nil {
return
}
h.setProject(u)
if err != nil {
dialog.ShowError(err, h.win)
} else {
return
}
}, h.win)
}
func (h *hgui) makeMenu() *fyne.MainMenu {
file := fyne.NewMenu("File",
fyne.NewMenuItemSeparator(),
fyne.NewMenuItem("Download Filter", h.showSaveBloomDialog),
fyne.NewMenuItem("Load Filter From File", h.loadFilterFromFile),
fyne.NewMenuItem("Load Filter From Remote", h.loadFilterFromRemote),
fyne.NewMenuItemSeparator(),
fyne.NewMenuItem("Switch Offline mode", h.switchOffline),
fyne.NewMenuItemSeparator(),
fyne.NewMenuItem("Reset Tree Root", h.changeProjectDir),
//fyne.NewMenuItem("Save", h.menuActionSave),
//fyne.NewMenuItem("Run Online", h.menuActionRunOnline),
//fyne.NewMenuItem("Run Offline", h.menuActionRunOffline),
)
helpMenu := fyne.NewMenu("Help",
fyne.NewMenuItem("Github", func() {
u, _ := url.Parse("https://github.com/hashlookup/hashlookup-gui")
_ = (*h.app).OpenURL(u)
}))
return fyne.NewMainMenu(file, helpMenu)
}
func (h *hgui) makeToolbar() *widget.Toolbar {
if h.offlineMode {
h.offlineTool = widget.NewToolbarAction(theme.VisibilityOffIcon(), h.switchOffline)
} else {
h.offlineTool = widget.NewToolbarAction(theme.VisibilityIcon(), h.switchOffline)
}
h.toolBar = widget.NewToolbar(
//widget.NewToolbarAction(theme.FileIcon(), h.showSaveBloomDialog),
//widget.NewToolbarAction(theme.DocumentSaveIcon(), h.menuActionSave),
//widget.NewToolbarAction(theme.MailForwardIcon(), h.menuActionRunOnline),
//widget.NewToolbarAction(theme.MailForwardIcon(), h.menuActionRunOffline),
h.offlineTool,
)
return h.toolBar
}
func defaultDir() fyne.ListableURI {
homeDir, err := os.UserHomeDir()
if err != nil {
fyne.LogError("Failed to get user home directory", err)
return nil
}
defaultDir := storage.NewFileURI(homeDir)
newDir, err := storage.ListerForURI(defaultDir)
if err != nil {
fyne.LogError("Failed to list home directory", err)
return nil
}
return newDir
}