-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
275 lines (228 loc) · 8.13 KB
/
main.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
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
// main.go
/*
Source file auto-generated on Sat, 24 Apr 2021 04:33:11 using Gotk3 Objects Handler v1.7.8
©2018-21 hfmrow https://hfmrow.github.io
This software use gotk3 that is licensed under the ISC License:
https://github.com/gotk3/gotk3/blob/master/LICENSE
Copyright ©2018-21 hfmrow - Search And Replace v1.10 github.com/hfmrow/search-and-replace
This program comes with absolutely no warranty. See the The MIT License (MIT) for details:
https://opensource.org/licenses/mit-license.php
*/
package main
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"github.com/gotk3/gotk3/gtk"
)
func main() {
/* Build options */
// devMode: is used in some functions to control the behavior of the program
// When software is ready to be published, this flag must be set at "false"
// that means:
// - options file will be stored in $HOME/.config/[Creat]/[softwareName],
// - translate function if used, will no more auto-update "sts" map sentences,
// - all built-in assets will be used instead of the files themselves.
// Be aware to update assets via "Goh" and translations with "Got" before all.
devMode = false
absoluteRealPath, optFilename = getAbsRealPath()
/* Logger init. */
Logger = Log2FileStructNew(optFilename, devMode)
defer Logger.CloseLogger()
// Initialization of assets according to the chosen mode (devMode).
// you can set this flag to your liking without reference to devMode.
assetsDeclarationsUseEmbedded(!devMode)
// Create temp directory .. or not
doTempDir = false
/* Init & read options file */
opt = new(MainOpt) // Assignate options' structure.
opt.Read() // Read values from options' file if exists.
/* Init gtk display */
mainWindowTitle = fmt.Sprintf("%s %s %s %s %s",
Name,
Vers,
"©"+YearCreat,
Creat,
LicenseAbrv)
mainStartGtk(mainWindowTitle,
opt.MainWinWidth,
opt.MainWinHeight, true)
}
func mainApplication() {
var (
err error
tmpErr string
)
/* Init AboutBox */
About = AboutInfosNew(obj.mainWin)
About.ImageTopHeight = 40
About.FillInfos(
"About "+Name,
Name,
Vers,
Creat,
YearCreat,
LicenseAbrv,
LicenseShort,
Repository,
Descr,
"",
tickIcon48)
/* Specific UI tuning */
chkCharacterClassToggled()
/* Init Windows title for easy updating */
mainWinTitle = TitleBarStructureNew(obj.mainWin)
findWinTitle = TitleBarStructureNew(obj.findWin, sts["titleSearchResults"])
textWinTitle = TitleBarStructureNew(obj.textWin, sts["titlePreviewText"])
/* Translate init. */
translate = MainTranslateNew(absoluteRealPath+opt.LanguageFilename, devMode)
/* Init Statusbar */
statusbar = StatusBarStructureNew(obj.statusbar, []string{
sts["sbFiles"], sts["sbFilesSel"], sts["scanTime"],
sts["searchTime"], sts["dispTime"], sts["status"]})
/* Init ListStore */
if tvsList, err = TreeViewStructureNew(obj.listViewFiles, true, false); err == nil {
tvsList.AddColumns(opt.listStoreColumns, false, true, true, true, false, true)
// Define selection changed function .
tvsList.SelectionChangedFunc = func() {
if tvsList.Selection.CountSelectedRows() > 0 {
updateStatusBar()
}
}
tvsList.Columns[opt.mapListStore["pathReal"]].Visible = false // Hold filename not midified, hidden
if err = tvsList.StoreSetup(new(gtk.ListStore)); err == nil {
// Assign sorted column
tvsList.Columns[opt.mapListStore["Size"]].Column.SetSortColumnID(opt.mapListStore["sizeSort"]) // (col 1 will be sorted using values of col 4)
tvsList.Columns[opt.mapListStore["Date"]].Column.SetSortColumnID(opt.mapListStore["dateSort"]) // (col 2 will be sorted using values of col 5)
/* Init treeView popup menu */
initTreeViewPopupMenu()
/* Init TreeStore (found results) */
if tvsTree, err = TreeViewStructureNew(obj.findWinTreeView, true, false); err == nil {
tvsTree.AddColumns(opt.treeStoreColumns, false, true, false, false, false, true)
tvsTree.Columns[opt.mapTreeStore["Toggle"]].Editable = true
tvsTree.Columns[opt.mapTreeStore["Toggle"]].ReadOnly = false
tvsTree.Columns[opt.mapTreeStore["fileIdx"]].Visible = false // File index storage
tvsTree.Columns[opt.mapTreeStore["lineIdx"]].Visible = false // Line Index storage
tvsTree.CallbackOnSetColValue = func(iter *gtk.TreeIter, col int, value interface{}) {
if col == opt.mapTreeStore["Toggle"] {
fileIdx := int(tvsTree.GetColValue(iter, opt.mapTreeStore["fileIdx"]).(int64))
lineIdx := int(tvsTree.GetColValue(iter, opt.mapTreeStore["lineIdx"]).(int64))
if lineIdx > -1 {
idxExist := IsExistSlIface(
&filesFoundMulti[fileIdx].SearchAndRepl.Pos.UntouchedLines,
filesFoundMulti[fileIdx].SearchAndRepl.Pos.FoundLinesIdx[lineIdx].Number)
if !value.(bool) && idxExist == -1 {
filesFoundMulti[fileIdx].SearchAndRepl.Pos.UntouchedLines = append(
filesFoundMulti[fileIdx].SearchAndRepl.Pos.UntouchedLines,
filesFoundMulti[fileIdx].SearchAndRepl.Pos.FoundLinesIdx[lineIdx].Number)
} else if idxExist > -1 {
for idxExist > -1 {
DeleteSlIface(&filesFoundMulti[fileIdx].SearchAndRepl.Pos.UntouchedLines, idxExist)
idxExist = IsExistSlIface(
&filesFoundMulti[fileIdx].SearchAndRepl.Pos.UntouchedLines,
filesFoundMulti[fileIdx].SearchAndRepl.Pos.FoundLinesIdx[lineIdx].Number)
}
}
}
}
}
}
err = tvsTree.StoreSetup(new(gtk.TreeStore))
}
}
if err != nil {
DlgErr("mainApplication:TreeViewStructureNew", err)
return
}
/* Init Drag and drop */
dnd = DragNDropNew(obj.listViewFiles, ¤tInFilesList,
func() {
// Callaback function on Drag and drop operations
fromDnD = true
obj.switchFileChooserButton.SetActive(false)
if len(*dnd.FilesList) > 0 {
l := *dnd.FilesList
dir := filepath.Dir(l[0])
obj.fileChooserBtn.SetFilename(dir)
updateTreeViewFilesDisplay()
}
})
/* Init Clipboard */
clipboardInit()
/* Retreive command line arguments */
if len(os.Args) > 1 {
var countedError int
var flagError = true
for _, file := range os.Args[1:] {
if _, err = os.Stat(file); err == nil {
currentInFilesList = append(currentInFilesList, file)
} else {
if countedError < 14 && flagError {
tmpErr += err.Error() + "\n"
countedError++
} else {
flagError = false
tmpErr += "too many errors ...\n"
}
}
}
if err == nil {
fromDnD = true
obj.switchFileChooserButton.SetActive(false)
obj.fileChooserBtn.SetFilename("None")
} else {
if len(tmpErr) != 0 {
err = errors.New(tmpErr)
}
DlgErr("Retreive command line arguments", err)
return
}
}
/* TextView with line number init.*/
svs, err = SourceViewStructNew(obj.View, obj.Map, obj.textWin)
DlgErr("mainApplication:SourceViewStructNew", err)
svs.View.SetEditable(false)
svs.View.SetHighlightCurrentLine(true)
svs.Buffer.SetHighlightMatchingBrackets(true)
/* Handling "populate-popup" signal to add some personal entries */
svs.View.Connect("populate-popup", popupTextViewPopulateMenu)
/* Hide ProgressBar */
displayProgressBar(false)
/* Display files list */
updateTreeViewFilesDisplay()
/*Init single found structure */
fileFoundSingle = SearchAndReplaceNew("", []byte{}, "", "")
/* Initialize comboboxEntry */
svs.UserLanguagePath = filepath.Join(absoluteRealPath, opt.HighlightUserDefined)
svs.UserStylePath = filepath.Join(absoluteRealPath, opt.HighlightUserDefined)
svs.DefaultLanguageId = opt.DefaultSourceLang
svs.DefaultStyleShemeId = opt.DefaultSourceStyle
svs.ComboboxHandling(
obj.textWinComboBoxLanguage,
obj.textWinComboBoxTextStyleChooser,
&opt.DefaultSourceLang,
&opt.DefaultSourceStyle)
/* Focus search entry */
obj.entrySearch.GrabFocus()
/* Progressbar Init */
pbs = ProgressGifNew(linearProgressHorzBlue, obj.mainBox, 1)
}
/*************************************\
/* Executed just before closing all. */
/************************************/
func onShutdown() bool {
var err error
// Update opt with GtkObjects and save it
if err = opt.Write(); err == nil {
// What you want to execute before closing the app.
// Return:
// true for exit applicaton
// false does not exit application
}
if err != nil {
log.Fatalf("Unexpected error on exit: %s", err.Error())
}
return true
}