Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seperate plat code of dialog into different files
- Loading branch information
Showing
4 changed files
with
110 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dialog | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func getFavoriteLocations() (map[string]string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return map[string]string{ | ||
"Home": homeDir, | ||
"Documents": filepath.Join(homeDir, "Documents"), | ||
"Downloads": filepath.Join(homeDir, "Downloads"), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dialog | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
func getFavoriteLocationLinux(homeDir, name string) (string, error) { | ||
cmdName := "xdg-user-dir" | ||
fallback := filepath.Join(homeDir, name) | ||
|
||
if _, err := exec.LookPath(cmdName); err != nil { | ||
return fallback, fmt.Errorf("%s not found in PATH. using fallback paths", cmdName) | ||
} | ||
|
||
cmd := exec.Command(cmdName, name) | ||
stdout := bytes.NewBufferString("") | ||
|
||
cmd.Stdout = stdout | ||
err := cmd.Run() | ||
if err != nil { | ||
return fallback, err | ||
} | ||
|
||
loc := stdout.String() | ||
// Remove \n at the end | ||
loc = loc[:len(loc)-1] | ||
|
||
if loc == homeDir { | ||
return fallback, fmt.Errorf("this computer does not have a %s folder", name) | ||
} | ||
|
||
return stdout.String(), nil | ||
} | ||
|
||
func getFavoriteLocations() (map[string]string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rv := map[string]string{ | ||
"Home": homeDir, | ||
} | ||
var err error | ||
documentsDir, err1 := getFavoriteLocationLinux(homeDir, "DOCUMENTS") | ||
if err == nil { | ||
rv["Documents"] = documentsDir | ||
} else { | ||
rv["Documents"] = filepath.Join(homeDir, "Documents") | ||
err = err1 | ||
} | ||
downloadsDir, err1 := getFavoriteLocationLinux(homeDir, "DOWNLOADS") | ||
if err == nil { | ||
rv["Downloads"] = downloadsDir | ||
} else { | ||
rv["Downloads"] = filepath.Join(homeDir, "Downloads") | ||
err = err1 | ||
} | ||
|
||
return rv, err | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// +build !windows,!android,!ios | ||
|
||
package dialog | ||
|
||
import ( | ||
"fyne.io/fyne" | ||
"fyne.io/fyne/theme" | ||
) | ||
|
||
func (f *fileDialog) loadPlaces() []fyne.CanvasObject { | ||
return []fyne.CanvasObject{makeFavoriteButton("Computer", theme.ComputerIcon(), func() { | ||
f.setDirectory("/") | ||
})} | ||
} | ||
|
||
func isHidden(file, _ string) bool { | ||
return len(file) == 0 || file[0] == '.' | ||
} | ||
|
||
func fileOpenOSOverride(*FileDialog) bool { | ||
return false | ||
} | ||
|
||
func fileSaveOSOverride(*FileDialog) bool { | ||
return false | ||
} |