-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
settings.go
184 lines (149 loc) 路 3.62 KB
/
settings.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
package settings
// DialogIcon is the enumeration for dialog icons.
type DialogIcon uint
// The stock dialog icons.
const (
UndefinedIcon DialogIcon = iota
ErrorIcon
WarningIcon
InfoIcon
QuestionIcon
)
// General Dialog settings are default settings for all dialogs.
type General struct {
Title string
Width uint
Height uint
WindowIcon DialogIcon
}
// GeneralButton are default settings for the standard buttons on certain dialogs.
type GeneralButton struct {
OkLabel string
CancelLabel string
DefaultCancel bool
ExtraButtons []string // On macOS only one additional button is allowed.
}
// GeneralText are default text settings for certain dialogs.
type GeneralText struct {
Text string
NoWrap bool
Ellipsize bool
}
// MessageStyle is the message style.
type MessageStyle uint
// The message styles.
const (
InfoStyle MessageStyle = iota
WarningStyle
ErrorStyle
QuestionStyle
)
// Message are options for the message dialog.
type Message struct {
General
GeneralText
GeneralButton
Style MessageStyle
Icon DialogIcon
}
// OptionsStyle is the style with which the list dialog is rendered.
type OptionsStyle uint
const (
// OptionsStyleList renders the list dialog with a selection list.
OptionsStyleList OptionsStyle = iota
// OptionsStyleButtons renders the list dialog with a buttons list.
// Multiple selections can therefore not be performed.
// Unsupported at the moment.
OptionsStyleButtons
)
// Options are options for the options dialog.
type Options struct {
General
GeneralText
GeneralButton
Options []string
DefaultOptions []uint
Style OptionsStyle
MultipleSelection bool
}
// Entry are options for the entry dialog.
type Entry struct {
General
GeneralText
GeneralButton
DefaultEntry string
HideDefaultEntry bool
Icon DialogIcon // Only on macOS supported.
}
// Notification are options for the notification.
type Notification struct {
General
Text string
}
// FileFilter is file filter for the file dialog.
type FileFilter struct {
Name string // Name that describes the filter (optional).
Patterns []string // Filter patterns for the display string.
}
// GeneralFile are general options for file dialog.
type GeneralFile struct {
// Root directory of the file dialog. (default is current working dir)
Root string
// Default file/directory name in the dialog.
Filename string
// File filter.
FileFilters []FileFilter
// Show hidden files.
ShowHidden bool // Windows and macOS only.
// Select only directories.
OnlyDirectories bool
}
// FileSave are options for the file dialog.
type FileSave struct {
General
GeneralFile
// Confirm if the file get overwritten.
// Cannot be disabled on macOS.
ConfirmOverwrite bool
// Confirm if the file does not exist.
ConfirmCreate bool // Windows only.
}
// FileSelection are options for the file dialog.
// Note: Adding member -> Check Conversion from `FileSave` -> `FileSelection`.
type FileSelection struct {
General
GeneralFile
MultipleSelection bool
}
func (s *Message) SetDefaultIcons() {
switch s.Style {
case QuestionStyle:
if s.WindowIcon == UndefinedIcon {
s.WindowIcon = QuestionIcon
}
if s.Icon == UndefinedIcon {
s.Icon = QuestionIcon
}
case InfoStyle:
if s.WindowIcon == UndefinedIcon {
s.WindowIcon = InfoIcon
}
if s.Icon == UndefinedIcon {
s.Icon = InfoIcon
}
case WarningStyle:
if s.WindowIcon == UndefinedIcon {
s.WindowIcon = WarningIcon
}
if s.Icon == UndefinedIcon {
s.Icon = WarningIcon
}
case ErrorStyle:
if s.WindowIcon == UndefinedIcon {
s.WindowIcon = ErrorIcon
}
if s.Icon == UndefinedIcon {
s.Icon = ErrorIcon
}
}
}