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+.

This commit is contained in:
Pietro Gagliardi 2014-04-01 16:43:56 -04:00
parent 81153617dc
commit 2647d28f2b
11 changed files with 16 additions and 17 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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()

View File

@ -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() {

View File

@ -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 {