-
Notifications
You must be signed in to change notification settings - Fork 5
/
m_dialogs.go
207 lines (189 loc) · 5.66 KB
/
m_dialogs.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package main
import (
"errors"
"fmt"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
// show info about app
func (a *App) aboutDialog() {
a.disableShortcuts()
var logo *canvas.Image
if a.state.Theme == "dark" {
logo = canvas.NewImageFromResource(appIconDark)
} else {
logo = canvas.NewImageFromResource(appIconLight)
}
logo.FillMode = canvas.ImageFillOriginal
logoRow := container.NewBorder(nil, nil, logo, nil)
infoRow := widget.NewRichTextFromMarkdown(`
## Pixyne - photo picker
---
Use [Pixyne](http://vinser.github.io/pixyne) to quickly review your photo folder and safely delete bad and similar shots.
You may also fix EXIF the shooting dates, crop and ajust photos.
---`)
var buildVersion, buildFor, buildTime, goVersion, versionLine, buildLine string
if buildVersion = a.Metadata().Version; buildVersion == "" {
buildVersion = "selfcrafted"
}
versionLine = "Version: " + buildVersion
if buildFor = a.Metadata().Custom["BuildForOS"]; buildFor != "" {
buildLine = fmt.Sprintf("Build for: %s ", buildFor)
}
if buildTime = a.Metadata().Custom["BuildTime"]; buildTime != "" {
buildLine = buildLine + fmt.Sprintf(" | Build time: %s ", buildTime)
}
if goVersion = a.Metadata().Custom["GoVersion"]; goVersion != "" {
buildLine = buildLine + fmt.Sprintf(" | Go version: %s ", goVersion)
}
tecRow := widget.NewRichTextFromMarkdown(
`Licence: MIT | [GitHub](https://github.com/vinser/pixyne) repo | ` + versionLine + `
` + buildLine)
noteRow := widget.NewRichTextFromMarkdown(`
---
*Created using* [Fyne](https://fyne.io) *GUI library*.
*App icon designed by* [Icon8](https://icon8.com).`)
aboutDialog := dialog.NewCustom("About", "Ok", container.NewVBox(logoRow, infoRow, tecRow, noteRow), a.topWindow)
aboutDialog.SetOnClosed(func() {
a.enableShortcuts()
})
aboutDialog.Show()
}
// show info about app hotkeys
func (a *App) hotkeysDialog() {
a.disableShortcuts()
ctrlForm := widget.NewForm()
for i := range a.ControlShortCuts {
item := widget.FormItem{Text: a.ControlShortCuts[i].Name, Widget: widget.NewLabel("Ctrl + " + string(a.ControlShortCuts[i].KeyName))}
ctrlForm.AppendItem(&item)
}
altForm := widget.NewForm()
for i := range a.AltShortCuts {
item := widget.FormItem{Text: a.AltShortCuts[i].Name, Widget: widget.NewLabel("Alt + " + string(a.AltShortCuts[i].KeyName))}
altForm.AppendItem(&item)
}
keysDialog := dialog.NewCustom("Hotkeys", "Ok", container.NewGridWithColumns(2, ctrlForm, altForm), a.topWindow)
keysDialog.SetOnClosed(func() {
a.enableShortcuts()
})
keysDialog.Show()
}
// open photo folder dialog
func (a *App) openFolderDialog() {
a.disableShortcuts()
d := dialog.NewFolderOpen(func(list fyne.ListableURI, err error) {
a.statusInfo.ShowProgress()
defer a.statusInfo.HideProgress()
a.statusInfo.text.Set("")
if err != nil {
dialog.ShowError(err, a.topWindow)
return
}
if list == nil {
return
}
if list.Scheme() != "file" {
dialog.ShowError(errors.New("only local files are supported"), a.topWindow)
return
}
a.defaultState(false)
rootURI = list
a.topWindowTitle.Set(rootURI.Path())
a.newPhotoList()
a.newLayout()
a.enableShortcuts()
}, a.topWindow)
d.SetLocation(rootURI)
d.Resize(fyne.NewSize(672, 378))
d.Show()
}
// Save choosed photos:
// 1. move dropped photo to droppped folder
// 2. update exif dates with file modify date or input date
func (a *App) savePhotoListDialog() {
a.disableShortcuts()
renameFiles := false
datedFileFormat := time.Now().Format(FileNameDateFormat)
content := container.NewVBox(
widget.NewLabel("Ready to save changes?"),
widget.NewCheck("Rename files to date taken format "+datedFileFormat, func(b bool) { renameFiles = b }),
)
d := dialog.NewCustomConfirm(
"Save changes",
"Proceed",
"Cancel",
content,
func(b bool) {
if b {
a.statusInfo.ShowProgress()
defer a.statusInfo.HideProgress()
a.statusInfo.text.Set("")
a.SavePhotoList(renameFiles)
a.defaultState(false)
a.topWindowTitle.Set(a.state.Folder)
a.newPhotoList()
a.newLayout()
}
a.enableShortcuts()
},
a.topWindow)
d.Show()
}
func (a *App) settingsDialog() {
a.disableShortcuts()
s := NewSettings()
settingsForm := widget.NewForm(
widget.NewFormItem("", s.scalePreviewsRow(a.topWindow.Canvas().Scale())),
widget.NewFormItem("Scale", s.scalesRow()),
widget.NewFormItem("Main Color", s.colorsRow()),
widget.NewFormItem("Theme", s.themesRow()),
widget.NewFormItem("Mode", s.modeRow(a)),
widget.NewFormItem("Date Format", s.datesRow(a)),
widget.NewFormItem("Hotkeys", s.hotkeysRow()),
)
d := dialog.NewCustom("Settings", "Ok", settingsForm, a.topWindow)
d.SetOnClosed(func() {
a.statusInfo.ShowProgress()
defer a.statusInfo.HideProgress()
if len(list) > 0 {
if !a.frameView.Hidden {
a.showFrameToolbar()
}
a.topWindow.Content().Refresh()
frame.At(a.state.FramePos)
frame.ItemEndingAt(a.state.ItemPos)
}
a.enableShortcuts()
})
resettButton := widget.NewButton("Reset all", func() { a.approveResetAllDialog(d) })
resettButton.Importance = widget.DangerImportance
settingsForm.Append("", container.NewBorder(nil, nil, nil, resettButton))
d.Show()
}
func (a *App) approveResetAllDialog(parent *dialog.CustomDialog) {
d := dialog.NewCustomConfirm(
"Reset all",
"Proceed",
"Cancel",
container.NewVBox(
widget.NewLabel("WARNING!"),
widget.NewLabel("All settings will be reset to default values."),
),
func(b bool) {
if b {
a.statusInfo.text.Set("")
a.defaultState(true)
a.topWindowTitle.Set(a.state.Folder)
a.newPhotoList()
a.newLayout()
parent.Hide()
parent = nil
}
},
a.topWindow)
d.Show()
}