diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-18 11:50:56 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-18 11:50:56 -0400 |
| commit | 24342eb05d70af48d609a224351237eb1f3d41d2 (patch) | |
| tree | a76faba6d73910fa1f982e58a0f3696c5c702ff8 /listbox.go | |
| parent | b95d581e86ee57de7c163efa5eb0fb165d0a1032 (diff) | |
Restored the locks everywhere except on resizing calculations. I'll run under the assumption that uitask cannot process any requests while a resize occurs, which means preferredSize() and Stack/Grid.setRect() are inherently safe... let's hope I'm right...
Diffstat (limited to 'listbox.go')
| -rw-r--r-- | listbox.go | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -40,20 +40,24 @@ func NewMultiSelListbox(items ...string) *Listbox { // Append adds items to the end of the Listbox's list. // Append will panic if something goes wrong on platforms that do not abort themselves. func (l *Listbox) Append(what ...string) { + l.lock.Lock() + defer l.lock.Unlock() + if l.created { for _, s := range what { l.sysData.append(s) } return } - l.lock.Lock() - defer l.lock.Unlock() l.initItems = append(l.initItems, what...) } // InsertBefore inserts a new item in the Listbox before the item at the given position. It panics if the given index is out of bounds. // InsertBefore will also panic if something goes wrong on platforms that do not abort themselves. func (l *Listbox) InsertBefore(what string, before int) { + l.lock.Lock() + defer l.lock.Unlock() + var m []string if l.created { @@ -63,8 +67,6 @@ func (l *Listbox) InsertBefore(what string, before int) { l.sysData.insertBefore(what, before) return } - l.lock.Lock() - defer l.lock.Unlock() if before < 0 || before >= len(l.initItems) { goto badrange } @@ -79,6 +81,9 @@ badrange: // Delete removes the given item from the Listbox. It panics if the given index is out of bounds. func (l *Listbox) Delete(index int) { + l.lock.Lock() + defer l.lock.Unlock() + if l.created { if index < 0 || index >= l.sysData.len() { goto badrange @@ -86,8 +91,6 @@ func (l *Listbox) Delete(index int) { l.sysData.delete(index) return } - l.lock.Lock() - defer l.lock.Unlock() if index < 0 || index >= len(l.initItems) { goto badrange } @@ -99,21 +102,23 @@ badrange: // Selection returns a list of strings currently selected in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox. func (l *Listbox) Selection() []string { + l.lock.Lock() + defer l.lock.Unlock() + if l.created { return l.sysData.selectedTexts() } - l.lock.Lock() - defer l.lock.Unlock() return nil } // SelectedIndices returns a list of the currently selected indexes in the Listbox, or an empty list if none have been selected. This list will have at most one item on a single-selection Listbox. func (l *Listbox) SelectedIndices() []int { + l.lock.Lock() + defer l.lock.Unlock() + if l.created { return l.sysData.selectedIndices() } - l.lock.Lock() - defer l.lock.Unlock() return nil } @@ -121,11 +126,12 @@ func (l *Listbox) SelectedIndices() []int { // // On platforms for which this function may return an error, it panics if one is returned. func (l *Listbox) Len() int { + l.lock.Lock() + defer l.lock.Unlock() + if l.created { return l.sysData.len() } - l.lock.Lock() - defer l.lock.Unlock() return len(l.initItems) } |
