summaryrefslogtreecommitdiff
path: root/listbox.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-11 13:37:19 -0400
committerPietro Gagliardi <[email protected]>2014-03-11 13:37:19 -0400
commitc43583fe20a3a54920774fb762c74d22b60b70dc (patch)
tree48450cf2b6fae55786291c5c411dc98f789127dd /listbox.go
parentcbcf9da6a03d3e559eaf9744947208fcb2a18c0a (diff)
Handle out of range on Listbox.Delete(). The Mac OS X exception behavior I previously noted has bene resolved: what happens after exception handling is undefined :|
Diffstat (limited to 'listbox.go')
-rw-r--r--listbox.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/listbox.go b/listbox.go
index 6d5decc..63f8722 100644
--- a/listbox.go
+++ b/listbox.go
@@ -69,17 +69,24 @@ badrange:
panic(fmt.Errorf("index %d out of range in Listbox.InsertBefore()", before))
}
-// Delete removes the given item from the Listbox.
-// (TODO action on invalid index)
+// Delete removes the given item from the Listbox. It panics if the given index is out of bounds.
func (l *Listbox) Delete(index int) error {
l.lock.Lock()
defer l.lock.Unlock()
if l.created {
+ if index < 0 || index >= l.sysData.len() {
+ goto badrange
+ }
return l.sysData.delete(index)
}
+ if index < 0 || index >= len(l.initItems) {
+ goto badrange
+ }
l.initItems = append(l.initItems[:index], l.initItems[index + 1:]...)
return nil
+badrange:
+ panic(fmt.Errorf("index %d out of range in Listbox.Delete()", index))
}
// 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.