From 8c30cae462e7be26ec51a726c583255b9bcc304a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 15 Feb 2014 17:52:33 -0500 Subject: Added Combobox.Append() and Combobox.InsertBefore(). --- combobox.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'combobox.go') 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 { -- cgit v1.2.3