diff --git a/dialog/file_notunix.go b/dialog/file_notunix.go new file mode 100644 index 0000000000..f5a6637efe --- /dev/null +++ b/dialog/file_notunix.go @@ -0,0 +1,11 @@ +//go:build (!linux && !openbsd && !freebsd && !netbsd) || android || wasm || js + +package dialog + +func fileOpenOSOverride(*FileDialog) bool { + return false +} + +func fileSaveOSOverride(*FileDialog) bool { + return false +} diff --git a/dialog/file_unix.go b/dialog/file_unix.go index bcb6b3cc08..dea11fbe4a 100644 --- a/dialog/file_unix.go +++ b/dialog/file_unix.go @@ -37,11 +37,3 @@ func isHidden(file fyne.URI) bool { func hideFile(filename string) error { return nil } - -func fileOpenOSOverride(*FileDialog) bool { - return false -} - -func fileSaveOSOverride(*FileDialog) bool { - return false -} diff --git a/dialog/file_xdg.go b/dialog/file_xdg.go index 824aa1bce3..846567902a 100644 --- a/dialog/file_xdg.go +++ b/dialog/file_xdg.go @@ -12,6 +12,7 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/storage" + "github.com/rymdport/portal/filechooser" "golang.org/x/sys/execabs" ) @@ -74,3 +75,61 @@ func getFavoriteLocations() (map[string]fyne.ListableURI, error) { return favoriteLocations, err } + +func fileOpenOSOverride(d *FileDialog) bool { + go func() { + callback, folder := d.callback.(func(fyne.ListableURI, error)) + options := &filechooser.OpenOptions{Modal: true, Directory: folder} + + uris, err := filechooser.OpenFile("", "Open File", options) + if !folder { + callback := d.callback.(func(fyne.URIReadCloser, error)) + if err != nil { + callback(nil, err) + return + } + + uri, err := storage.ParseURI(uris[0]) + if err != nil { + callback(nil, err) + return + } + + callback(storage.Reader(uri)) + return + } + if err != nil { + callback(nil, err) + } + + uri, err := storage.ParseURI(uris[0]) + if err != nil { + callback(nil, err) + return + } + + callback(storage.ListerForURI(uri)) + }() + + return true +} + +func fileSaveOSOverride(d *FileDialog) bool { + go func() { + callback := d.callback.(func(fyne.URIWriteCloser, error)) + uris, err := filechooser.SaveFile("", "Open File", &filechooser.SaveSingleOptions{Modal: true}) + if err != nil { + callback(nil, err) + return + } + + uri, err := storage.ParseURI(uris[0]) + if err != nil { + callback(nil, err) + return + } + + callback(storage.Writer(uri)) + }() + return true +}