-
Notifications
You must be signed in to change notification settings - Fork 0
/
searching.go
126 lines (104 loc) · 3.69 KB
/
searching.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
// searching.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"
glfsft "github.com/hfmrow/genLib/files/fileText"
)
func getArguments() (treeviewSelectedRows []string, entrySearchText, entryReplaceText string, err error) {
var rows [][]string
entrySearchText = GetEntryText(obj.entrySearch)
entryReplaceText = GetEntryText(obj.entryReplace)
if len(entrySearchText) == 0 {
err = errors.New(sts["nothingToSearch"])
return
}
// if there is no row selected, consider there are all selected.
if tvsList.Selection.CountSelectedRows() == 0 {
// err = errors.New(sts["noFileSel"])
// return
treeviewSelectedRows, err = tvsList.StoreColToStringSl(opt.mapListStore["pathReal"])
} else if rows, err = tvsList.GetSelectedRows(); err == nil {
for _, row := range rows {
treeviewSelectedRows = append(treeviewSelectedRows, row[opt.mapListStore["pathReal"]])
}
}
return
}
func searchAndReplace(treeviewSelectedRows []string,
entrySearchText, entryReplaceText string,
removeEmptyResult, replace bool) (mainFound []glfsft.SearchAndReplaceFiles, occurrences int, err error) {
return SearchAndReplaceInFiles(
treeviewSelectedRows,
entrySearchText,
entryReplaceText,
opt.FileMinSizeLimit, // Size limit >
opt.FileMaxSizeLimit, // Size limit <
obj.chkCaseSensitive.GetActive(),
obj.chkCharacterClass.GetActive(),
obj.chkCharacterClassStrictMode.GetActive(),
obj.chkRegex.GetActive(),
obj.chkWildcard.GetActive(),
obj.chkUseEscapeChar.GetActive(),
obj.chkUseEscapeCharToReplace.GetActive(),
obj.chkWholeWord.GetActive(),
replace, // DoReplace
acceptBinary,
removeEmptyResult)
}
func displayResults(occurrences int) (countFiles int) {
if occurrences > 0 {
// Prepare displaying results window
if !alreadyPlacedFoundWin {
x, y := obj.mainWin.GetPosition()
obj.findWin.Move(x+opt.CascadeDepth, y+opt.CascadeDepth)
obj.findWin.Resize(obj.mainWin.GetSize())
alreadyPlacedFoundWin = true
}
countFiles = showResults(&filesFoundMulti)
findWinTitle.Update([]string{fmt.Sprintf("%s %d %s %d %s", sts["totalOccurrences"], occurrences, sts["in"], countFiles, sts["file"])})
BringToFront(obj.findWin)
return
}
DialogMessage(obj.mainWin, "warning", sts["done"], "\n\n"+sts["notFound"], "", "Ok")
return
}
// onTheFlySearch:
func onTheFlySearch(inTextBytes []byte, doReplace bool) (outTextBytes []byte, err error) {
if len(inTextBytes) != 0 {
if !fileFoundSingle.IsReadyToReplace() {
fileFoundSingle = SearchAndReplaceNew("", []byte{}, "", "")
}
fileFoundSingle.Init(
inTextBytes,
fmt.Sprint(GetEntryText(obj.entrySearch)),
fmt.Sprint(GetEntryText(obj.entryReplace)),
obj.chkCaseSensitive.GetActive(),
obj.chkCharacterClass.GetActive(),
obj.chkCharacterClassStrictMode.GetActive(),
obj.chkRegex.GetActive(),
obj.chkWildcard.GetActive(),
obj.chkUseEscapeChar.GetActive(),
obj.chkUseEscapeCharToReplace.GetActive(),
obj.chkWholeWord.GetActive(),
doReplace)
// Return text after replacement (i.e: clipboard replace)
if err = fileFoundSingle.SearchAndReplace(); err == nil {
outTextBytes = fileFoundSingle.TextBytes
if doReplace {
// Get back original TextBytes, we don't want a real replacement ...
fileFoundSingle.TextBytes = inTextBytes
}
}
}
return
}