file search improved
This commit is contained in:
BIN
bin/nwg-drawer
BIN
bin/nwg-drawer
Binary file not shown.
2
main.go
2
main.go
@@ -103,6 +103,7 @@ var (
|
|||||||
statusLabel *gtk.Label
|
statusLabel *gtk.Label
|
||||||
status string
|
status string
|
||||||
mainColumnWidth int
|
mainColumnWidth int
|
||||||
|
ignore string
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
@@ -315,7 +316,6 @@ func main() {
|
|||||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||||
|
|
||||||
userDirsMap = mapXdgUserDirs()
|
userDirsMap = mapXdgUserDirs()
|
||||||
fmt.Println(userDirsMap)
|
|
||||||
|
|
||||||
placeholder, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
placeholder, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
resultsWrapper.PackStart(placeholder, true, true, 0)
|
resultsWrapper.PackStart(placeholder, true, true, 0)
|
||||||
|
|||||||
@@ -274,12 +274,17 @@ func walk(path string, d fs.DirEntry, e error) error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
//if !d.IsDir() {
|
//if !d.IsDir() {
|
||||||
parts := strings.Split(path, "/")
|
// don't search leading part of the path, as e.g. '/home/user/Pictures'
|
||||||
//fileName := parts[len(parts)-1]
|
toSearch := strings.Split(path, ignore)[1]
|
||||||
fileName := strings.Join(parts[4:], "/")
|
if strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) {
|
||||||
if strings.Contains(strings.ToLower(fileName), strings.ToLower(phrase)) {
|
// mark directories
|
||||||
|
if d.IsDir() {
|
||||||
|
fileSearchResults = append(fileSearchResults, fmt.Sprintf("#is_dir#%s", path))
|
||||||
|
} else {
|
||||||
fileSearchResults = append(fileSearchResults, path)
|
fileSearchResults = append(fileSearchResults, path)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//}
|
//}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -339,9 +344,10 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
|
|
||||||
func searchUserDir(dir string) {
|
func searchUserDir(dir string) {
|
||||||
fileSearchResults = nil
|
fileSearchResults = nil
|
||||||
|
ignore = userDirsMap[dir]
|
||||||
filepath.WalkDir(userDirsMap[dir], walk)
|
filepath.WalkDir(userDirsMap[dir], walk)
|
||||||
|
|
||||||
if fileSearchResults != nil && len(fileSearchResults) > 2 {
|
if fileSearchResults != nil && len(fileSearchResults) > 0 {
|
||||||
btn := setUpUserDirButton(fmt.Sprintf("folder-%s", dir), "", dir, userDirsMap)
|
btn := setUpUserDirButton(fmt.Sprintf("folder-%s", dir), "", dir, userDirsMap)
|
||||||
fileSearchResultFlowBox.Add(btn)
|
fileSearchResultFlowBox.Add(btn)
|
||||||
|
|
||||||
@@ -393,6 +399,13 @@ func setUpUserFileSearchResultButton(fileName, filePath string) *gtk.Box {
|
|||||||
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
button, _ := gtk.ButtonNew()
|
button, _ := gtk.ButtonNew()
|
||||||
|
|
||||||
|
// in the walk function we've marked directories with the '#is_dir#' prefix
|
||||||
|
if strings.HasPrefix(filePath, "#is_dir#") {
|
||||||
|
filePath = filePath[8:]
|
||||||
|
img, _ := gtk.ImageNewFromIconName("folder", gtk.ICON_SIZE_MENU)
|
||||||
|
button.SetImage(img)
|
||||||
|
}
|
||||||
|
|
||||||
tooltipText := ""
|
tooltipText := ""
|
||||||
if len(fileName) > *nameLimit {
|
if len(fileName) > *nameLimit {
|
||||||
tooltipText = fileName
|
tooltipText = fileName
|
||||||
|
|||||||
Reference in New Issue
Block a user