diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-15 17:52:33 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-15 17:52:33 -0500 |
| commit | 8c30cae462e7be26ec51a726c583255b9bcc304a (patch) | |
| tree | 905344b9d011d679848d1b02900b5cccbba7ef48 /combobox.go | |
| parent | 430eac563a56fdace04fa0781594bfbd1ad3ef6e (diff) | |
Added Combobox.Append() and Combobox.InsertBefore().
Diffstat (limited to 'combobox.go')
| -rw-r--r-- | combobox.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/combobox.go b/combobox.go index 9b38fa3..9d55ed3 100644 --- a/combobox.go +++ b/combobox.go @@ -26,7 +26,34 @@ func NewCombobox(editable bool, items ...string) (c *Combobox) { return c } -// TODO Append, InsertBefore, Delete +// Append adds an item to the end of the Combobox's list. +func (c *Combobox) Append(what string) (err error) { + c.lock.Lock() + defer c.lock.Unlock() + + if c.created { + return c.sysData.append(what) + } + c.initItems = append(c.initItems, what) + return nil +} + +// InsertBefore inserts a new item in the Combobox before the item at the given position. +func (c *Combobox) InsertBefore(what string, before int) (err error) { + c.lock.Lock() + defer c.lock.Unlock() + + if c.created { + return c.sysData.insertBefore(what, before) + } + m := make([]string, 0, len(c.initItems) + 1) + m = append(m, c.initItems[:before]...) + m = append(m, what) + c.initItems = append(m, c.initItems[before:]...) + return nil +} + +// TODO Delete // Selection returns the current selection. func (c *Combobox) Selection() string { |
