Skip to content
This repository was archived by the owner on Jun 3, 2022. It is now read-only.

Commit e6fab12

Browse files
committed
Implement simple MessageBox dialog, where no icon will be displayed.
In some cases it was necessary to have a dialog without the icon. Especially on macOS where the dialog's text gets squeezed due to the icon being too big, making it look a little odd. On Linux I made it display as `info`, since I don't know of a way to disable icons using zenity.
1 parent cbd38e8 commit e6fab12

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

message_darwin.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88
"syscall"
99
)
1010

11+
// MessageBox displays message box and ok button without icon.
12+
func MessageBox(title, text string) (bool, error) {
13+
return osaDialog(title, text, "")
14+
}
15+
1116
// Info displays information dialog.
1217
func Info(title, text string) (bool, error) {
1318
return osaDialog(title, text, "note")
@@ -48,7 +53,11 @@ func Question(title, text string, defaultCancel bool) (bool, error) {
4853

4954
// osaDialog displays dialog.
5055
func osaDialog(title, text, icon string) (bool, error) {
51-
out, err := osaExecute(`display dialog ` + osaEscapeString(text) + ` with title ` + osaEscapeString(title) + ` buttons {"OK"} default button "OK" with icon ` + icon + ``)
56+
iconScript := ""
57+
if icon != "" {
58+
iconScript = ` with icon ` + icon
59+
}
60+
out, err := osaExecute(`display dialog ` + osaEscapeString(text) + ` with title ` + osaEscapeString(title) + ` buttons {"OK"} default button "OK"` + iconScript)
5261
if err != nil {
5362
if exitError, ok := err.(*exec.ExitError); ok {
5463
ws := exitError.Sys().(syscall.WaitStatus)

message_js.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import (
66
"github.com/gopherjs/gopherjs/js"
77
)
88

9+
// MessageBox displays message box and ok button without icon.
10+
func MessageBox(title, text string) (bool, error) {
11+
return alertDialog(title, text, "")
12+
}
13+
914
// Info displays information dialog.
1015
func Info(title, text string) (ret bool, err error) {
1116
return alertDialog(title, text, "\u24d8")

message_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import (
77
"syscall"
88
)
99

10+
// MessageBox displays message box and ok button without icon.
11+
func MessageBox(title, text string) (bool, error) {
12+
return cmdDialog(title, text, "info") // TODO: Remove icon
13+
}
14+
1015
// Info displays information dialog.
1116
func Info(title, text string) (bool, error) {
1217
return cmdDialog(title, text, "info")

message_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import (
44
"testing"
55
)
66

7+
func TestMessageBox(t *testing.T) {
8+
ret, err := MessageBox("MessageBox", "Lorem ipsum dolor sit amet.")
9+
if err != nil {
10+
t.Error(err)
11+
}
12+
13+
if verboseTests {
14+
println("ret:", ret)
15+
}
16+
}
17+
718
func TestInfo(t *testing.T) {
819
ret, err := Info("Info", "Lorem ipsum dolor sit amet.")
920
if err != nil {

message_unsupported.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
package dlgs
44

5+
// MessageBox displays message box and ok button without icon.
6+
func MessageBox(title, text string) (bool, error) {
7+
return false, ErrUnsupported
8+
}
9+
510
// Info displays information dialog box.
611
func Info(title, message string) (bool, error) {
712
return false, ErrUnsupported

message_windows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
package dlgs
44

5+
// MessageBox displays message box and ok button without icon.
6+
func MessageBox(title, text string) (bool, error) {
7+
ret := messageBox(title, text, mbOk)
8+
return ret == idOk, nil
9+
}
10+
511
// Info displays information dialog.
612
func Info(title, text string) (bool, error) {
713
ret := messageBox(title, text, mbOk|mbIconInfo)

0 commit comments

Comments
 (0)