GTInspector and sorting in dictionaries

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

GTInspector and sorting in dictionaries

Holger Freyther
Hey,

I have a simple dictionary with class as the key and a number as value. In the inspector I try to sort it by the value. But it is doing an alphabetical sort and not numerical?

I can change Dictionary>>#gtInspectorItemsIn: to pass a sortedBy: block when adding the value column but is "<" a general usable protocol? How would one specialize the sort depending on the data in the dictionary?

Any ideas how to get numbers sorted intuitively without adding too much magic (trying to convert the string representation back to a number, custom GTTablePresentation, using "a value < b value" and use the string representation if that fails..)?

cheers
        holger
Reply | Threaded
Open this post in threaded view
|

Re: GTInspector and sorting in dictionaries

Juraj Kubelka
Hi,

> El 26-07-2017, a las 20:28, Holger Freyther <[hidden email]> escribió:
>
> Hey,
>
> I have a simple dictionary with class as the key and a number as value. In the inspector I try to sort it by the value. But it is doing an alphabetical sort and not numerical?

By default, Glamour framework sorts string representations of displayed data.

>
> I can change Dictionary>>#gtInspectorItemsIn: to pass a sortedBy: block when adding the value column but is "<" a general usable protocol? How would one specialize the sort depending on the data in the dictionary?

You cannot send #< message to any object, e.g. Object new < Object new.
I think it would be necessary to introduce a new method to Object (or ProtoObject) to deal with your scenario in a polymorphic way.

>
> Any ideas how to get numbers sorted intuitively without adding too much magic (trying to convert the string representation back to a number, custom GTTablePresentation, using "a value < b value" and use the string representation if that fails..)?

If I need a customized Inspector views, I usually subclass a collection class. In your case, it would be:

Dictionary subclass: NumberKeyedDictionary … or something like that … then you can change Glamour presentations (GTInspector extensions).

>
> cheers
> holger

Cheers,
Juraj