Fix default date on macOS.
This commit is contained in:
parent
ece0ced937
commit
0b2f5d218d
7 changed files with 26 additions and 17 deletions
|
@ -397,6 +397,9 @@ func loadFlags() []zenity.Option {
|
|||
if extraButton != unspecified {
|
||||
opts = append(opts, zenity.ExtraButton(extraButton))
|
||||
}
|
||||
if defaultCancel {
|
||||
opts = append(opts, zenity.DefaultCancel())
|
||||
}
|
||||
|
||||
var ico zenity.DialogIcon
|
||||
switch icon {
|
||||
|
@ -429,9 +432,6 @@ func loadFlags() []zenity.Option {
|
|||
if ellipsize {
|
||||
opts = append(opts, zenity.Ellipsize())
|
||||
}
|
||||
if defaultCancel {
|
||||
opts = append(opts, zenity.DefaultCancel())
|
||||
}
|
||||
|
||||
// Entry options
|
||||
|
||||
|
|
|
@ -55,9 +55,9 @@ func TestCalendar_script(t *testing.T) {
|
|||
err error
|
||||
}{
|
||||
{name: "Cancel", call: "cancel", err: zenity.ErrCanceled},
|
||||
{name: "Black", call: "choose today", want: time.Now()},
|
||||
{name: "Rebecca", call: "press OK", want: time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local),
|
||||
opts: []zenity.Option{zenity.DefaultDate(2000, 1, 1)}},
|
||||
{name: "Today", call: "choose today", want: time.Now()},
|
||||
{name: "Default", call: "press OK", want: time.Date(2006, 1, 1, 0, 0, 0, 0, time.Local),
|
||||
opts: []zenity.Option{zenity.DefaultDate(2006, 1, 1)}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -33,6 +33,8 @@ date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
|||
date.setFrameSize(date.fittingSize)
|
||||
{{- if .Date}}
|
||||
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
|
||||
{{- else}}
|
||||
date.setDateValue($.NSDate.date)
|
||||
{{- end}}
|
||||
var alert=$.NSAlert.alloc.init
|
||||
alert.setAccessoryView(date)
|
||||
|
|
|
@ -8,6 +8,8 @@ date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
|||
date.setFrameSize(date.fittingSize)
|
||||
{{- if .Date}}
|
||||
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
|
||||
{{- else}}
|
||||
date.setDateValue($.NSDate.date)
|
||||
{{- end}}
|
||||
|
||||
var alert = $.NSAlert.alloc.init
|
||||
|
|
5
msg.go
5
msg.go
|
@ -58,8 +58,3 @@ func NoWrap() Option {
|
|||
func Ellipsize() Option {
|
||||
return funcOption(func(o *options) { o.ellipsize = true })
|
||||
}
|
||||
|
||||
// DefaultCancel returns an Option to give the Cancel button focus by default.
|
||||
func DefaultCancel() Option {
|
||||
return funcOption(func(o *options) { o.defaultCancel = true })
|
||||
}
|
||||
|
|
|
@ -130,6 +130,11 @@ func ExtraButton(extra string) Option {
|
|||
return funcOption(func(o *options) { o.extraButton = &extra })
|
||||
}
|
||||
|
||||
// DefaultCancel returns an Option to give the Cancel button focus by default.
|
||||
func DefaultCancel() Option {
|
||||
return funcOption(func(o *options) { o.defaultCancel = true })
|
||||
}
|
||||
|
||||
// DialogIcon is an Option that sets the dialog icon.
|
||||
type DialogIcon int
|
||||
|
||||
|
@ -154,7 +159,7 @@ const (
|
|||
// Tip: use DialogIcon directly.
|
||||
func Icon(icon DialogIcon) Option { return icon }
|
||||
|
||||
// Icon returns an Option to set a custom dialog icon, loaded from a file.
|
||||
// CustomIcon returns an Option to set a custom dialog icon, loaded from a file.
|
||||
func CustomIcon(path string) Option {
|
||||
return funcOption(func(o *options) {
|
||||
o.icon = unspecifiedIcon
|
||||
|
|
|
@ -5,9 +5,11 @@ import (
|
|||
"image/color"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_applyOptions(t *testing.T) {
|
||||
date := time.Date(2006, 1, 1, 0, 0, 0, 0, time.Local)
|
||||
tests := []struct {
|
||||
name string
|
||||
args Option
|
||||
|
@ -20,8 +22,8 @@ func Test_applyOptions(t *testing.T) {
|
|||
{name: "OKLabel", args: OKLabel("OK"), want: options{okLabel: stringPtr("OK")}},
|
||||
{name: "CancelLabel", args: CancelLabel("Cancel"), want: options{cancelLabel: stringPtr("Cancel")}},
|
||||
{name: "ExtraButton", args: ExtraButton("Extra"), want: options{extraButton: stringPtr("Extra")}},
|
||||
{name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}},
|
||||
{name: "DefaultCancel", args: DefaultCancel(), want: options{defaultCancel: true}},
|
||||
{name: "Icon", args: Icon(ErrorIcon), want: options{icon: ErrorIcon}},
|
||||
|
||||
// Message options
|
||||
{name: "NoWrap", args: NoWrap(), want: options{noWrap: true}},
|
||||
|
@ -36,6 +38,9 @@ func Test_applyOptions(t *testing.T) {
|
|||
{name: "DisallowEmpty", args: DisallowEmpty(), want: options{disallowEmpty: true}},
|
||||
{name: "DefaultItems", args: DefaultItems("a", "b"), want: options{defaultItems: []string{"a", "b"}}},
|
||||
|
||||
// Calendar options
|
||||
{name: "DefaultDate", args: DefaultDate(2006, time.January, 1), want: options{time: &date}},
|
||||
|
||||
// File selection options
|
||||
{name: "Directory", args: Directory(), want: options{directory: true}},
|
||||
{name: "ConfirmOverwrite", args: ConfirmOverwrite(), want: options{confirmOverwrite: true}},
|
||||
|
@ -49,16 +54,16 @@ func Test_applyOptions(t *testing.T) {
|
|||
fileFilters: FileFilters{{"Go files", []string{"*.go"}}},
|
||||
}},
|
||||
|
||||
// Color selection options
|
||||
{name: "Color", args: Color(color.Black), want: options{color: color.Black}},
|
||||
{name: "ShowPalette", args: ShowPalette(), want: options{showPalette: true}},
|
||||
|
||||
// Progress indication options
|
||||
{name: "MaxValue", args: MaxValue(100), want: options{maxValue: 100}},
|
||||
{name: "Pulsate", args: Pulsate(), want: options{maxValue: -1}},
|
||||
{name: "NoCancel", args: NoCancel(), want: options{noCancel: true}},
|
||||
{name: "TimeRemaining", args: TimeRemaining(), want: options{timeRemaining: true}},
|
||||
|
||||
// Color selection options
|
||||
{name: "Color", args: Color(color.Black), want: options{color: color.Black}},
|
||||
{name: "ShowPalette", args: ShowPalette(), want: options{showPalette: true}},
|
||||
|
||||
// Context for timeout
|
||||
{name: "Context", args: Context(context.TODO()), want: options{ctx: context.TODO()}},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue