From c43583fe20a3a54920774fb762c74d22b60b70dc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 11 Mar 2014 13:37:19 -0400 Subject: 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 :| --- listbox.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'listbox.go') 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. -- cgit v1.2.3