From 5533b77ca0ac0d3f22affb8aa28a61b334e75272 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 5 Dec 2022 13:24:58 +0000 Subject: [PATCH 1/4] List DisallowEmpty (windows). --- cmd/zenity/main.go | 12 ++++++------ internal/win/user32.go | 1 + list.go | 2 +- list_windows.go | 32 +++++++++++++++++++++++++------- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/cmd/zenity/main.go b/cmd/zenity/main.go index e3a73ca..994dd99 100644 --- a/cmd/zenity/main.go +++ b/cmd/zenity/main.go @@ -70,10 +70,10 @@ var ( username bool // List options - columns int - checklist bool - radiolist bool - allowEmpty bool + columns int + checklist bool + radiolist bool + disallowEmpty bool // Calendar options year uint @@ -242,7 +242,7 @@ func parseFlags() []string { fset.Bool("hide-header", true, "Hide the column headers") fset.BoolVar(&checklist, "checklist", false, "Use check boxes for the first column (Unix only)") fset.BoolVar(&radiolist, "radiolist", false, "Use radio buttons for the first column (Unix only)") - fset.BoolVar(&allowEmpty, "allow-empty", true, "Allow empty selection (macOS only)") + fset.BoolVar(&disallowEmpty, "disallow-empty", false, "Disallow empty selection (Windows and macOS only)") // Calendar options fset.UintVar(&year, "year", 0, "Set the calendar `year`") @@ -538,7 +538,7 @@ func loadFlags() []zenity.Option { if radiolist { opts = append(opts, zenity.RadioList()) } - if !allowEmpty { + if disallowEmpty { opts = append(opts, zenity.DisallowEmpty()) } diff --git a/internal/win/user32.go b/internal/win/user32.go index eb9fb68..59b52d6 100644 --- a/internal/win/user32.go +++ b/internal/win/user32.go @@ -142,6 +142,7 @@ const ( ES_AUTOHSCROLL = 0x0080 // List box control styles + LBS_NOTIFY = 0x0001 LBS_EXTENDEDSEL = 0x0800 // Month calendar control styles diff --git a/list.go b/list.go index 732d1e5..f8ff565 100644 --- a/list.go +++ b/list.go @@ -57,7 +57,7 @@ func DefaultItems(items ...string) Option { return funcOption(func(o *options) { o.defaultItems = items }) } -// DisallowEmpty returns an Option to not allow zero items to be selected (macOS only). +// DisallowEmpty returns an Option to not allow zero items to be selected (Windows and macOS only). func DisallowEmpty() Option { return funcOption(func(o *options) { o.disallowEmpty = true }) } diff --git a/list_windows.go b/list_windows.go index 3e2f24b..3b97f13 100644 --- a/list_windows.go +++ b/list_windows.go @@ -31,17 +31,19 @@ func listDlg(text string, items []string, multiple bool, opts options) ([]string } dlg := &listDialog{ - items: items, - multiple: multiple, + items: items, + multiple: multiple, + disallowEmpty: opts.disallowEmpty, } return dlg.setup(text, opts) } type listDialog struct { - items []string - multiple bool - out []string - err error + items []string + multiple bool + disallowEmpty bool + out []string + err error wnd win.HWND textCtl win.HWND @@ -84,7 +86,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) { strptr("STATIC"), strptr(text), _WS_ZEN_LABEL, 12, 10, 241, 16, dlg.wnd, 0, instance, nil) - var flags uint32 = _WS_ZEN_CONTROL | win.WS_VSCROLL + var flags uint32 = _WS_ZEN_CONTROL | win.WS_VSCROLL | win.LBS_NOTIFY if dlg.multiple { flags |= win.LBS_EXTENDEDSEL } @@ -120,6 +122,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) { } } + dlg.update() dlg.layout(getDPI(dlg.wnd)) centerWindow(dlg.wnd) win.SetFocus(dlg.listCtl) @@ -166,6 +169,20 @@ func (dlg *listDialog) layout(dpi dpi) { } } +func (dlg *listDialog) update() { + if dlg.disallowEmpty { + var enable bool + if dlg.multiple { + len := win.SendMessage(dlg.listCtl, win.LB_GETSELCOUNT, 0, 0) + enable = int32(len) > 0 + } else { + idx := win.SendMessage(dlg.listCtl, win.LB_GETCURSEL, 0, 0) + enable = int32(idx) >= 0 + } + win.EnableWindow(dlg.okBtn, enable) + } +} + func listProc(wnd win.HWND, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr { var dlg *listDialog switch msg { @@ -189,6 +206,7 @@ func listProc(wnd win.HWND, msg uint32, wparam uintptr, lparam *unsafe.Pointer) case win.WM_COMMAND: switch wparam { default: + dlg.update() return 1 case win.IDOK, win.IDYES: if dlg.multiple { From 900a9165ebdca109aa32121f65c42625da777ac1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:06:54 +0000 Subject: [PATCH 2/4] Bump golang.org/x/sys from 0.2.0 to 0.3.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.2.0 to 0.3.0. - [Release notes](https://github.com/golang/sys/releases) - [Commits](https://github.com/golang/sys/compare/v0.2.0...v0.3.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 03dc14f..04cc619 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 go.uber.org/goleak v1.2.0 // test golang.org/x/image v0.1.0 - golang.org/x/sys v0.2.0 + golang.org/x/sys v0.3.0 ) require ( diff --git a/go.sum b/go.sum index 0b17048..080e27e 100644 --- a/go.sum +++ b/go.sum @@ -39,10 +39,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= From ec524fa57e41bb5114146025b144c84b42f69adf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:37:15 +0000 Subject: [PATCH 3/4] Bump golang.org/x/image from 0.1.0 to 0.2.0 Bumps [golang.org/x/image](https://github.com/golang/image) from 0.1.0 to 0.2.0. - [Release notes](https://github.com/golang/image/releases) - [Commits](https://github.com/golang/image/compare/v0.1.0...v0.2.0) --- updated-dependencies: - dependency-name: golang.org/x/image dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 04cc619..fe06526 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/ncruces/go-strftime v0.1.8 github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 go.uber.org/goleak v1.2.0 // test - golang.org/x/image v0.1.0 + golang.org/x/image v0.2.0 golang.org/x/sys v0.3.0 ) diff --git a/go.sum b/go.sum index 080e27e..a013e84 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/image v0.1.0 h1:r8Oj8ZA2Xy12/b5KZYj3tuv7NG/fBz3TwQVvpJ9l8Rk= -golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c= +golang.org/x/image v0.2.0 h1:/DcQ0w3VHKCC5p0/P2B0JpAZ9Z++V2KOo2fyU89CXBQ= +golang.org/x/image v0.2.0/go.mod h1:la7oBXb9w3YFjBqaAwtynVioc1ZvOnNteUNrifGNmAI= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= @@ -46,7 +46,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= From 13c7dd311226b4ca6ebb9e7e7acb9018966c1df1 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Tue, 6 Dec 2022 18:24:37 +0000 Subject: [PATCH 4/4] Fixes focus issues, see #40. --- date_darwin.go | 3 --- internal/zenutil/osa_generated.go | 13 ++++++++----- internal/zenutil/osascripts/common.gojs | 17 +++++++++-------- internal/zenutil/osascripts/date.gojs | 2 ++ progress_darwin.go | 3 --- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/date_darwin.go b/date_darwin.go index 03da0d5..2c9954e 100644 --- a/date_darwin.go +++ b/date_darwin.go @@ -25,9 +25,6 @@ func calendar(text string, opts options) (t time.Time, err error) { } else { data.Text = text } - if opts.attach != nil { - data.Application = opts.attach - } if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i } diff --git a/internal/zenutil/osa_generated.go b/internal/zenutil/osa_generated.go index a3081d2..ddb84f9 100644 --- a/internal/zenutil/osa_generated.go +++ b/internal/zenutil/osa_generated.go @@ -23,23 +23,26 @@ $.exit(-1)} {'rgb('+res.map(x=>Math.round(x*255))+')'} {{- end}} {{define "common" -}} +{{if .WindowIcon}}{ObjC.import('Cocoa') +let nsapp=$.NSApplication.sharedApplication +let nsimg=$.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) +nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) +nsapp.setApplicationIconImage(nsimg)}{{end}} {{- if .Application}} try{var app=Application({{json .Application}})}catch{var app=Application.currentApplication()} {{- else}} var app=Application.currentApplication() {{- end}} app.includeStandardAdditions=true -{{if .WindowIcon}}{ObjC.import('Cocoa') -let nsapp=$.NSApplication.sharedApplication -let nsimg=$.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) -nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) -nsapp.setApplicationIconImage(nsimg)}{{end}} +app.activate() {{- end}} {{define "date" -}} ObjC.import('Cocoa') ObjC.import('stdio') ObjC.import('stdlib') {{template "common" .}} +var nsapp=$.NSApplication.sharedApplication +nsapp.setActivationPolicy($.NSApplicationActivationPolicyAccessory) var date=$.NSDatePicker.alloc.init date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar) date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay) diff --git a/internal/zenutil/osascripts/common.gojs b/internal/zenutil/osascripts/common.gojs index 4593fdb..12034ad 100644 --- a/internal/zenutil/osascripts/common.gojs +++ b/internal/zenutil/osascripts/common.gojs @@ -1,3 +1,11 @@ +{{if .WindowIcon}}{ + ObjC.import('Cocoa') + let nsapp = $.NSApplication.sharedApplication + let nsimg = $.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) + nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) + nsapp.setApplicationIconImage(nsimg) +}{{end}} + {{- if .Application}} try { var app = Application({{json .Application}}) @@ -8,11 +16,4 @@ var app = Application.currentApplication() {{- end}} app.includeStandardAdditions = true - -{{if .WindowIcon}}{ - ObjC.import('Cocoa') - let nsapp = $.NSApplication.sharedApplication - let nsimg = $.NSImage.alloc.initWithContentsOfFile({{json .WindowIcon}}) - nsapp.setActivationPolicy($.NSApplicationActivationPolicyRegular) - nsapp.setApplicationIconImage(nsimg) -}{{end}} \ No newline at end of file +app.activate() \ No newline at end of file diff --git a/internal/zenutil/osascripts/date.gojs b/internal/zenutil/osascripts/date.gojs index 4cf2f5a..c457c8c 100644 --- a/internal/zenutil/osascripts/date.gojs +++ b/internal/zenutil/osascripts/date.gojs @@ -1,6 +1,8 @@ ObjC.import('Cocoa') ObjC.import('stdio') ObjC.import('stdlib') +var nsapp = $.NSApplication.sharedApplication +nsapp.setActivationPolicy($.NSApplicationActivationPolicyAccessory) {{template "common" .}} var date = $.NSDatePicker.alloc.init diff --git a/progress_darwin.go b/progress_darwin.go index eb520a2..0c16700 100644 --- a/progress_darwin.go +++ b/progress_darwin.go @@ -19,9 +19,6 @@ func progress(opts options) (ProgressDialog, error) { if opts.maxValue >= 0 { data.Total = &opts.maxValue } - if opts.attach != nil { - data.Application = opts.attach - } if i, ok := opts.windowIcon.(string); ok { data.WindowIcon = i }