diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-28 16:02:50 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-28 16:02:50 -0400 |
| commit | 02d6a03ba3a657aa7b50d072771361236bb207a3 (patch) | |
| tree | 84b3f82db75150b88f31ef7547925c5f78664025 /dialog.go | |
| parent | cd116033a380a119a3a025cb54873b5732cb3803 (diff) | |
Decided to make dialogs code-modal; will figure out how to get the behavior I want on Mac OS X - http://stackoverflow.com/questions/24468620/how-do-i-create-a-nested-run-loop-after-nsalert-beginsheetmodalforwindow-tha - Now to see if Windows works...
Diffstat (limited to 'dialog.go')
| -rw-r--r-- | dialog.go | 36 |
1 files changed, 9 insertions, 27 deletions
@@ -2,12 +2,6 @@ package ui -// 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 ( @@ -15,14 +9,6 @@ const ( 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 } - // sentinel (not nil so programmer errors don't go undetected) // this window is invalid and cannot be used directly // notice the support it uses @@ -31,11 +17,6 @@ var dialogWindow = &Window{ winhandler: dh, } } -type dhandler chan *dialogret -func (d dhandler) Event(e Event, dat interface{}) { - d <- dat.(*dialogret) -} -var dh = make(dhandler) // 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. @@ -44,31 +25,32 @@ var dh = make(dhandler) // On platforms that allow for the message box window to have a title, os.Args[0] is used. // // See "On Dialogs" in the package overview for behavioral information. -func MsgBox(primaryText string, secondaryText string) Response { +func MsgBox(primaryText string, secondaryText string) { dialogWindow.msgBox(primaryText, secondaryText) - return (<-dh).res } // 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. -func (w *Window) MsgBox(primaryText string, secondaryText string) Dialog { +func (w *Window) MsgBox(primaryText string, secondaryText string) { if !w.created { panic("parent window passed to Window.MsgBox() before it was created") } - return w.msgBox(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. // // See "On Dialogs" in the package overview for more information. -func MsgBoxError(primaryText string, secondaryText string) Dialog { +func MsgBoxError(primaryText string, secondaryText string) { dialogWindow.msgBoxError(primaryText, secondaryText) - return (<-dh).res } // 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. -func (w *Window) MsgBoxError(primaryText string, secondaryText string) Dialog { - return w.msgBoxError(primaryText, secondaryText) +func (w *Window) MsgBoxError(primaryText string, secondaryText string) { + if !w.created { + panic("parent window passed to Window.MsgBox() before it was created") + } + w.msgBoxError(primaryText, secondaryText) } |
