2021-04-07 09:16:35 -04:00
|
|
|
package zenity
|
|
|
|
|
|
|
|
// List displays the list dialog.
|
|
|
|
//
|
|
|
|
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
2022-07-28 20:16:15 -04:00
|
|
|
// WindowIcon, Attach, Modal, RadioList, DefaultItems, DisallowEmpty.
|
2022-03-25 20:58:27 -04:00
|
|
|
//
|
|
|
|
// May return: ErrCanceled, ErrExtraButton, ErrUnsupported.
|
2021-04-29 11:05:28 -04:00
|
|
|
func List(text string, items []string, options ...Option) (string, error) {
|
2021-04-07 09:16:35 -04:00
|
|
|
return list(text, items, applyOptions(options))
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListItems displays the list dialog.
|
2022-03-25 20:58:27 -04:00
|
|
|
//
|
2022-05-03 09:20:22 -04:00
|
|
|
// May return: ErrCanceled, ErrUnsupported.
|
2021-04-29 11:05:28 -04:00
|
|
|
func ListItems(text string, items ...string) (string, error) {
|
2021-04-07 09:16:35 -04:00
|
|
|
return List(text, items)
|
|
|
|
}
|
|
|
|
|
2021-04-08 11:43:14 -04:00
|
|
|
// ListMultiple displays the list dialog, allowing multiple items to be selected.
|
2021-04-07 09:16:35 -04:00
|
|
|
//
|
|
|
|
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
2022-07-28 20:16:15 -04:00
|
|
|
// WindowIcon, Attach, Modal, CheckList, DefaultItems, DisallowEmpty.
|
2022-03-25 20:58:27 -04:00
|
|
|
//
|
|
|
|
// May return: ErrCanceled, ErrExtraButton, ErrUnsupported.
|
2021-04-07 09:16:35 -04:00
|
|
|
func ListMultiple(text string, items []string, options ...Option) ([]string, error) {
|
|
|
|
return listMultiple(text, items, applyOptions(options))
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:28:17 -04:00
|
|
|
// ListMultipleItems displays the list dialog, allowing multiple items to be selected.
|
2022-03-25 20:58:27 -04:00
|
|
|
//
|
2022-05-03 09:20:22 -04:00
|
|
|
// May return: ErrCanceled, ErrUnsupported.
|
2021-04-07 09:16:35 -04:00
|
|
|
func ListMultipleItems(text string, items ...string) ([]string, error) {
|
2022-12-07 09:35:37 -05:00
|
|
|
return ListMultiple(text, items, CheckList())
|
2021-04-07 09:16:35 -04:00
|
|
|
}
|
|
|
|
|
2022-07-28 20:16:15 -04:00
|
|
|
// CheckList returns an Option to show check boxes (Unix only).
|
|
|
|
func CheckList() Option {
|
|
|
|
return funcOption(func(o *options) { o.listKind = checkListKind })
|
|
|
|
}
|
|
|
|
|
|
|
|
// RadioList returns an Option to show radio boxes (Unix only).
|
|
|
|
func RadioList() Option {
|
|
|
|
return funcOption(func(o *options) { o.listKind = radioListKind })
|
|
|
|
}
|
|
|
|
|
|
|
|
type listKind int
|
|
|
|
|
|
|
|
const (
|
|
|
|
basicListKind listKind = iota
|
|
|
|
checkListKind
|
|
|
|
radioListKind
|
|
|
|
)
|
|
|
|
|
2022-12-05 06:16:59 -05:00
|
|
|
// DefaultItems returns an Option to set the items to initially select (Windows and macOS only).
|
2021-04-07 09:16:35 -04:00
|
|
|
func DefaultItems(items ...string) Option {
|
|
|
|
return funcOption(func(o *options) { o.defaultItems = items })
|
|
|
|
}
|
|
|
|
|
2022-12-05 08:24:58 -05:00
|
|
|
// DisallowEmpty returns an Option to not allow zero items to be selected (Windows and macOS only).
|
2021-04-07 09:16:35 -04:00
|
|
|
func DisallowEmpty() Option {
|
|
|
|
return funcOption(func(o *options) { o.disallowEmpty = true })
|
|
|
|
}
|