diff --git a/combobox.go b/combobox.go index 85384be..009e639 100644 --- a/combobox.go +++ b/combobox.go @@ -78,7 +78,7 @@ 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) error { +func (c *Combobox) Delete(index int) { c.lock.Lock() defer c.lock.Unlock() @@ -86,13 +86,14 @@ func (c *Combobox) Delete(index int) error { if index < 0 || index >= c.sysData.len() { goto badrange } - return c.sysData.delete(index) + c.sysData.delete(index) + return } if index < 0 || index >= len(c.initItems) { goto badrange } c.initItems = append(c.initItems[:index], c.initItems[index + 1:]...) - return nil + return badrange: panic(fmt.Errorf("index %d out of range in Combobox.Delete()", index)) } diff --git a/listbox.go b/listbox.go index 63f8722..7e05287 100644 --- a/listbox.go +++ b/listbox.go @@ -70,7 +70,7 @@ 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) error { +func (l *Listbox) Delete(index int) { l.lock.Lock() defer l.lock.Unlock() @@ -78,13 +78,14 @@ func (l *Listbox) Delete(index int) error { if index < 0 || index >= l.sysData.len() { goto badrange } - return l.sysData.delete(index) + l.sysData.delete(index) + return } if index < 0 || index >= len(l.initItems) { goto badrange } l.initItems = append(l.initItems[:index], l.initItems[index + 1:]...) - return nil + return badrange: panic(fmt.Errorf("index %d out of range in Listbox.Delete()", index)) } diff --git a/sysdata.go b/sysdata.go index a942122..2680269 100644 --- a/sysdata.go +++ b/sysdata.go @@ -61,7 +61,7 @@ func (c *cSysData) selectedTexts() []string { func (c *cSysData) setWindowSize(int, int) error { panic(runtime.GOOS + " sysData does not define setWindowSize()") } -func (c *cSysData) delete(int) error { +func (c *cSysData) delete(int) { panic(runtime.GOOS + " sysData does not define delete()") } func (c *cSysData) preferredSize() (int, int) { diff --git a/sysdata_darwin.go b/sysdata_darwin.go index 32b94c3..85b6c73 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -449,7 +449,7 @@ func (s *sysData) setWindowSize(width int, height int) error { return nil } -func (s *sysData) delete(index int) error { +func (s *sysData) delete(index int) { ret := make(chan struct{}) defer close(ret) uitask <- func() { @@ -457,7 +457,6 @@ func (s *sysData) delete(index int) error { ret <- struct{}{} } <-ret - return nil } func (s *sysData) setProgress(percent int) { diff --git a/sysdata_unix.go b/sysdata_unix.go index a910df7..6947e20 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -275,7 +275,7 @@ func (s *sysData) setWindowSize(width int, height int) error { return nil } -func (s *sysData) delete(index int) error { +func (s *sysData) delete(index int) { ret := make(chan struct{}) defer close(ret) uitask <- func() { @@ -283,7 +283,6 @@ func (s *sysData) delete(index int) error { ret <- struct{}{} } <-ret - return nil } func (s *sysData) setProgress(percent int) { diff --git a/sysdata_windows.go b/sysdata_windows.go index 62c5788..3cc5730 100644 --- a/sysdata_windows.go +++ b/sysdata_windows.go @@ -494,7 +494,7 @@ func (s *sysData) setWindowSize(width int, height int) error { return nil } -func (s *sysData) delete(index int) (err error) { +func (s *sysData) delete(index int) { ret := make(chan uiret) defer close(ret) uitask <- &uimsg{ @@ -509,9 +509,8 @@ func (s *sysData) delete(index int) (err error) { } r := <-ret if r.ret == uintptr(classTypes[s.ctype].selectedIndexErr) { - return fmt.Errorf("failed to delete item from combobox/listbox (last error: %v)", r.err) + panic(fmt.Errorf("failed to delete item from combobox/listbox (last error: %v)", r.err)) } - return nil } func (s *sysData) setProgress(percent int) { diff --git a/todo.md b/todo.md index ec02400..87d5c76 100644 --- a/todo.md +++ b/todo.md @@ -17,8 +17,7 @@ so I don't forget: - Combobox/Listbox.Select (with Listbox.Select allowing bulk) - Checkbox.Check or Checkbox.SetChecked - Listbox.SelectAll -- have Listbox.Delete() panic on invalid index; it does not yet due to the Mac OS X signaling issue mentioned under "super important" - - same for other methods that take indices, like the Stack and Grid stretchy methods +- have methods that take indices panic on invalid index, like the Stack and Grid stretchy methods - make the Windows implementation of message boxes run on uitask - ensure MsgBoxError can run if initialization failed if things change ever - should Labels be selectable?