I’m still a scripting novice with LL, so forgive me for the following question which probably has a simple answer.

I’m still a scripting novice with LL, so forgive me for the following question which probably has a simple answer.

I’m missing a basic feature in LL: When I add or remove an item from a folder, I want the folder to automatically rearrange its contents in alphabetical order.

It’s trivial to fetch the container holding the items in the folder, but what then?

I can’t find a built-in sort method, so do I need to write my own? If so, what do I do with my sorted array of items once I have it? How do I assign that back to the container?

I’m probably overthinking this. Maybe there’s a built-in method after all.

]]>

4 Commentsto I’m still a scripting novice with LL, so forgive me for the following question which probably has a simple answer.

  1. Anonymous says:

    < ![CDATA[

    Here is a simple script to do that:



    var e=LL.getEvent();


    var c=e.getContainer();


    var width=1;


    var editor=


    c.getOpener().getProperties().edit();


    var enter=LL.getEvent().getSource()==”C_RESUMED”;


    editor.setInteger(“s.labelFontColor”,enter?0xffff0000:0xff000000);


    editor.setInteger(“s.iconColorFilter”,enter?0xffff0000:0xff000000);


    editor.commit();


    if(enter)


    {


    var items=c.getItems();


    var labels=[];


    for(a=0;a


    {


    var i=items.getAt(a);


    labels.push(i.getLabel());


    i.setName(i.getLabel());


    }


    labels.sort(noCaseSort);


    for(b=0;b


    c.getItemByName(labels[b]).setCell(b%width,Math.floor(b/width),b%width+1,Math.floor(b/width)+1);


    }



    function noCaseSort(a,b)


    {


    if(a.toLowerCase()>b.toLowerCase())return 1;


    if(a.toLowerCase()


    return 0;


    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    This is what I use in my drawer, it does some other things too

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Lukas Morawietz Thanks for that. I’ll try it out.



    There’s more to this than I thought. Because LL folders have an option to sort their contents, I thought there would be a method in the API that I could simply call.



    I was hoping for something like:



    c = LL.getEvent().getContainer();


    c = c.sortItems(noCaseSort);



    but all of the work has to be done manually.



    The setCell invocation in particular would have taken me ages to figure out.



    Thank you very much!

    ]]>

  4. Anonymous says:

    < ![CDATA[

    Me too searching an option to sort folders alphabetically.


    Not sure if this script does it.


    Do I need to import it to any folder I wish to sort automatically in a-z order?


    Is that maybe on the ToDo List for some future version?


    It l ooks so basic to me, to have it sorted in different ways that I wonder that a script is needed.


    Thanks.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *