mirror of
https://github.com/nwg-piotr/nwg-drawer.git
synced 2024-08-16 09:10:21 +03:00
file search improved
This commit is contained in:
parent
2a4a00c8f3
commit
675631949e
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
|
||||
status string
|
||||
mainColumnWidth int
|
||||
ignore string
|
||||
)
|
||||
|
||||
// Flags
|
||||
@ -315,7 +316,6 @@ func main() {
|
||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||
|
||||
userDirsMap = mapXdgUserDirs()
|
||||
fmt.Println(userDirsMap)
|
||||
|
||||
placeholder, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||
resultsWrapper.PackStart(placeholder, true, true, 0)
|
||||
|
@ -274,12 +274,17 @@ func walk(path string, d fs.DirEntry, e error) error {
|
||||
return e
|
||||
}
|
||||
//if !d.IsDir() {
|
||||
parts := strings.Split(path, "/")
|
||||
//fileName := parts[len(parts)-1]
|
||||
fileName := strings.Join(parts[4:], "/")
|
||||
if strings.Contains(strings.ToLower(fileName), strings.ToLower(phrase)) {
|
||||
fileSearchResults = append(fileSearchResults, path)
|
||||
// don't search leading part of the path, as e.g. '/home/user/Pictures'
|
||||
toSearch := strings.Split(path, ignore)[1]
|
||||
if strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) {
|
||||
// mark directories
|
||||
if d.IsDir() {
|
||||
fileSearchResults = append(fileSearchResults, fmt.Sprintf("#is_dir#%s", path))
|
||||
} else {
|
||||
fileSearchResults = append(fileSearchResults, path)
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
return nil
|
||||
}
|
||||
@ -339,9 +344,10 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
||||
|
||||
func searchUserDir(dir string) {
|
||||
fileSearchResults = nil
|
||||
ignore = userDirsMap[dir]
|
||||
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)
|
||||
fileSearchResultFlowBox.Add(btn)
|
||||
|
||||
@ -393,6 +399,13 @@ func setUpUserFileSearchResultButton(fileName, filePath string) *gtk.Box {
|
||||
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
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 := ""
|
||||
if len(fileName) > *nameLimit {
|
||||
tooltipText = fileName
|
||||
|
Loading…
Reference in New Issue
Block a user