forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 1
/
folder.go
41 lines (34 loc) · 1.07 KB
/
folder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package dialog
import (
"fyne.io/fyne"
"fyne.io/fyne/storage"
)
var folderFilter = storage.NewMimeTypeFileFilter([]string{"application/x-directory"})
// NewFolderOpen creates a file dialog allowing the user to choose a folder to open.
// The dialog will appear over the window specified when Show() is called.
func NewFolderOpen(callback func(fyne.ListableURI, error), parent fyne.Window) *FileDialog {
dialog := &FileDialog{}
dialog.callback = callback
dialog.parent = parent
dialog.filter = folderFilter
return dialog
}
// ShowFolderOpen creates and shows a file dialog allowing the user to choose a folder to open.
// The dialog will appear over the window specified.
func ShowFolderOpen(callback func(fyne.ListableURI, error), parent fyne.Window) {
dialog := NewFolderOpen(callback, parent)
if fileOpenOSOverride(dialog) {
return
}
dialog.Show()
}
func (f *FileDialog) isDirectory() bool {
return f.filter == folderFilter
}
func isListable(u fyne.URI) bool {
if _, ok := u.(fyne.ListableURI); ok {
return true
}
_, err := storage.ListerForURI(u)
return err == nil
}