mirror of
https://github.com/nwg-piotr/nwg-drawer.git
synced 2024-10-26 14:53:57 +03:00
multiple fixes
This commit is contained in:
parent
a9fe4a7371
commit
1f91ade8e6
BIN
bin/nwg-drawer
BIN
bin/nwg-drawer
Binary file not shown.
5
main.go
5
main.go
@ -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
|
||||
|
15
tools.go
15
tools.go
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user