multiple fixes

This commit is contained in:
piotr 2021-09-28 02:40:23 +02:00
parent a9fe4a7371
commit 1f91ade8e6
4 changed files with 37 additions and 20 deletions

Binary file not shown.

View File

@ -262,7 +262,7 @@ func main() {
// For opening files we use xdg-open. As its configuration is PITA, we may override some associations
// in the ~/.config/nwg-panel/preferred-apps.json file.
paFile := filepath.Join(configDirectory, "preferred-apps.json")
paFile := path.Join(configDirectory, "preferred-apps.json")
preferredApps, err = loadPreferredApps(paFile)
if err != nil {
log.Infof("Custom associations file %s not found or invalid", paFile)
@ -271,13 +271,12 @@ func main() {
}
// Load user-defined paths excluded from file search
exFile := filepath.Join(configDirectory, "excluded-dirs")
exFile := path.Join(configDirectory, "excluded-dirs")
exclusions, err = loadTextFile(exFile)
if err != nil {
log.Infof("Search exclusions file %s not found %s", exFile, err)
} else {
log.Infof("Found %v search exclusions in %s", len(exclusions), exFile)
log.Info(exclusions)
}
// USER INTERFACE

View File

@ -154,18 +154,23 @@ func oldConfigDir() (string, error) {
if os.Getenv("XDG_CONFIG_HOME") != "" {
dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-panel")
return dir, nil
} else if os.Getenv("HOME") != "" {
dir := path.Join(os.Getenv("HOME"), ".config/nwg-panel")
return dir, nil
}
return "", errors.New("old config dir not found")
}
func configDir() string {
var home string
home = os.Getenv("XDG_CONFIG_HOME")
if home == "" {
home = os.Getenv("HOME")
var dir string
if os.Getenv("XDG_CONFIG_HOME") != "" {
dir = path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-drawer")
} else if os.Getenv("HOME") != "" {
dir = path.Join(os.Getenv("HOME"), ".config/nwg-drawer")
}
dir := path.Join(home, ".config/nwg-drawer")
log.Infof("Config dir: %s", dir)
createDir(dir)
return dir

View File

@ -291,16 +291,26 @@ func walk(path string, d fs.DirEntry, e error) error {
if e != nil {
return e
}
if !isExcluded(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)
}
// don't search leading part of the path, as e.g. '/home/user/Pictures'
toSearch := strings.Split(path, ignore)[1]
// Remaing part of the path (w/o file name) must be checked against being present in excluded dirs
doSearch := true
parts := strings.Split(toSearch, "/")
remainingPart := ""
if len(parts) > 1 {
remainingPart = strings.Join(parts[:len(parts)-1], "/")
}
if remainingPart != "" && isExcluded(remainingPart) {
doSearch = false
}
if doSearch && 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)
}
}
@ -412,8 +422,11 @@ func searchUserDir(dir string) {
for _, path := range fileSearchResults {
partOfPathToShow := strings.Split(path, userDirsMap[dir])[1]
if partOfPathToShow != "" {
btn := setUpUserFileSearchResultButton(partOfPathToShow, path)
fileSearchResultFlowBox.Add(btn)
if !(strings.HasPrefix(path, "#is_dir#") && isExcluded(path)) {
btn := setUpUserFileSearchResultButton(partOfPathToShow, path)
fileSearchResultFlowBox.Add(btn)
}
}
}
fileSearchResultFlowBox.Hide()