Calendar (macos).
This commit is contained in:
parent
ff30098813
commit
d239bcb824
5 changed files with 97 additions and 5 deletions
28
date_darwin.go
Normal file
28
date_darwin.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package zenity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ncruces/zenity/internal/zenutil"
|
||||
)
|
||||
|
||||
func calendar(text string, opts options) (time.Time, error) {
|
||||
var date zenutil.Date
|
||||
|
||||
date.Date = time.Now().Unix()
|
||||
date.Format = "yyyy-MM-dd"
|
||||
|
||||
if opts.title != nil {
|
||||
date.Text = *opts.title
|
||||
date.Info = text
|
||||
} else {
|
||||
date.Text = text
|
||||
}
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, "date", date)
|
||||
str, err := strResult(opts, out, err)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.Parse("2006-01-02", str)
|
||||
}
|
10
date_unix.go
10
date_unix.go
|
@ -1,4 +1,4 @@
|
|||
// +build !windows,!darwin
|
||||
//go:build !windows && !darwin
|
||||
|
||||
package zenity
|
||||
|
||||
|
@ -26,9 +26,9 @@ func calendar(text string, opts options) (time.Time, error) {
|
|||
}
|
||||
|
||||
out, err := zenutil.Run(opts.ctx, args)
|
||||
str, ok, err := strResult(opts, out, err)
|
||||
if ok {
|
||||
return time.Parse("2006-01-02", str)
|
||||
str, err := strResult(opts, out, err)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.Time{}, err
|
||||
return time.Parse("2006-01-02", str)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,30 @@ app.activate()
|
|||
var res=app.chooseColor({defaultColor:{{json .}}})
|
||||
{'rgb('+res.map(x=>Math.round(x*255))+')'}
|
||||
{{- end}}
|
||||
{{define "date" -}}
|
||||
var app=Application.currentApplication()
|
||||
app.includeStandardAdditions=true
|
||||
app.activate()
|
||||
ObjC.import('Cocoa')
|
||||
ObjC.import('stdio')
|
||||
ObjC.import('stdlib')
|
||||
var date=$.NSDatePicker.alloc.init
|
||||
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
||||
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
||||
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
|
||||
date.setFrameSize(date.fittingSize)
|
||||
var alert=$.NSAlert.alloc.init
|
||||
alert.setAccessoryView(date)
|
||||
alert.setMessageText({{json .Text}})
|
||||
{{- if .Info}}alert.setInformativeText({{json .Info}}){{- end}}
|
||||
{{- range .Buttons}}alert.addButtonWithTitle([{{json .}}]){{end}}
|
||||
var res=alert.runModal
|
||||
switch(res){case $.NSAlertThirdButtonReturn:$.puts({{json .Buttons}}[2])
|
||||
case $.NSAlertSecondButtonReturn:$.exit(1)}
|
||||
var fmt=$.NSDateFormatter.alloc.init
|
||||
fmt.dateFormat={{json .Format}}
|
||||
fmt.stringFromDate(date.dateValue)
|
||||
{{- end}}
|
||||
{{define "dialog" -}}
|
||||
var app=Application.currentApplication()
|
||||
app.includeStandardAdditions=true
|
||||
|
|
31
internal/zenutil/osascripts/date.gojs
Normal file
31
internal/zenutil/osascripts/date.gojs
Normal file
|
@ -0,0 +1,31 @@
|
|||
var app = Application.currentApplication()
|
||||
app.includeStandardAdditions = true
|
||||
app.activate()
|
||||
|
||||
ObjC.import('Cocoa')
|
||||
ObjC.import('stdio')
|
||||
ObjC.import('stdlib')
|
||||
|
||||
var date = $.NSDatePicker.alloc.init
|
||||
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
|
||||
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
|
||||
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
|
||||
date.setFrameSize(date.fittingSize)
|
||||
|
||||
var alert = $.NSAlert.alloc.init
|
||||
alert.setAccessoryView(date)
|
||||
alert.setMessageText({{json .Text}})
|
||||
{{- if .Info}}alert.setInformativeText({{json .Info}}){{- end}}
|
||||
{{- range .Buttons}}alert.addButtonWithTitle([{{json .}}]){{end}}
|
||||
|
||||
var res = alert.runModal
|
||||
switch (res) {
|
||||
case $.NSAlertThirdButtonReturn:
|
||||
$.puts({{json .Buttons}}[2])
|
||||
case $.NSAlertSecondButtonReturn:
|
||||
$.exit(1)
|
||||
}
|
||||
|
||||
var fmt = $.NSDateFormatter.alloc.init
|
||||
fmt.dateFormat = {{json .Format}}
|
||||
fmt.stringFromDate(date.dateValue)
|
|
@ -216,3 +216,12 @@ type Progress struct {
|
|||
Description *string
|
||||
Total *int
|
||||
}
|
||||
|
||||
// Date is internal.
|
||||
type Date struct {
|
||||
Date int64
|
||||
Text string
|
||||
Info string
|
||||
Format string
|
||||
Buttons []string
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue