Added the concept of transience to MsgBox() and MsgBoxError(). Individual implementations will come next.

This commit is contained in:
Pietro Gagliardi 2014-06-04 23:12:56 -04:00
parent c3a87ab713
commit 7ee05f8263
2 changed files with 20 additions and 10 deletions

View File

@ -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)
}

View File

@ -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()