zenity/internal/zenutil/osascripts/date.gojs
2022-05-17 15:36:40 +01:00

38 lines
No EOL
1 KiB
Text

ObjC.import('Cocoa')
ObjC.import('stdio')
ObjC.import('stdlib')
var date = $.NSDatePicker.alloc.init
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
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)
alert.setMessageText({{json .Text}})
alert.addButtonWithTitle({{json .OK}})
alert.addButtonWithTitle({{json .Cancel}}).keyEquivalent = '\033'
{{- if .Info}}
alert.setInformativeText({{json .Info}})
{{- end}}
{{- if .Extra}}
alert.addButtonWithTitle({{json .Extra}})
{{- end}}
var res = alert.runModal
switch (res) {
case $.NSAlertThirdButtonReturn:
$.puts({{json .Extra}})
case $.NSAlertSecondButtonReturn:
$.exit(1)
}
var fmt = $.NSDateFormatter.alloc.init
fmt.locale = $.NSLocale.localeWithLocaleIdentifier('en_US_POSIX')
fmt.dateFormat = {{json .Format}}
fmt.stringFromDate(date.dateValue)