Skip to content

Commit

Permalink
Wire up initial support for file and folder dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Nov 19, 2023
1 parent b6ff012 commit da68adf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
11 changes: 11 additions & 0 deletions dialog/file_notunix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build (!linux && !openbsd && !freebsd && !netbsd) || android || wasm || js

package dialog

func fileOpenOSOverride(*FileDialog) bool {

Check failure on line 5 in dialog/file_notunix.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.17.x, windows-latest)

previous declaration

Check failure on line 5 in dialog/file_notunix.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.17.x, windows-latest)

previous declaration

Check failure on line 5 in dialog/file_notunix.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.20.x, windows-latest)

other declaration of fileOpenOSOverride
return false
}

func fileSaveOSOverride(*FileDialog) bool {

Check failure on line 9 in dialog/file_notunix.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.17.x, windows-latest)

previous declaration

Check failure on line 9 in dialog/file_notunix.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.17.x, windows-latest)

previous declaration

Check failure on line 9 in dialog/file_notunix.go

View workflow job for this annotation

GitHub Actions / platform_tests (1.20.x, windows-latest)

other declaration of fileSaveOSOverride
return false
}
8 changes: 0 additions & 8 deletions dialog/file_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
59 changes: 59 additions & 0 deletions dialog/file_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/storage"
"github.com/rymdport/portal/filechooser"

"golang.org/x/sys/execabs"
)
Expand Down Expand Up @@ -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
}

0 comments on commit da68adf

Please sign in to comment.