zenity/file_darwin.go

58 lines
1.4 KiB
Go
Raw Normal View History

2019-12-29 20:00:50 -05:00
package zenity
2019-12-11 05:29:31 -05:00
import (
2020-01-19 06:57:05 -05:00
"github.com/ncruces/zenity/internal/zenutil"
2019-12-11 05:29:31 -05:00
)
2021-03-04 07:42:30 -05:00
func selectFile(opts options) (string, error) {
2021-02-19 12:46:47 -05:00
var data zenutil.File
data.Options.Prompt = opts.title
data.Options.Invisibles = opts.showHidden
data.Options.Location, _ = splitDirAndName(opts.filename)
2020-01-09 20:46:53 -05:00
if opts.directory {
data.Operation = "chooseFolder"
} else {
data.Operation = "chooseFile"
2021-04-13 08:28:26 -04:00
data.Options.Type = opts.fileFilters.types()
2020-01-09 20:46:53 -05:00
}
2020-01-28 07:46:43 -05:00
out, err := zenutil.Run(opts.ctx, "file", data)
2021-04-29 11:05:28 -04:00
return strResult(opts, out, err)
2019-12-11 05:29:31 -05:00
}
2021-03-04 07:42:30 -05:00
func selectFileMutiple(opts options) ([]string, error) {
2021-02-19 12:46:47 -05:00
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
2020-01-09 20:46:53 -05:00
if opts.directory {
data.Operation = "chooseFolder"
} else {
data.Operation = "chooseFile"
2021-04-13 08:28:26 -04:00
data.Options.Type = opts.fileFilters.types()
2020-01-09 20:46:53 -05:00
}
2020-01-28 07:46:43 -05:00
out, err := zenutil.Run(opts.ctx, "file", data)
2021-04-08 11:43:14 -04:00
return lstResult(opts, out, err)
2019-12-11 05:29:31 -05:00
}
2021-03-04 07:42:30 -05:00
func selectFileSave(opts options) (string, error) {
2021-02-19 12:46:47 -05:00
var data zenutil.File
data.Options.Prompt = opts.title
data.Options.Invisibles = opts.showHidden
data.Options.Location, data.Options.Name = splitDirAndName(opts.filename)
2020-01-12 18:09:11 -05:00
if opts.directory {
data.Operation = "chooseFolder"
} else {
data.Operation = "chooseFileName"
2019-12-11 05:29:31 -05:00
}
2020-01-28 07:46:43 -05:00
out, err := zenutil.Run(opts.ctx, "file", data)
2021-04-29 11:05:28 -04:00
return strResult(opts, out, err)
2019-12-11 05:29:31 -05:00
}