diff --git a/color.go b/color.go index b50b2b6..1f14542 100644 --- a/color.go +++ b/color.go @@ -4,7 +4,7 @@ import "image/color" // SelectColor displays the color selection dialog. // -// Valid options: Title, Color, ShowPalette. +// Valid options: Title, WindowIcon, Attach, Modal, Color, ShowPalette. // // May return: ErrCanceled. func SelectColor(options ...Option) (color.Color, error) { diff --git a/color_unix.go b/color_unix.go index f2ac465..264558b 100644 --- a/color_unix.go +++ b/color_unix.go @@ -11,7 +11,7 @@ import ( func selectColor(opts options) (color.Color, error) { args := []string{"--color-selection"} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) if opts.color != nil { args = append(args, "--color", zenutil.UnparseColor(opts.color)) } diff --git a/date.go b/date.go index 07b354f..04ca536 100644 --- a/date.go +++ b/date.go @@ -5,7 +5,7 @@ import "time" // Calendar displays the calendar dialog. // // Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton, -// Icon, DefaultDate. +// WindowIcon, Attach, Modal, DefaultDate. // // May return: ErrCanceled, ErrExtraButton. func Calendar(text string, options ...Option) (time.Time, error) { diff --git a/date_unix.go b/date_unix.go index de403ed..d6f490d 100644 --- a/date_unix.go +++ b/date_unix.go @@ -11,7 +11,7 @@ import ( func calendar(text string, opts options) (time.Time, error) { args := []string{"--calendar", "--text", text, "--date-format", zenutil.DateFormat} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) args = appendWidthHeight(args, opts) args = appendWindowIcon(args, opts) diff --git a/entry.go b/entry.go index 011567e..c8706e6 100644 --- a/entry.go +++ b/entry.go @@ -3,7 +3,7 @@ package zenity // Entry displays the text entry dialog. // // Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton, -// Icon, EntryText, HideText. +// WindowIcon, Attach, Modal, EntryText, HideText. // // May return: ErrCanceled, ErrExtraButton. func Entry(text string, options ...Option) (string, error) { diff --git a/entry_unix.go b/entry_unix.go index f6bab51..9444854 100644 --- a/entry_unix.go +++ b/entry_unix.go @@ -8,7 +8,7 @@ import ( func entry(text string, opts options) (string, error) { args := []string{"--entry", "--text", text} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) args = appendWidthHeight(args, opts) args = appendWindowIcon(args, opts) diff --git a/file.go b/file.go index 9f682d7..b2c8a32 100644 --- a/file.go +++ b/file.go @@ -8,7 +8,8 @@ import ( // SelectFile displays the file selection dialog. // -// Valid options: Title, Directory, Filename, ShowHidden, FileFilter(s). +// Valid options: Title, WindowIcon, Attach, Modal, Directory, Filename, +// ShowHidden, FileFilter(s). // // May return: ErrCanceled. func SelectFile(options ...Option) (string, error) { @@ -17,7 +18,8 @@ func SelectFile(options ...Option) (string, error) { // SelectFileMultiple displays the multiple file selection dialog. // -// Valid options: Title, Directory, Filename, ShowHidden, FileFilter(s). +// Valid options: Title, WindowIcon, Attach, Modal, Directory, Filename, +// ShowHidden, FileFilter(s). // // May return: ErrCanceled, ErrUnsupported. func SelectFileMultiple(options ...Option) ([]string, error) { @@ -31,8 +33,8 @@ func SelectFileMutiple(options ...Option) ([]string, error) { // SelectFileSave displays the save file selection dialog. // -// Valid options: Title, Filename, ConfirmOverwrite, ConfirmCreate, ShowHidden, -// FileFilter(s). +// Valid options: Title, WindowIcon, Attach, Modal, Filename, +// ConfirmOverwrite, ConfirmCreate, ShowHidden, FileFilter(s). // // May return: ErrCanceled. func SelectFileSave(options ...Option) (string, error) { diff --git a/file_unix.go b/file_unix.go index 077efa4..bef1872 100644 --- a/file_unix.go +++ b/file_unix.go @@ -10,7 +10,7 @@ import ( func selectFile(opts options) (string, error) { args := []string{"--file-selection"} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendFileArgs(args, opts) out, err := zenutil.Run(opts.ctx, args) @@ -19,7 +19,7 @@ func selectFile(opts options) (string, error) { func selectFileMultiple(opts options) ([]string, error) { args := []string{"--file-selection", "--multiple", "--separator", zenutil.Separator} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendFileArgs(args, opts) out, err := zenutil.Run(opts.ctx, args) @@ -28,7 +28,7 @@ func selectFileMultiple(opts options) ([]string, error) { func selectFileSave(opts options) (string, error) { args := []string{"--file-selection", "--save"} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendFileArgs(args, opts) out, err := zenutil.Run(opts.ctx, args) diff --git a/list.go b/list.go index 1e72a90..a2d14c8 100644 --- a/list.go +++ b/list.go @@ -3,7 +3,7 @@ package zenity // List displays the list dialog. // // Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton, -// Icon, DefaultItems, DisallowEmpty. +// WindowIcon, Attach, Modal, DefaultItems, DisallowEmpty. // // May return: ErrCanceled, ErrExtraButton, ErrUnsupported. func List(text string, items []string, options ...Option) (string, error) { @@ -20,7 +20,7 @@ func ListItems(text string, items ...string) (string, error) { // ListMultiple displays the list dialog, allowing multiple items to be selected. // // Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton, -// Icon, DefaultItems, DisallowEmpty. +// WindowIcon, Attach, Modal, DefaultItems, DisallowEmpty. // // May return: ErrCanceled, ErrExtraButton, ErrUnsupported. func ListMultiple(text string, items []string, options ...Option) ([]string, error) { diff --git a/list_unix.go b/list_unix.go index 3476bd1..7a7e0ae 100644 --- a/list_unix.go +++ b/list_unix.go @@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil" func list(text string, items []string, opts options) (string, error) { args := []string{"--list", "--column=", "--hide-header", "--text", text} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) args = appendWidthHeight(args, opts) args = appendWindowIcon(args, opts) @@ -18,7 +18,7 @@ func list(text string, items []string, opts options) (string, error) { func listMultiple(text string, items []string, opts options) ([]string, error) { args := []string{"--list", "--column=", "--hide-header", "--text", text, "--multiple", "--separator", zenutil.Separator} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) args = appendWidthHeight(args, opts) args = appendWindowIcon(args, opts) diff --git a/msg.go b/msg.go index 592e217..1e01afd 100644 --- a/msg.go +++ b/msg.go @@ -3,7 +3,7 @@ package zenity // Question displays the question dialog. // // Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton, -// Icon, NoWrap, Ellipsize, DefaultCancel. +// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize, DefaultCancel. // // May return: ErrCanceled, ErrExtraButton. func Question(text string, options ...Option) error { @@ -12,8 +12,8 @@ func Question(text string, options ...Option) error { // Info displays the info dialog. // -// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon, -// NoWrap, Ellipsize. +// Valid options: Title, Width, Height, OKLabel, ExtraButton, +// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize. // // May return: ErrCanceled, ErrExtraButton. func Info(text string, options ...Option) error { @@ -22,8 +22,8 @@ func Info(text string, options ...Option) error { // Warning displays the warning dialog. // -// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon, -// NoWrap, Ellipsize. +// Valid options: Title, Width, Height, OKLabel, ExtraButton, +// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize. // // May return: ErrCanceled, ErrExtraButton. func Warning(text string, options ...Option) error { @@ -32,8 +32,8 @@ func Warning(text string, options ...Option) error { // Error displays the error dialog. // -// Valid options: Title, Width, Height, OKLabel, ExtraButton, Icon, -// NoWrap, Ellipsize. +// Valid options: Title, Width, Height, OKLabel, ExtraButton, +// Icon, WindowIcon, Attach, Modal, NoWrap, Ellipsize. // // May return: ErrCanceled, ErrExtraButton. func Error(text string, options ...Option) error { diff --git a/msg_unix.go b/msg_unix.go index eb86aaf..c99dc8f 100644 --- a/msg_unix.go +++ b/msg_unix.go @@ -16,7 +16,7 @@ func message(kind messageKind, text string, opts options) error { case errorKind: args = append(args, "--error") } - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) args = appendWidthHeight(args, opts) args = appendWindowIcon(args, opts) diff --git a/notify_unix.go b/notify_unix.go index c31c095..9c3c979 100644 --- a/notify_unix.go +++ b/notify_unix.go @@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil" func notify(text string, opts options) error { args := []string{"--notification", "--text", text} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) switch opts.icon { case ErrorIcon: args = append(args, "--window-icon=dialog-error") diff --git a/progress.go b/progress.go index 623ca2c..bf03ce9 100644 --- a/progress.go +++ b/progress.go @@ -3,7 +3,7 @@ package zenity // Progress displays the progress indication dialog. // // Valid options: Title, Width, Height, OKLabel, CancelLabel, ExtraButton, -// Icon, MaxValue, Pulsate, NoCancel, TimeRemaining. +// Icon, WindowIcon, Attach, Modal, MaxValue, Pulsate, NoCancel, TimeRemaining. // // May return: ErrUnsupported. func Progress(options ...Option) (ProgressDialog, error) { diff --git a/progress_unix.go b/progress_unix.go index 4451002..7c9f74f 100644 --- a/progress_unix.go +++ b/progress_unix.go @@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil" func progress(opts options) (ProgressDialog, error) { args := []string{"--progress"} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) args = appendWidthHeight(args, opts) args = appendWindowIcon(args, opts) diff --git a/pwd.go b/pwd.go index 3992478..9d7216c 100644 --- a/pwd.go +++ b/pwd.go @@ -2,7 +2,8 @@ package zenity // Password displays the password dialog. // -// Valid options: Title, OKLabel, CancelLabel, ExtraButton, Icon, Username. +// Valid options: Title, OKLabel, CancelLabel, ExtraButton, +// WindowIcon, Attach, Modal, Username. // // May return: ErrCanceled, ErrExtraButton. func Password(options ...Option) (usr string, pwd string, err error) { diff --git a/pwd_unix.go b/pwd_unix.go index c720459..aacb6c4 100644 --- a/pwd_unix.go +++ b/pwd_unix.go @@ -6,7 +6,7 @@ import "github.com/ncruces/zenity/internal/zenutil" func password(opts options) (string, string, error) { args := []string{"--password"} - args = appendTitle(args, opts) + args = appendGeneral(args, opts) args = appendButtons(args, opts) if opts.username { args = append(args, "--username") diff --git a/util_unix.go b/util_unix.go index ca66265..fe6c168 100644 --- a/util_unix.go +++ b/util_unix.go @@ -4,6 +4,7 @@ package zenity import ( "bytes" + "fmt" "os/exec" "strconv" "strings" @@ -11,10 +12,16 @@ import ( "github.com/ncruces/zenity/internal/zenutil" ) -func appendTitle(args []string, opts options) []string { +func appendGeneral(args []string, opts options) []string { if opts.title != nil { args = append(args, "--title", *opts.title) } + if opts.attach != nil { + args = append(args, "--attach", fmt.Sprint(opts.attach)) + } + if opts.modal { + args = append(args, "--modal") + } return args } diff --git a/util_unix_test.go b/util_unix_test.go index 44c3a23..1aa65d2 100644 --- a/util_unix_test.go +++ b/util_unix_test.go @@ -11,9 +11,13 @@ import ( "github.com/ncruces/zenity/internal/zenutil" ) -func Test_appendTitle(t *testing.T) { - got := appendTitle(nil, options{title: stringPtr("Title")}) - want := []string{"--title", "Title"} +func Test_appendGeneral(t *testing.T) { + got := appendGeneral(nil, options{ + title: stringPtr("Title"), + attach: 12345, + modal: true, + }) + want := []string{"--title", "Title", "--attach", "12345", "--modal"} if !reflect.DeepEqual(got, want) { t.Errorf("appendTitle() = %v; want %v", got, want) } diff --git a/zenity.go b/zenity.go index 98518e1..7b4e6bf 100644 --- a/zenity.go +++ b/zenity.go @@ -44,6 +44,8 @@ type options struct { defaultCancel bool icon any windowIcon any + attach any + modal bool // Message options noWrap bool @@ -169,7 +171,7 @@ func Icon(icon any) Option { return funcOption(func(o *options) { o.icon = icon }) } -// WindowIcon returns an Option to set the dialog icon (macOS and Unix only). +// WindowIcon returns an Option to set the window icon. // // WindowIcon accepts a DialogIcon, or a string path. func WindowIcon(icon any) Option { @@ -182,13 +184,23 @@ func WindowIcon(icon any) Option { return funcOption(func(o *options) { o.windowIcon = icon }) } -// CustomIcon returns an Option to set a custom dialog icon, loaded from a file. +// CustomIcon returns an Option to set a custom dialog icon. // // Deprecated: use Icon instead. func CustomIcon(path string) Option { return Icon(path) } +// Attach returns an Option to set the parent window to attach to. +func Attach(id any) Option { + return funcOption(func(o *options) { o.attach = id }) +} + +// Modal returns an Option to set the modal hint. +func Modal() Option { + return funcOption(func(o *options) { o.modal = true }) +} + // Context returns an Option to set a Context that can dismiss the dialog. // // Dialogs dismissed by ctx return ctx.Err(). diff --git a/zenity_test.go b/zenity_test.go index 4406205..629e27d 100644 --- a/zenity_test.go +++ b/zenity_test.go @@ -27,6 +27,9 @@ func Test_applyOptions(t *testing.T) { {name: "WindowIcon", args: WindowIcon("error"), want: options{windowIcon: "error"}}, {name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}}, {name: "Icon", args: Icon("error"), want: options{icon: "error"}}, + {name: "Attach", args: Attach(12345), want: options{attach: 12345}}, + {name: "Attach", args: Attach("Terminal"), want: options{attach: "Terminal"}}, + {name: "Modal", args: Modal(), want: options{modal: true}}, // Message options {name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},