summaryrefslogtreecommitdiff
path: root/dialog.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-08 08:17:47 -0400
committerPietro Gagliardi <[email protected]>2014-06-08 08:17:47 -0400
commit7cb8fc1e324c6c6c2717d169bc928717c5c44198 (patch)
treed1480d3ce4f0813d2d914b5b62624cbbad731bd9 /dialog.go
parent4509247a7793f71879b0ad63308bbeac2947776a (diff)
Woo yeah it's another API change to MsgBox()! This splits parent out and makes it a receiver of MsgBox() and MsgBoxError() for the case when you want to show modal to a specific window only. These will eventually return channels, but first I'll need to igure out how to get this working...
Diffstat (limited to 'dialog.go')
-rw-r--r--dialog.go42
1 files changed, 27 insertions, 15 deletions
diff --git a/dialog.go b/dialog.go
index 2c16107..9a5ec5e 100644
--- a/dialog.go
+++ b/dialog.go
@@ -6,34 +6,46 @@ import (
// ...
)
+// sentinel (presently nil; may be a private instance if subtle bugs start showing up in user code)
+var dialogWindow *Window
+
// MsgBox displays an informational message box to the user with just an OK button.
// primaryText should be a short string describing the message, and will be displayed with additional emphasis on platforms that support it.
// 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.
//
-// 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.
+// 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.
-// If parent has not yet been created, MsgBox() panics.
-// If parent has not been shown yet or is currently hidden, what MsgBox() does is implementation-defined.
-func MsgBox(parent *Window, primaryText string, secondaryText string) {
- if parent != nil && !parent.created {
- panic("parent window passed to MsgBox() before it was created")
+func MsgBox(primaryText string, secondaryText string) {
+ dialogWindow.msgBox(parent, primaryText, secondaryText)
+}
+
+// MsgBox behaves like the package-scope MsgBox function, except the message box is modal to w only.
+// Attempts to interact with w will be blocked, but all other Windows in the application can still be used properly.
+// The message box will also stay above w.
+// Whether w can be resized while the message box is displayed is implementation-defined, but will work properly if allowed.
+// If w has not yet been created, MsgBox() panics.
+// If w has not been shown yet or is currently hidden, what MsgBox does is implementation-defined.
+func (w *Window) MsgBox(primaryText string, secondaryText string) {
+ if !w.created {
+ panic("parent window passed to Window.MsgBox() before it was created")
}
- msgBox(parent, primaryText, secondaryText)
+ w.msgBox(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(parent *Window, primaryText string, secondaryText string) {
- if parent != nil && !parent.created {
+func MsgBoxError(primaryText string, secondaryText string) {
+ dialogWindow.msgBoxError(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 Window.MsgBox.
+func (w *Window) MsgBoxError(primaryText string, secondaryText string) {
+ if !w.created {
panic("parent window passed to MsgBoxError() before it was created")
}
- msgBoxError(parent, primaryText, secondaryText)
+ w.msgBoxError(primaryText, secondaryText)
}