Documentation ¶
Overview ¶
Package gexplorer is based on https://github.com/gioui/gio-x/blob/main/explorer This version only wants to work with filename/filepath which is more flexible than any other types.
Given the filename/filepath, the caller of this package is able to do whatever it want.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUserDecline is returned when the user doesn't select the file. ErrUserDecline = errors.New("user exited the file selector without selecting a file") // ErrNotAvailable is return when the current OS isn't supported. ErrNotAvailable = errors.New("current OS not supported") )
Functions ¶
This section is empty.
Types ¶
type Explorer ¶
type Explorer struct {
// contains filtered or unexported fields
}
Explorer facilitates opening OS-native dialogs to choose files and create files.
func NewExplorer ¶
func NewExplorer(run RunHandler) (e *Explorer)
NewExplorer creates a new Explorer for the given RunHandler. The given RunHandler must be unique and you should call NewExplorer once per new RunHandler.
func (*Explorer) ChooseFile ¶
ChooseFile shows the file selector, allowing the user to select a single file. Optionally, it's possible to define which file extensions is supported to be selected (such as `.jpg`, `.png`).
Example: ChooseFile(".jpg", ".png") will only accept the selection of files with .jpg or .png extensions.
In most known browsers, when user clicks cancel then this function never returns.
It's a blocking call, you should call it on a separated goroutine. For most OSes, only one ChooseFile or CreateFile, can happen at the same time, for each Explorer.
func (*Explorer) ChooseFiles ¶
ChooseFiles shows the files selector, allowing the user to select multiple files. Optionally, it's possible to define which file extensions is supported to be selected (such as `.jpg`, `.png`).
Example: ChooseFiles(".jpg", ".png") will only accept the selection of files with .jpg or .png extensions.
In most known browsers, when user clicks cancel then this function never returns.
It's a blocking call, you should call it on a separated goroutine. For most OSes, only one ChooseFile{,s} or CreateFile, can happen at the same time, for each Explorer.
func (*Explorer) CreateFile ¶
CreateFile opens the file selector, and writes the given content into some file, which the use can choose the location.
It's a blocking call, you should call it on a separated goroutine. For most OSes, only one ChooseFile or CreateFile, can happen at the same time, for each Explorer.
type RunHandler ¶
type RunHandler func(func())
RunHandler allows to run a function in the context of another thread. Mainly used for https://pkg.go.dev/gioui.org@v0.0.0-20230502183330-59695984e53c/app#Window.Run