summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-04 23:12:56 -0400
committerPietro Gagliardi <[email protected]>2014-06-04 23:12:56 -0400
commit7ee05f826313410c99a04dcd5907b805d8e1ca3e (patch)
tree0453f65878902967e7730a4f775165def25e9518
parentc3a87ab7134fbbdbc0792c0df8c9aa06b4713d8a (diff)
Added the concept of transience to MsgBox() and MsgBoxError(). Individual implementations will come next.
-rw-r--r--dialog.go18
-rw-r--r--test/main.go12
2 files changed, 20 insertions, 10 deletions
diff --git a/dialog.go b/dialog.go
index ae94685..5fefd0f 100644
--- a/dialog.go
+++ b/dialog.go
@@ -11,12 +11,22 @@ import (
// Optionally, secondaryText can be used to show additional information.
// If you pass an empty string for secondaryText, neither additional information nor space for additional information will be shown.
// On platforms that allow for the message box window to have a title, os.Args[0] is used.
-func MsgBox(primaryText string, secondaryText string) {
- msgBox(primaryText, secondaryText)
+//
+// If parent is nil, the message box is modal to the entire application: the user cannot interact with any other window until this one is dismissed.
+// Whether or not resizing Windows will still be allowed is implementation-defined; if the implementation does allow it, resizes will still work properly.
+// Whether or not the message box stays above all other W+indows in the program is also implementation-defined.
+//
+// If parent is not nil, the message box is modal to that Window only.
+// Attempts to interact with parent will be blocked, but all other Windows in the application can still be used properly.
+// The message box will also stay above parent.
+// As with parent == nil, resizing is implementation-defined, but will work properly if allowed. [TODO verify]
+// If parent has not yet been created, MsgBox() panics. [TODO check what happens if hidden]
+func MsgBox(parent *Window, primaryText string, secondaryText string) {
+ msgBox(parent, primaryText, secondaryText)
}
// MsgBoxError displays a message box to the user with just an OK button and an icon indicating an error.
// Otherwise, it behaves like MsgBox.
-func MsgBoxError(primaryText string, secondaryText string) {
- msgBoxError(primaryText, secondaryText)
+func MsgBoxError(parent *Window, primaryText string, secondaryText string) {
+ msgBoxError(parent, primaryText, secondaryText)
}
diff --git a/test/main.go b/test/main.go
index cb17466..31e66c1 100644
--- a/test/main.go
+++ b/test/main.go
@@ -49,7 +49,7 @@ var macCrashTest = flag.Bool("maccrash", false, "attempt crash on Mac OS X on de
func invalidTest(c *Combobox, l *Listbox, s *Stack, g *Grid) {
x := func(what string ) {
if j := recover(); j == nil {
- MsgBoxError("test", fmt.Sprintf("%s: no panic", what))
+ MsgBoxError(nil, "test", fmt.Sprintf("%s: no panic", what))
panic("invalid test fail")
} else {
println("got", j.(error).Error())
@@ -143,7 +143,7 @@ func invalidTest(c *Combobox, l *Listbox, s *Stack, g *Grid) {
defer x("Area.SetSize() " + q.msg); a.SetSize(q.x, q.y); panic(nil)
}()
}
- MsgBox("test", "all working as intended")
+ MsgBox(nil, "test", "all working as intended")
}
var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening window")
@@ -226,7 +226,7 @@ func areaTest() {
if err != nil { println(err); continue }
a.SetSize(width, height)
case <-modaltest.Clicked:
- MsgBox("Modal Test", "")
+ MsgBox(nil, "Modal Test", "")
}
}
}
@@ -368,7 +368,7 @@ _=curtime
if c.Checked() {
f = MsgBoxError
}
- f("List Info",
+ f(nil, "List Info",
fmt.Sprintf("cb1: %d %q (len %d)\ncb2: %d %q (len %d)\nlb1: %d %q (len %d)\nlb2: %d %q (len %d)",
cb1.SelectedIndex(), cb1.Selection(), cb1.Len(),
cb2.SelectedIndex(), cb2.Selection(), cb2.Len(),
@@ -393,8 +393,8 @@ _=curtime
case <-invalidButton.Clicked:
invalidTest(cb1, lb1, nil, nil)
case <-bmsg.Clicked:
- MsgBox("Title Only", "")
- MsgBox("Title and Text", "Text and Title")
+ MsgBox(nil, "Title Only, no parent", "")
+ MsgBox(w, "Title and Text", "parent")
}
}
w.Hide()