summaryrefslogtreecommitdiff
path: root/combobox.go
diff options
context:
space:
mode:
Diffstat (limited to 'combobox.go')
-rw-r--r--combobox.go30
1 files changed, 18 insertions, 12 deletions
diff --git a/combobox.go b/combobox.go
index 2b50a72..41b24c0 100644
--- a/combobox.go
+++ b/combobox.go
@@ -39,20 +39,24 @@ func NewEditableCombobox(items ...string) *Combobox {
// Append adds items to the end of the Combobox's list.
// Append will panic if something goes wrong on platforms that do not abort themselves.
func (c *Combobox) Append(what ...string) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
for _, s := range what {
c.sysData.append(s)
}
return
}
- c.lock.Lock()
- defer c.lock.Unlock()
c.initItems = append(c.initItems, what...)
}
// InsertBefore inserts a new item in the Combobox 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 (c *Combobox) InsertBefore(what string, before int) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
var m []string
if c.created {
@@ -62,8 +66,6 @@ func (c *Combobox) InsertBefore(what string, before int) {
c.sysData.insertBefore(what, before)
return
}
- c.lock.Lock()
- defer c.lock.Unlock()
if before < 0 || before >= len(c.initItems) {
goto badrange
}
@@ -78,6 +80,9 @@ badrange:
// Delete removes the given item from the Combobox. It panics if the given index is out of bounds.
func (c *Combobox) Delete(index int) {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
if index < 0 || index >= c.sysData.len() {
goto badrange
@@ -85,8 +90,6 @@ func (c *Combobox) Delete(index int) {
c.sysData.delete(index)
return
}
- c.lock.Lock()
- defer c.lock.Unlock()
if index < 0 || index >= len(c.initItems) {
goto badrange
}
@@ -98,21 +101,23 @@ badrange:
// Selection returns the current selection.
func (c *Combobox) Selection() string {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
return c.sysData.text()
}
- c.lock.Lock()
- defer c.lock.Unlock()
return ""
}
// SelectedIndex returns the index of the current selection in the Combobox. It returns -1 either if no selection was made or if text was manually entered in an editable Combobox.
func (c *Combobox) SelectedIndex() int {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
return c.sysData.selectedIndex()
}
- c.lock.Lock()
- defer c.lock.Unlock()
return -1
}
@@ -120,11 +125,12 @@ func (c *Combobox) SelectedIndex() int {
//
// On platforms for which this function may return an error, it panics if one is returned.
func (c *Combobox) Len() int {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
if c.created {
return c.sysData.len()
}
- c.lock.Lock()
- defer c.lock.Unlock()
return len(c.initItems)
}