59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package zenity
|
|
|
|
import (
|
|
"github.com/ncruces/zenity/internal/zenutil"
|
|
)
|
|
|
|
func selectFile(opts options) (string, error) {
|
|
var data zenutil.File
|
|
data.Options.Prompt = opts.title
|
|
data.Options.Invisibles = opts.showHidden
|
|
data.Options.Location, _ = splitDirAndName(opts.filename)
|
|
|
|
if opts.directory {
|
|
data.Operation = "chooseFolder"
|
|
} else {
|
|
data.Operation = "chooseFile"
|
|
data.Options.Type = opts.fileFilters.darwin()
|
|
}
|
|
|
|
out, err := zenutil.Run(opts.ctx, "file", data)
|
|
str, _, err := strResult(opts, out, err)
|
|
return str, err
|
|
}
|
|
|
|
func selectFileMutiple(opts options) ([]string, error) {
|
|
var data zenutil.File
|
|
data.Options.Prompt = opts.title
|
|
data.Options.Invisibles = opts.showHidden
|
|
data.Options.Location, _ = splitDirAndName(opts.filename)
|
|
data.Options.Multiple = true
|
|
data.Separator = zenutil.Separator
|
|
|
|
if opts.directory {
|
|
data.Operation = "chooseFolder"
|
|
} else {
|
|
data.Operation = "chooseFile"
|
|
data.Options.Type = opts.fileFilters.darwin()
|
|
}
|
|
|
|
out, err := zenutil.Run(opts.ctx, "file", data)
|
|
return lstResult(opts, out, err)
|
|
}
|
|
|
|
func selectFileSave(opts options) (string, error) {
|
|
var data zenutil.File
|
|
data.Options.Prompt = opts.title
|
|
data.Options.Invisibles = opts.showHidden
|
|
data.Options.Location, data.Options.Name = splitDirAndName(opts.filename)
|
|
|
|
if opts.directory {
|
|
data.Operation = "chooseFolder"
|
|
} else {
|
|
data.Operation = "chooseFileName"
|
|
}
|
|
|
|
out, err := zenutil.Run(opts.ctx, "file", data)
|
|
str, _, err := strResult(opts, out, err)
|
|
return str, err
|
|
}
|