TreeView custom sort?
Richard Gaskin
ambassador at fourthworld.com
Sat Dec 10 13:27:14 EST 2016
Matt Maier wrote:
> On Sat, Dec 10, 2016 at 9:30 AM, Richard Gaskin wrote:
>
>> I need a sort of object browser, and have been playing around with
>> the TreeView widget as a possible quick solution.
>>
>> Handy for many things, but being array-based it seems my options for
>> sorting are limited.
>>
>> Like the IDE's Object Browser, I need a sort order which reflects
>> physical layering of objects.
>>
>> I could number these as I add them to the array, but the numbers
>> would be meaningless to the user, as they would be in the Object
>> Browser.
>>
>> I'd like to show the object name instead, but I can't find a way to
>> do that while maintaining a fixed order.
>>
>> Any ideas, or am I back to making a custom control for this?
>
> I used rTree when I was trying to find a pre-built tree tool. It's
> pretty good.
I like rtree, but my needs are modest enough that I prefer to use a
single object for such things when I can.
I've made tree viewers before with a single field, and may do that again
if I can't get the TreeView widget to do what I need.
> As a side note, I just want to say that it's refreshing to see you
> have a hard time explaining something ;)
If that seems rare we just don't hang out enough. :)
> So is the problem that TreeView doesn't let you control what order the
> branches are displayed in? It just dumps them out in a random order,
> or in a single order that happens to be the wrong one for your use
> case?
My question may have been sparse because it assumes the reader is
familiar with the nature of associative arrays as being inherently
unsorted, and also assumes my understanding that arrays are the only way
to load the TreeView widget is correct. Either assumption can fail. :)
Associative arrays like LiveCode's differ from indexed arrays by having
no internal sense of order. For getting and putting values that's fine,
but when you need to retrieve the aggregate collection it means the
result (such as with "get the keys of tSomeArray) will be in an
unpredictable order.
The TreeView widget allows sorting the keys either alphabetically or
numerically, but neither are meaningful in my UI.
With a standard list field I can put the contents in as a single chunk
and of course the order of lines is preserved.
But since the data I'm working with is hierarchical, it would be nice to
use a prefab object like the TreeView to display its contents, rather
than have to use a third-party custom control like rtree or roll my own.
With a list field I have the option of having zero-width columns, so if
I need to sort by something (say an ordinal number I use internally when
building the list) I can do so and the user never needs to see it.
Similarly, I could use an ordinal number as the first level of the
array, and use that for sorting only while displaying for the user only
the subarrays.
But the TreeView doesn't seem to provide any way to hide keys or
portions of key names, and being array-based I can think of no other
option for maintaining a fixed order.
It may not be so bad to roll my own. The TreeView widget doesn't seem
to handle default keyboard actions common to hierarchical list views
(left and right arrow keys to expand/collapse, or up and down to
navigate) so I'd need to be doing a bit of scripting with this either way.
--
Richard Gaskin
Fourth World Systems
Software Design and Development for the Desktop, Mobile, and the Web
____________________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list