Reshuffle.
This commit is contained in:
parent
79ade2cd7e
commit
4c753a3c39
9 changed files with 117 additions and 105 deletions
|
@ -36,17 +36,17 @@ var (
|
|||
title string
|
||||
width uint
|
||||
height uint
|
||||
okLabel string
|
||||
cancelLabel string
|
||||
extraButton string
|
||||
text string
|
||||
icon string
|
||||
|
||||
// Entry options
|
||||
entryText string
|
||||
hideText bool
|
||||
|
||||
// Message options
|
||||
icon string
|
||||
okLabel string
|
||||
cancelLabel string
|
||||
extraButton string
|
||||
noWrap bool
|
||||
ellipsize bool
|
||||
defaultCancel bool
|
||||
|
@ -136,10 +136,13 @@ func setupFlags() {
|
|||
|
||||
// General options
|
||||
flag.StringVar(&title, "title", "", "Set the dialog `title`")
|
||||
flag.StringVar(&icon, "window-icon", "", "Set the window `icon` (error, info, question, warning)")
|
||||
flag.UintVar(&width, "width", 0, "Set the `width`")
|
||||
flag.UintVar(&height, "height", 0, "Set the `height`")
|
||||
flag.StringVar(&okLabel, "ok-label", "", "Set the label of the OK button")
|
||||
flag.StringVar(&cancelLabel, "cancel-label", "", "Set the label of the Cancel button")
|
||||
flag.StringVar(&extraButton, "extra-button", "", "Add an extra button")
|
||||
flag.StringVar(&text, "text", "", "Set the dialog `text`")
|
||||
flag.StringVar(&icon, "window-icon", "", "Set the window `icon` (error, info, question, warning)")
|
||||
|
||||
// Entry options
|
||||
flag.StringVar(&entryText, "entry-text", "", "Set the entry `text`")
|
||||
|
@ -147,9 +150,6 @@ func setupFlags() {
|
|||
|
||||
// Message options
|
||||
flag.StringVar(&icon, "icon-name", "", "Set the dialog `icon` (dialog-error, dialog-information, dialog-question, dialog-warning)")
|
||||
flag.StringVar(&okLabel, "ok-label", "", "Set the label of the OK button")
|
||||
flag.StringVar(&cancelLabel, "cancel-label", "", "Set the label of the Cancel button")
|
||||
flag.StringVar(&extraButton, "extra-button", "", "Add an extra button")
|
||||
flag.BoolVar(&noWrap, "no-wrap", false, "Do not enable text wrapping")
|
||||
flag.BoolVar(&ellipsize, "ellipsize", false, "Enable ellipsizing in the dialog text")
|
||||
flag.BoolVar(&defaultCancel, "default-cancel", false, "Give Cancel button focus by default")
|
||||
|
@ -180,11 +180,11 @@ func setupFlags() {
|
|||
|
||||
// Detect unspecified values
|
||||
title = unspecified
|
||||
icon = unspecified
|
||||
text = unspecified
|
||||
okLabel = unspecified
|
||||
cancelLabel = unspecified
|
||||
extraButton = unspecified
|
||||
text = unspecified
|
||||
icon = unspecified
|
||||
}
|
||||
|
||||
func validateFlags() {
|
||||
|
@ -266,30 +266,6 @@ func loadFlags() []zenity.Option {
|
|||
}
|
||||
opts = append(opts, zenity.Width(width))
|
||||
opts = append(opts, zenity.Height(height))
|
||||
|
||||
// Entry options
|
||||
opts = append(opts, zenity.EntryText(entryText))
|
||||
if hideText {
|
||||
opts = append(opts, zenity.HideText())
|
||||
}
|
||||
|
||||
// Message options
|
||||
|
||||
var ico zenity.DialogIcon
|
||||
switch icon {
|
||||
case "":
|
||||
ico = zenity.NoIcon
|
||||
case "error", "dialog-error":
|
||||
ico = zenity.ErrorIcon
|
||||
case "info", "dialog-information":
|
||||
ico = zenity.InfoIcon
|
||||
case "question", "dialog-question":
|
||||
ico = zenity.QuestionIcon
|
||||
case "important", "warning", "dialog-warning":
|
||||
ico = zenity.WarningIcon
|
||||
}
|
||||
|
||||
opts = append(opts, zenity.Icon(ico))
|
||||
if okLabel != unspecified {
|
||||
opts = append(opts, zenity.OKLabel(okLabel))
|
||||
}
|
||||
|
@ -299,6 +275,33 @@ func loadFlags() []zenity.Option {
|
|||
if extraButton != unspecified {
|
||||
opts = append(opts, zenity.ExtraButton(extraButton))
|
||||
}
|
||||
|
||||
var ico zenity.DialogIcon
|
||||
switch icon {
|
||||
case "error", "dialog-error":
|
||||
ico = zenity.ErrorIcon
|
||||
case "info", "dialog-information":
|
||||
ico = zenity.InfoIcon
|
||||
case "question", "dialog-question":
|
||||
ico = zenity.QuestionIcon
|
||||
case "important", "warning", "dialog-warning":
|
||||
ico = zenity.WarningIcon
|
||||
case "dialog-password":
|
||||
ico = zenity.PasswordIcon
|
||||
case "":
|
||||
ico = zenity.NoIcon
|
||||
}
|
||||
opts = append(opts, zenity.Icon(ico))
|
||||
|
||||
// Entry options
|
||||
|
||||
opts = append(opts, zenity.EntryText(entryText))
|
||||
if hideText {
|
||||
opts = append(opts, zenity.HideText())
|
||||
}
|
||||
|
||||
// Message options
|
||||
|
||||
if noWrap {
|
||||
opts = append(opts, zenity.NoWrap())
|
||||
}
|
||||
|
@ -311,10 +314,6 @@ func loadFlags() []zenity.Option {
|
|||
|
||||
// File selection options
|
||||
|
||||
opts = append(opts, fileFilters)
|
||||
if filename != "" {
|
||||
opts = append(opts, zenity.Filename(ingestPath(filename)))
|
||||
}
|
||||
if directory {
|
||||
opts = append(opts, zenity.Directory())
|
||||
}
|
||||
|
@ -327,6 +326,10 @@ func loadFlags() []zenity.Option {
|
|||
if showHidden {
|
||||
opts = append(opts, zenity.ShowHidden())
|
||||
}
|
||||
if filename != "" {
|
||||
opts = append(opts, zenity.Filename(ingestPath(filename)))
|
||||
}
|
||||
opts = append(opts, fileFilters)
|
||||
|
||||
// Color selection options
|
||||
|
||||
|
|
3
entry.go
3
entry.go
|
@ -4,7 +4,8 @@ package zenity
|
|||
//
|
||||
// Returns nil on cancel.
|
||||
//
|
||||
// Valid options: Title, Text, EntryText, HideText.
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, EntryText, HideText.
|
||||
func Entry(text string, options ...Option) (string, error) {
|
||||
return entry(text, applyOptions(options))
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func entry(text string, opts options) (string, error) {
|
||||
args := []string{"--entry", "--text", text}
|
||||
args := []string{"--entry", "--text", text, "--entry-text", opts.entryText}
|
||||
if opts.title != nil {
|
||||
args = append(args, "--title", *opts.title)
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ func entry(text string, opts options) (string, error) {
|
|||
if opts.extraButton != nil {
|
||||
args = append(args, "--extra-button", *opts.extraButton)
|
||||
}
|
||||
if opts.hideText {
|
||||
args = append(args, "--hide-text")
|
||||
}
|
||||
switch opts.icon {
|
||||
case ErrorIcon:
|
||||
args = append(args, "--window-icon=error")
|
||||
|
|
18
file.go
18
file.go
|
@ -33,15 +33,6 @@ func SelectFileSave(options ...Option) (string, error) {
|
|||
return selectFileSave(applyOptions(options))
|
||||
}
|
||||
|
||||
// Filename returns an Option to set the filename.
|
||||
//
|
||||
// You can specify a file name, a directory path, or both.
|
||||
// Specifying a file name, makes it the default selected file.
|
||||
// Specifying a directory path, makes it the default dialog location.
|
||||
func Filename(filename string) Option {
|
||||
return funcOption(func(o *options) { o.filename = filename })
|
||||
}
|
||||
|
||||
// Directory returns an Option to activate directory-only selection.
|
||||
func Directory() Option {
|
||||
return funcOption(func(o *options) { o.directory = true })
|
||||
|
@ -64,6 +55,15 @@ func ShowHidden() Option {
|
|||
return funcOption(func(o *options) { o.showHidden = true })
|
||||
}
|
||||
|
||||
// Filename returns an Option to set the filename.
|
||||
//
|
||||
// You can specify a file name, a directory path, or both.
|
||||
// Specifying a file name, makes it the default selected file.
|
||||
// Specifying a directory path, makes it the default dialog location.
|
||||
func Filename(filename string) Option {
|
||||
return funcOption(func(o *options) { o.filename = filename })
|
||||
}
|
||||
|
||||
// FileFilter is an Option that sets a filename filter.
|
||||
//
|
||||
// macOS hides filename filters from the user,
|
||||
|
|
22
file_unix.go
22
file_unix.go
|
@ -11,12 +11,12 @@ import (
|
|||
|
||||
func selectFile(opts options) (string, error) {
|
||||
args := []string{"--file-selection"}
|
||||
if opts.directory {
|
||||
args = append(args, "--directory")
|
||||
}
|
||||
if opts.title != nil {
|
||||
args = append(args, "--title", *opts.title)
|
||||
}
|
||||
if opts.directory {
|
||||
args = append(args, "--directory")
|
||||
}
|
||||
if opts.filename != "" {
|
||||
args = append(args, "--filename", opts.filename)
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ func selectFile(opts options) (string, error) {
|
|||
|
||||
func selectFileMutiple(opts options) ([]string, error) {
|
||||
args := []string{"--file-selection", "--multiple", "--separator", zenutil.Separator}
|
||||
if opts.directory {
|
||||
args = append(args, "--directory")
|
||||
}
|
||||
if opts.title != nil {
|
||||
args = append(args, "--title", *opts.title)
|
||||
}
|
||||
if opts.directory {
|
||||
args = append(args, "--directory")
|
||||
}
|
||||
if opts.filename != "" {
|
||||
args = append(args, "--filename", opts.filename)
|
||||
}
|
||||
|
@ -63,18 +63,18 @@ func selectFileMutiple(opts options) ([]string, error) {
|
|||
|
||||
func selectFileSave(opts options) (string, error) {
|
||||
args := []string{"--file-selection", "--save"}
|
||||
if opts.directory {
|
||||
args = append(args, "--directory")
|
||||
}
|
||||
if opts.title != nil {
|
||||
args = append(args, "--title", *opts.title)
|
||||
}
|
||||
if opts.filename != "" {
|
||||
args = append(args, "--filename", opts.filename)
|
||||
if opts.directory {
|
||||
args = append(args, "--directory")
|
||||
}
|
||||
if opts.confirmOverwrite {
|
||||
args = append(args, "--confirm-overwrite")
|
||||
}
|
||||
if opts.filename != "" {
|
||||
args = append(args, "--filename", opts.filename)
|
||||
}
|
||||
args = append(args, initFilters(opts.fileFilters)...)
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, args)
|
||||
|
|
25
msg.go
25
msg.go
|
@ -8,8 +8,8 @@ const ErrExtraButton = stringErr("Extra button pressed")
|
|||
//
|
||||
// Returns true on OK, false on Cancel, or ErrExtraButton.
|
||||
//
|
||||
// Valid options: Title, Width, Height, Icon, OKLabel, CancelLabel,
|
||||
// ExtraButton, NoWrap, Ellipsize, DefaultCancel.
|
||||
// Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton,
|
||||
// Icon, NoWrap, Ellipsize, DefaultCancel.
|
||||
func Question(text string, options ...Option) (bool, error) {
|
||||
return message(questionKind, text, applyOptions(options))
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func Question(text string, options ...Option) (bool, error) {
|
|||
//
|
||||
// Returns true on OK, false on dismiss, or ErrExtraButton.
|
||||
//
|
||||
// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton,
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon,
|
||||
// NoWrap, Ellipsize.
|
||||
func Info(text string, options ...Option) (bool, error) {
|
||||
return message(infoKind, text, applyOptions(options))
|
||||
|
@ -28,7 +28,7 @@ func Info(text string, options ...Option) (bool, error) {
|
|||
//
|
||||
// Returns true on OK, false on dismiss, or ErrExtraButton.
|
||||
//
|
||||
// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton,
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon,
|
||||
// NoWrap, Ellipsize.
|
||||
func Warning(text string, options ...Option) (bool, error) {
|
||||
return message(warningKind, text, applyOptions(options))
|
||||
|
@ -38,7 +38,7 @@ func Warning(text string, options ...Option) (bool, error) {
|
|||
//
|
||||
// Returns true on OK, false on dismiss, or ErrExtraButton.
|
||||
//
|
||||
// Valid options: Title, Width, Height, Icon, OKLabel, ExtraButton,
|
||||
// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon,
|
||||
// NoWrap, Ellipsize.
|
||||
func Error(text string, options ...Option) (bool, error) {
|
||||
return message(errorKind, text, applyOptions(options))
|
||||
|
@ -53,21 +53,6 @@ const (
|
|||
errorKind
|
||||
)
|
||||
|
||||
// OKLabel returns an Option to set the label of the OK button.
|
||||
func OKLabel(ok string) Option {
|
||||
return funcOption(func(o *options) { o.okLabel = &ok })
|
||||
}
|
||||
|
||||
// CancelLabel returns an Option to set the label of the Cancel button.
|
||||
func CancelLabel(cancel string) Option {
|
||||
return funcOption(func(o *options) { o.cancelLabel = &cancel })
|
||||
}
|
||||
|
||||
// ExtraButton returns an Option to add an extra button.
|
||||
func ExtraButton(extra string) Option {
|
||||
return funcOption(func(o *options) { o.extraButton = &extra })
|
||||
}
|
||||
|
||||
// NoWrap returns an Option to disable enable text wrapping (Unix only).
|
||||
func NoWrap() Option {
|
||||
return funcOption(func(o *options) { o.noWrap = true })
|
||||
|
|
|
@ -49,8 +49,6 @@ func message(kind messageKind, text string, opts options) (bool, error) {
|
|||
args = append(args, "--default-cancel")
|
||||
}
|
||||
switch opts.icon {
|
||||
case NoIcon:
|
||||
args = append(args, "--icon-name=")
|
||||
case ErrorIcon:
|
||||
args = append(args, "--window-icon=error", "--icon-name=dialog-error")
|
||||
case WarningIcon:
|
||||
|
@ -59,6 +57,10 @@ func message(kind messageKind, text string, opts options) (bool, error) {
|
|||
args = append(args, "--window-icon=info", "--icon-name=dialog-information")
|
||||
case QuestionIcon:
|
||||
args = append(args, "--window-icon=question", "--icon-name=dialog-question")
|
||||
case PasswordIcon:
|
||||
args = append(args, "--icon-name=dialog-password")
|
||||
case NoIcon:
|
||||
args = append(args, "--icon-name=")
|
||||
}
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, args)
|
||||
|
|
|
@ -12,8 +12,6 @@ func notify(text string, opts options) error {
|
|||
args = append(args, "--title", *opts.title)
|
||||
}
|
||||
switch opts.icon {
|
||||
case NoIcon:
|
||||
args = append(args, "--window-icon=dialog")
|
||||
case ErrorIcon:
|
||||
args = append(args, "--window-icon=dialog-error")
|
||||
case WarningIcon:
|
||||
|
@ -22,6 +20,10 @@ func notify(text string, opts options) error {
|
|||
args = append(args, "--window-icon=dialog-information")
|
||||
case QuestionIcon:
|
||||
args = append(args, "--window-icon=dialog-question")
|
||||
case PasswordIcon:
|
||||
args = append(args, "--window-icon=dialog-password")
|
||||
case NoIcon:
|
||||
args = append(args, "--window-icon=dialog")
|
||||
}
|
||||
|
||||
_, err := zenutil.Run(opts.ctx, args)
|
||||
|
|
44
zenity.go
44
zenity.go
|
@ -26,32 +26,32 @@ type options struct {
|
|||
title *string
|
||||
width uint
|
||||
height uint
|
||||
okLabel *string
|
||||
cancelLabel *string
|
||||
extraButton *string
|
||||
icon DialogIcon
|
||||
|
||||
// Entry options
|
||||
entryText string
|
||||
hideText bool
|
||||
|
||||
// Message options
|
||||
noWrap bool
|
||||
ellipsize bool
|
||||
defaultCancel bool
|
||||
|
||||
// File selection options
|
||||
filename string
|
||||
directory bool
|
||||
confirmOverwrite bool
|
||||
confirmCreate bool
|
||||
showHidden bool
|
||||
filename string
|
||||
fileFilters []FileFilter
|
||||
|
||||
// Color selection options
|
||||
color color.Color
|
||||
showPalette bool
|
||||
|
||||
// Message options
|
||||
icon DialogIcon
|
||||
okLabel *string
|
||||
cancelLabel *string
|
||||
extraButton *string
|
||||
noWrap bool
|
||||
ellipsize bool
|
||||
defaultCancel bool
|
||||
|
||||
// Entry options
|
||||
entryText string
|
||||
hideText bool
|
||||
|
||||
// Context for timeout
|
||||
ctx context.Context
|
||||
}
|
||||
|
@ -92,6 +92,21 @@ func Height(height uint) Option {
|
|||
})
|
||||
}
|
||||
|
||||
// OKLabel returns an Option to set the label of the OK button.
|
||||
func OKLabel(ok string) Option {
|
||||
return funcOption(func(o *options) { o.okLabel = &ok })
|
||||
}
|
||||
|
||||
// CancelLabel returns an Option to set the label of the Cancel button.
|
||||
func CancelLabel(cancel string) Option {
|
||||
return funcOption(func(o *options) { o.cancelLabel = &cancel })
|
||||
}
|
||||
|
||||
// ExtraButton returns an Option to add an extra button.
|
||||
func ExtraButton(extra string) Option {
|
||||
return funcOption(func(o *options) { o.extraButton = &extra })
|
||||
}
|
||||
|
||||
// DialogIcon is the enumeration for dialog icons.
|
||||
type DialogIcon int
|
||||
|
||||
|
@ -101,6 +116,7 @@ const (
|
|||
WarningIcon
|
||||
InfoIcon
|
||||
QuestionIcon
|
||||
PasswordIcon
|
||||
NoIcon
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue