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 // 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. // 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) preferredApps, err = loadPreferredApps(paFile)
if err != nil { if err != nil {
log.Infof("Custom associations file %s not found or invalid", paFile) 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 // Load user-defined paths excluded from file search
exFile := filepath.Join(configDirectory, "excluded-dirs") exFile := path.Join(configDirectory, "excluded-dirs")
exclusions, err = loadTextFile(exFile) exclusions, err = loadTextFile(exFile)
if err != nil { if err != nil {
log.Infof("Search exclusions file %s not found %s", exFile, err) log.Infof("Search exclusions file %s not found %s", exFile, err)
} else { } else {
log.Infof("Found %v search exclusions in %s", len(exclusions), exFile) log.Infof("Found %v search exclusions in %s", len(exclusions), exFile)
log.Info(exclusions)
} }
// USER INTERFACE // USER INTERFACE

View File

@@ -154,18 +154,23 @@ func oldConfigDir() (string, error) {
if os.Getenv("XDG_CONFIG_HOME") != "" { if os.Getenv("XDG_CONFIG_HOME") != "" {
dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-panel") dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-panel")
return dir, nil 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") return "", errors.New("old config dir not found")
} }
func configDir() string { func configDir() string {
var home string var dir string
home = os.Getenv("XDG_CONFIG_HOME") if os.Getenv("XDG_CONFIG_HOME") != "" {
if home == "" { dir = path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-drawer")
home = os.Getenv("HOME") } 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) createDir(dir)
return dir return dir

View File

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