This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabMakeOptions.go
179 lines (160 loc) · 5.28 KB
/
tabMakeOptions.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
// tabMakeOption.go
package main
import (
"strings"
"github.com/andlabs/ui"
"github.com/hfmrow/csveditor/genLib"
)
func tabMakeOptions(vbox *ui.Box) *ui.Box {
if CsvProfileList.Initialised { // If there is nothing to display, skip it ...
vbox.Enable() // Used to know if control has been already initialised
// Create options Form
entryForm := ui.NewForm()
entryForm.SetPadded(true)
vbox.Append(entryForm, false)
// First part in a group
gridComma := ui.NewGrid()
gridComma.SetPadded(true)
groupCommaQuote := ui.NewGroup(" C.S.V format: " + genLib.TruncateString(CsvProfileList.FileName, "...", 80, 1))
groupCommaQuote.SetMargined(true)
groupCommaQuote.SetChild(gridComma)
vbox.Append(groupCommaQuote, false)
// Populate fields
outComma := ui.NewEditableCombobox()
outComma.Append(`,`)
outComma.Append(`;`)
outComma.Append(`\t`)
outComma.SetText(CsvProfileList.OutComma)
outComma.OnChanged(func(*ui.EditableCombobox) {
CsvProfileList.OutComma = outComma.Text()
CsvProfileList.Modified = true
})
outQuote := ui.NewCombobox()
outQuote.Disable() // TODO using csvtrans
outQuote.Append(`"`)
outQuote.Append(`'`)
outQuote.SetSelected(getValChar("s", CsvProfileList.OutQuote).(int))
outQuote.OnSelected(func(*ui.Combobox) {
CsvProfileList.OutQuote = getValChar("s", outQuote.Selected()).(string)
CsvProfileList.Modified = true
})
outCRLF := ui.NewCombobox()
outCRLF.Append(`CR`)
outCRLF.Append(`LF`)
outCRLF.Append(`CRLF`)
outCRLF.SetSelected(getValChar("c", CsvProfileList.OutCrlf).(int))
outCRLF.OnSelected(func(*ui.Combobox) {
CsvProfileList.OutCrlf = getValChar("c", outCRLF.Selected()).(string)
CsvProfileList.Modified = true
})
fmtDate1 := ui.NewCombobox()
fmtDate2 := ui.NewCombobox()
fmtDate3 := ui.NewCombobox()
decimalSep := ui.NewCombobox()
decimalSep.Append(",")
decimalSep.Append(".")
decimalSep.SetSelected(0)
decimalSep.OnSelected(func(*ui.Combobox) {
switch decimalSep.Selected() {
case 0:
CsvProfileList.DecimalSep = ","
CsvProfileList.Modified = true
case 1:
CsvProfileList.DecimalSep = "."
CsvProfileList.Modified = true
}
})
// Populate Date format (combobox)
for idx := 0; idx < len(DatE[0]); idx++ {
fmtDate1.Append(DatE[0][idx])
fmtDate2.Append(DatE[0][idx])
fmtDate3.Append(DatE[0][idx])
}
dateFormat := strings.Split(CsvProfileList.DateFormat, "-")
fmtDate1.SetSelected(getDateFmt(DatE[0][getDateFmt(dateFormat[0])]))
fmtDate2.SetSelected(getDateFmt(DatE[0][getDateFmt(dateFormat[1])]))
fmtDate3.SetSelected(getDateFmt(DatE[0][getDateFmt(dateFormat[2])]))
fmtDate1.OnSelected(func(*ui.Combobox) { storeDateFmt(fmtDate1.Selected(), 0) })
fmtDate2.OnSelected(func(*ui.Combobox) { storeDateFmt(fmtDate2.Selected(), 1) })
fmtDate3.OnSelected(func(*ui.Combobox) { storeDateFmt(fmtDate3.Selected(), 2) })
outCharset := ui.NewCombobox()
CharsetList := genLib.NewCharsetList()
// Populate charset names (combobox)
for _, cs := range CharsetList.SimpleCharsetList {
outCharset.Append(cs)
}
_, cShort := CharsetList.GetPos(CsvProfileList.OutCharset)
outCharset.SetSelected(cShort)
outCharset.OnSelected(func(*ui.Combobox) {
_, outcShort := CharsetList.GetCharset(outCharset.Selected())
CsvProfileList.OutCharset = outcShort
CsvProfileList.Modified = true
})
// Display Date format
gridComma.Append(ui.NewLabel("Date format: "),
0, 0, 1, 1,
true, ui.AlignEnd, false, ui.AlignCenter)
gridComma.Append(fmtDate1,
1, 0, 1, 1,
true, ui.AlignStart, false, ui.AlignCenter)
gridComma.Append(fmtDate2,
1, 0, 2, 1,
true, ui.AlignCenter, false, ui.AlignCenter)
gridComma.Append(fmtDate3,
2, 0, 1, 1,
true, ui.AlignStart, false, ui.AlignCenter)
// Display decimal separator choice
gridComma.Append(ui.NewLabel("Decimal separator: "),
4, 0, 1, 1,
true, ui.AlignEnd, false, ui.AlignCenter)
gridComma.Append(decimalSep,
5, 0, 1, 1,
true, ui.AlignCenter, false, ui.AlignCenter)
// Display controls
gridComma.Append(ui.NewLabel("Out comma: "),
0, 1, 1, 1,
true, ui.AlignEnd, false, ui.AlignCenter)
gridComma.Append(outComma,
1, 1, 1, 1,
true, ui.AlignStart, false, ui.AlignEnd)
gridComma.Append(ui.NewLabel("Out quote: "),
2, 1, 1, 1,
true, ui.AlignEnd, false, ui.AlignCenter)
gridComma.Append(outQuote,
3, 1, 1, 1,
true, ui.AlignStart, false, ui.AlignEnd)
//
gridComma.Append(ui.NewLabel("Out line-end: "),
4, 1, 1, 1,
true, ui.AlignEnd, false, ui.AlignCenter)
gridComma.Append(outCRLF,
5, 1, 1, 1,
true, ui.AlignStart, false, ui.AlignEnd)
gridComma.Append(ui.NewLabel("Out charset: "),
6, 1, 1, 1,
true, ui.AlignEnd, false, ui.AlignCenter)
gridComma.Append(outCharset,
7, 1, 1, 1,
true, ui.AlignStart, false, ui.AlignEnd)
vbox = tabMakeOptionFields(vbox)
}
return vbox
}
// Refresh Option fields and Table tab
func refreshOption() {
mainTab.Delete(1)
mainTab.InsertAt("Options", 1, tabOptions()) // Display (Option fields) with new values
}
func storeDateFmt(value, idx int) {
dateFormat := strings.Split(CsvProfileList.DateFormat, "-")
switch idx {
case 0:
dateFormat[0] = DatE[1][value]
case 1:
dateFormat[1] = DatE[1][value]
case 2:
dateFormat[2] = DatE[1][value]
}
CsvProfileList.DateFormat = strings.Join(dateFormat, "-")
CsvProfileList.Modified = true
}