diff options
| author | Pietro Gagliardi <[email protected]> | 2014-06-28 15:40:06 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-06-28 15:40:06 -0400 |
| commit | cd116033a380a119a3a025cb54873b5732cb3803 (patch) | |
| tree | a9d861363217934431178c2adde43684895cc5fa | |
| parent | 7a1331c04cd43d26c3293b5597656920d7be7f47 (diff) | |
Adjusted window.go to make safe functions actually safe.
| -rw-r--r-- | window.go | 62 |
1 files changed, 37 insertions, 25 deletions
@@ -89,37 +89,49 @@ func (w *Window) SetSpaced(spaced bool) { // Open creates the Window with Create and then shows the Window with Show. As with Create, you cannot call Open more than once per window. func (w *Window) Open(control Control) { - w.Create(control) - w.Show() + done := make(chan struct{}) + defer close(done) + touitask(func() { + w.Create(control) + w.Show() + done <- struct{}{} + }) + <-done } // Create creates the Window, setting its control to the given control. It does not show the window. This can only be called once per window, and finalizes all initialization of the control. func (w *Window) Create(control Control) { - if w.created { - panic("window already open") - } - w.sysData.spaced = w.spaced - w.sysData.winhandler = w.handler - w.sysData.close = func(b *bool) { - w.sysData.winhandler.Event(Closing, b) - } - err := w.sysData.make(nil) - if err != nil { - panic(fmt.Errorf("error opening window: %v", err)) - } - if control != nil { - w.sysData.allocate = control.allocate - err = control.make(w.sysData) + done := make(chan struct{}) + defer close(done) + touitask(func() { + if w.created { + panic("window already open") + } + w.sysData.spaced = w.spaced + w.sysData.winhandler = w.handler + w.sysData.close = func(b *bool) { + w.sysData.winhandler.Event(Closing, b) + } + err := w.sysData.make(nil) if err != nil { - panic(fmt.Errorf("error adding window's control: %v", err)) + panic(fmt.Errorf("error opening window: %v", err)) } - } - err = w.sysData.setWindowSize(w.initWidth, w.initHeight) - if err != nil { - panic(fmt.Errorf("error setting window size (in Window.Open()): %v", err)) - } - w.sysData.setText(w.initTitle) - w.created = true + if control != nil { + w.sysData.allocate = control.allocate + err = control.make(w.sysData) + if err != nil { + panic(fmt.Errorf("error adding window's control: %v", err)) + } + } + err = w.sysData.setWindowSize(w.initWidth, w.initHeight) + if err != nil { + panic(fmt.Errorf("error setting window size (in Window.Open()): %v", err)) + } + w.sysData.setText(w.initTitle) + w.created = true + done <- struct{}{} + }) + <-done } // Show shows the window. |
