2014-02-17 01:34:58 -06:00
|
|
|
// 7 february 2014
|
2014-03-12 20:55:45 -05:00
|
|
|
|
2014-02-19 10:41:10 -06:00
|
|
|
package ui
|
2014-02-17 01:34:58 -06:00
|
|
|
|
2014-06-28 08:37:31 -05:00
|
|
|
// Dialog is an interface adopted by all dialogs.
|
|
|
|
type Dialog struct {
|
|
|
|
Response() Response // response code from the dialog
|
|
|
|
Selection() interface{} // currently nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Response denotes a response from the user to a Dialog.
|
|
|
|
type Response uint
|
|
|
|
const (
|
|
|
|
NotDone Response = iota
|
|
|
|
OK
|
|
|
|
)
|
|
|
|
|
|
|
|
// basic return
|
|
|
|
type dialogret struct {
|
|
|
|
res Response
|
|
|
|
sel interface{}
|
|
|
|
}
|
|
|
|
func (d *dialogret) Response() Response { return d.res }
|
|
|
|
func (d *dialogret) Selection() interface{} { return d.sel }
|
|
|
|
|
2014-06-08 12:00:21 -05:00
|
|
|
// sentinel (not nil so programmer errors don't go undetected)
|
|
|
|
// this window is invalid and cannot be used directly
|
2014-06-28 08:37:31 -05:00
|
|
|
// notice the support it uses
|
|
|
|
var dialogWindow = &Window{
|
|
|
|
sysData: &sysData{
|
|
|
|
winhandler: dh,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type dhandler chan *dialogret
|
|
|
|
func (d dhandler) Event(e Event, dat interface{}) {
|
|
|
|
d <- dat.(*dialogret)
|
|
|
|
}
|
|
|
|
var dh = make(dhandler)
|
2014-06-08 07:17:47 -05:00
|
|
|
|
2014-02-17 01:34:58 -06:00
|
|
|
// MsgBox displays an informational message box to the user with just an OK button.
|
2014-03-12 11:14:24 -05:00
|
|
|
// primaryText should be a short string describing the message, and will be displayed with additional emphasis on platforms that support it.
|
2014-04-10 11:34:30 -05:00
|
|
|
// 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.
|
2014-03-12 11:14:24 -05:00
|
|
|
// On platforms that allow for the message box window to have a title, os.Args[0] is used.
|
2014-06-10 13:49:54 -05:00
|
|
|
//
|
2014-06-08 11:56:04 -05:00
|
|
|
// See "On Dialogs" in the package overview for behavioral information.
|
2014-06-28 08:37:31 -05:00
|
|
|
func MsgBox(primaryText string, secondaryText string) Response {
|
|
|
|
dialogWindow.msgBox(primaryText, secondaryText)
|
|
|
|
return (<-dh).res
|
2014-06-08 07:17:47 -05:00
|
|
|
}
|
|
|
|
|
2014-06-08 11:56:04 -05:00
|
|
|
// MsgBox is the Window method version of the package-scope function MsgBox.
|
|
|
|
// See that function's documentation and "On Dialogs" in the package overview for more information.
|
2014-06-28 08:37:31 -05:00
|
|
|
func (w *Window) MsgBox(primaryText string, secondaryText string) Dialog {
|
2014-06-08 07:17:47 -05:00
|
|
|
if !w.created {
|
|
|
|
panic("parent window passed to Window.MsgBox() before it was created")
|
2014-06-05 02:09:02 -05:00
|
|
|
}
|
2014-06-08 07:50:52 -05:00
|
|
|
return w.msgBox(primaryText, secondaryText)
|
2014-02-17 01:34:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// MsgBoxError displays a message box to the user with just an OK button and an icon indicating an error.
|
2014-03-12 11:14:24 -05:00
|
|
|
// Otherwise, it behaves like MsgBox.
|
2014-06-10 13:49:54 -05:00
|
|
|
//
|
2014-06-08 11:56:04 -05:00
|
|
|
// See "On Dialogs" in the package overview for more information.
|
2014-06-28 08:37:31 -05:00
|
|
|
func MsgBoxError(primaryText string, secondaryText string) Dialog {
|
|
|
|
dialogWindow.msgBoxError(primaryText, secondaryText)
|
|
|
|
return (<-dh).res
|
2014-06-08 07:17:47 -05:00
|
|
|
}
|
|
|
|
|
2014-06-08 11:56:04 -05:00
|
|
|
// MsgBoxError is the Window method version of the package-scope function MsgBoxError.
|
|
|
|
// See that function's documentation and "On Dialogs" in the package overview for more information.
|
2014-06-28 08:37:31 -05:00
|
|
|
func (w *Window) MsgBoxError(primaryText string, secondaryText string) Dialog {
|
2014-06-08 07:50:52 -05:00
|
|
|
return w.msgBoxError(primaryText, secondaryText)
|
2014-02-17 01:34:58 -06:00
|
|
|
}
|