Sunday, December 11, 2011

gnocl::list add

I've finished taking a look at enhancing the add sub-command ensuring bakcward compatibility with the legacy effects. This snippet shows how it works:

widget-id add rowNum data options

$list add    { "A" 1 } -singleRow 1    ;# 1
$list add {} { "B" 2 } -singleRow 1    ;# 2
$list add  0 { "C" 3 } -singleRow 1    ;# 3
$list add -1 { "D" 4 } -singleRow 1    ;# 4
$list add  3 { "E" 5 } -singleRow 1    ;# 5

In order for the interpretor to know which row to use the second argument needs to be an integer. '0' means insert at the top of the list with -1 the bottom. In a pre-existing list, any other positive value in between will insert at the appropriate level. If the specified row is a value that exceeds the length of the list, the item will be appended to the end.
The command returns the number of the row just inserted.

Finally, providing a non integer values will also result in appending the value to the bottom of the list unless an empty string is provided which will prepend the entry to the top.

PS> Just noted that setting the -singleRow option is compulsory rather than an option! I'll look at this later today.

No comments: