zenity/list_darwin.go

61 lines
1.6 KiB
Go
Raw Permalink Normal View History

2021-04-07 09:16:35 -04:00
package zenity
import (
2022-05-03 09:20:22 -04:00
"fmt"
2024-07-10 00:06:01 -04:00
"git.bigun.dev/evan/zenity/internal/zenutil"
2021-04-07 09:16:35 -04:00
)
2021-04-29 11:05:28 -04:00
func list(text string, items []string, opts options) (string, error) {
2022-05-03 09:20:22 -04:00
if len(items) == 0 {
return "", fmt.Errorf("%w: empty items list", ErrUnsupported)
}
if opts.extraButton != nil {
return "", fmt.Errorf("%w: extra button", ErrUnsupported)
2021-04-30 14:19:14 -04:00
}
2022-07-27 19:11:12 -04:00
if len(opts.defaultItems) > 1 {
return "", fmt.Errorf("%w: multiple default items", ErrUnsupported)
}
2021-04-30 14:19:14 -04:00
2021-04-07 09:16:35 -04:00
var data zenutil.List
data.Items = items
data.Options.Prompt = &text
data.Options.Title = opts.title
data.Options.OK = opts.okLabel
data.Options.Cancel = opts.cancelLabel
data.Options.Default = opts.defaultItems
data.Options.Empty = !opts.disallowEmpty
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-04-07 09:16:35 -04:00
out, err := zenutil.Run(opts.ctx, "list", data)
2021-04-08 11:43:14 -04:00
return strResult(opts, out, err)
2021-04-07 09:16:35 -04:00
}
func listMultiple(text string, items []string, opts options) ([]string, error) {
2022-05-03 09:20:22 -04:00
if len(items) == 0 {
return nil, fmt.Errorf("%w: empty items list", ErrUnsupported)
}
if opts.extraButton != nil {
return nil, fmt.Errorf("%w: extra button", ErrUnsupported)
2021-04-30 14:19:14 -04:00
}
2021-04-07 09:16:35 -04:00
var data zenutil.List
data.Items = items
data.Options.Prompt = &text
data.Options.Title = opts.title
data.Options.OK = opts.okLabel
data.Options.Cancel = opts.cancelLabel
data.Options.Default = opts.defaultItems
data.Options.Empty = !opts.disallowEmpty
data.Options.Multiple = true
data.Separator = zenutil.Separator
out, err := zenutil.Run(opts.ctx, "list", data)
2021-04-08 11:43:14 -04:00
return lstResult(opts, out, err)
2021-04-07 09:16:35 -04:00
}