zenity/file_darwin.go

96 lines
2.3 KiB
Go
Raw Permalink Normal View History

2019-12-29 20:00:50 -05:00
package zenity
2019-12-11 05:29:31 -05:00
2023-04-12 07:52:10 -04:00
import (
"path/filepath"
2024-07-10 00:06:01 -04:00
"git.bigun.dev/evan/zenity/internal/zenutil"
2023-04-12 07:52:10 -04:00
)
2019-12-11 05:29:31 -05:00
2023-04-12 06:22:30 -04:00
func selectFile(opts options) (name string, err error) {
2021-02-19 12:46:47 -05:00
var data zenutil.File
data.Options.Prompt = opts.title
data.Options.Invisibles = opts.showHidden
2023-04-12 06:22:30 -04:00
data.Options.Location, _, err = splitDirAndName(opts.filename)
2023-04-12 07:52:10 -04:00
if data.Options.Location != "" && err == nil {
data.Options.Location, err = filepath.Abs(data.Options.Location)
}
2023-04-12 06:22:30 -04:00
if err != nil {
return "", err
}
2022-06-02 07:49:31 -04:00
if opts.attach != nil {
data.Application = opts.attach
2022-06-08 18:52:44 -04:00
}
if i, ok := opts.windowIcon.(string); ok {
2022-06-01 19:00:08 -04:00
data.WindowIcon = i
}
2021-02-19 12:46:47 -05:00
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
}
2023-04-12 06:22:30 -04:00
func selectFileMultiple(opts options) (list []string, err error) {
2021-02-19 12:46:47 -05:00
var data zenutil.File
2023-04-12 06:22:30 -04:00
data.Separator = zenutil.Separator
data.Options.Multiple = true
2021-02-19 12:46:47 -05:00
data.Options.Prompt = opts.title
data.Options.Invisibles = opts.showHidden
2023-04-12 06:22:30 -04:00
data.Options.Location, _, err = splitDirAndName(opts.filename)
2023-04-12 07:52:10 -04:00
if data.Options.Location != "" && err == nil {
data.Options.Location, err = filepath.Abs(data.Options.Location)
}
2023-04-12 06:22:30 -04:00
if err != nil {
return nil, err
}
2022-06-02 07:49:31 -04:00
if opts.attach != nil {
data.Application = opts.attach
2022-06-08 18:52:44 -04:00
}
if i, ok := opts.windowIcon.(string); ok {
2022-06-01 19:00:08 -04:00
data.WindowIcon = i
}
2021-02-19 12:46:47 -05:00
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
}
2023-04-12 06:22:30 -04:00
func selectFileSave(opts options) (name string, err error) {
2021-02-19 12:46:47 -05:00
var data zenutil.File
data.Options.Prompt = opts.title
data.Options.Invisibles = opts.showHidden
2023-04-12 06:22:30 -04:00
data.Options.Location, data.Options.Name, err = splitDirAndName(opts.filename)
2023-04-12 07:52:10 -04:00
if data.Options.Location != "" && err == nil {
data.Options.Location, err = filepath.Abs(data.Options.Location)
}
2023-04-12 06:22:30 -04:00
if err != nil {
return "", err
}
2022-06-02 07:49:31 -04:00
if opts.attach != nil {
data.Application = opts.attach
2022-06-08 18:52:44 -04:00
}
if i, ok := opts.windowIcon.(string); ok {
2022-06-01 19:00:08 -04:00
data.WindowIcon = i
}
2021-02-19 12:46:47 -05:00
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
}