From 2647d28f2bdc91bbc7350ceb1dec648b68d22599 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 1 Apr 2014 16:43:56 -0400 Subject: [PATCH] Removed the initText parameter from sysData.make() and changed all invocations to call sysData.setText() separately; this avoids the need to check if sysData.setText() is valid. Also implemented that on GTK+. --- area.go | 2 +- button.go | 3 ++- checkbox.go | 3 ++- combobox.go | 2 +- label.go | 3 ++- lineedit.go | 3 ++- listbox.go | 2 +- progressbar.go | 2 +- sysdata.go | 2 +- sysdata_unix.go | 8 +------- window.go | 3 ++- 11 files changed, 16 insertions(+), 17 deletions(-) diff --git a/area.go b/area.go index aee8b78..aee1684 100644 --- a/area.go +++ b/area.go @@ -288,7 +288,7 @@ func (a *Area) make(window *sysData) error { defer a.lock.Unlock() a.sysData.handler = a.handler - err := a.sysData.make("", window) + err := a.sysData.make(window) if err != nil { return err } diff --git a/button.go b/button.go index 9a5f93c..908936e 100644 --- a/button.go +++ b/button.go @@ -55,10 +55,11 @@ func (b *Button) make(window *sysData) error { defer b.lock.Unlock() b.sysData.event = b.Clicked - err := b.sysData.make(b.initText, window) + err := b.sysData.make(window) if err != nil { return err } + b.sysData.setText(b.initText) b.created = true return nil } diff --git a/checkbox.go b/checkbox.go index fe46023..6427d0c 100644 --- a/checkbox.go +++ b/checkbox.go @@ -63,10 +63,11 @@ func (c *Checkbox) make(window *sysData) error { c.lock.Lock() defer c.lock.Unlock() - err := c.sysData.make(c.initText, window) + err := c.sysData.make(window) if err != nil { return err } + c.sysData.setText(c.initText) c.created = true return nil } diff --git a/combobox.go b/combobox.go index 41b24c0..ec90dc6 100644 --- a/combobox.go +++ b/combobox.go @@ -138,7 +138,7 @@ func (c *Combobox) make(window *sysData) (err error) { c.lock.Lock() defer c.lock.Unlock() - err = c.sysData.make("", window) + err = c.sysData.make(window) if err != nil { return err } diff --git a/label.go b/label.go index c4bcc4e..69cdddc 100644 --- a/label.go +++ b/label.go @@ -49,10 +49,11 @@ func (l *Label) make(window *sysData) error { l.lock.Lock() defer l.lock.Unlock() - err := l.sysData.make(l.initText, window) + err := l.sysData.make(window) if err != nil { return err } + l.sysData.setText(l.initText) l.created = true return nil } diff --git a/lineedit.go b/lineedit.go index 43ec60c..79a8c25 100644 --- a/lineedit.go +++ b/lineedit.go @@ -61,10 +61,11 @@ func (l *LineEdit) make(window *sysData) error { defer l.lock.Unlock() l.sysData.alternate = l.password - err := l.sysData.make(l.initText, window) + err := l.sysData.make(window) if err != nil { return err } + l.sysData.setText(l.initText) l.created = true return nil } diff --git a/listbox.go b/listbox.go index 9a1d756..111d790 100644 --- a/listbox.go +++ b/listbox.go @@ -139,7 +139,7 @@ func (l *Listbox) make(window *sysData) (err error) { l.lock.Lock() defer l.lock.Unlock() - err = l.sysData.make("", window) + err = l.sysData.make(window) if err != nil { return err } diff --git a/progressbar.go b/progressbar.go index 6ef3f84..520fb0c 100644 --- a/progressbar.go +++ b/progressbar.go @@ -47,7 +47,7 @@ func (p *ProgressBar) make(window *sysData) error { p.lock.Lock() defer p.lock.Unlock() - err := p.sysData.make("", window) + err := p.sysData.make(window) if err != nil { return err } diff --git a/sysdata.go b/sysdata.go index fe4bb00..7f43a3e 100644 --- a/sysdata.go +++ b/sysdata.go @@ -21,7 +21,7 @@ type cSysData struct { // this interface is used to make sure all sysDatas are synced var _xSysData interface { - make(initText string, window *sysData) error + make(window *sysData) error firstShow() error show() hide() diff --git a/sysdata_unix.go b/sysdata_unix.go index d60bef4..50b51cd 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -64,7 +64,6 @@ var classTypes = [nctypes]*classData{ c_combobox: &classData{ make: gtk_combo_box_text_new, makeAlt: gtk_combo_box_text_new_with_entry, - // TODO setText text: gtk_combo_box_text_get_active_text, append: gtk_combo_box_text_append_text, insert: gtk_combo_box_text_insert_text, @@ -86,7 +85,6 @@ var classTypes = [nctypes]*classData{ c_listbox: &classData{ make: gListboxNewSingle, makeAlt: gListboxNewMulti, - // TODO setText text: gListboxText, append: gListboxAppend, insert: gListboxInsert, @@ -112,7 +110,7 @@ var classTypes = [nctypes]*classData{ }, } -func (s *sysData) make(initText string, window *sysData) error { +func (s *sysData) make(window *sysData) error { ct := classTypes[s.ctype] ret := make(chan *C.GtkWidget) defer close(ret) @@ -152,7 +150,6 @@ func (s *sysData) make(initText string, window *sysData) error { } <-ret } - s.setText(initText) return nil } @@ -183,9 +180,6 @@ func (s *sysData) hide() { } func (s *sysData) setText(text string) { - if classTypes[s.ctype].setText == nil { // does not have concept of text - return - } ret := make(chan struct{}) defer close(ret) uitask <- func() { diff --git a/window.go b/window.go index 868696c..c4ab16c 100644 --- a/window.go +++ b/window.go @@ -72,7 +72,7 @@ func (w *Window) Open(control Control) (err error) { panic("window already open") } w.sysData.event = w.Closing - err = w.sysData.make(w.initTitle, nil) + err = w.sysData.make(nil) if err != nil { return fmt.Errorf("error opening window: %v", err) } @@ -87,6 +87,7 @@ func (w *Window) Open(control Control) (err error) { if err != nil { return fmt.Errorf("error setting window size (in Window.Open()): %v", err) } + w.sysData.setText(w.initTitle) // TODO separate showing? err = w.sysData.firstShow() if err != nil {