8 Replies Latest reply on Sep 21, 2012 8:18 AM by RuyRamos

    Label function in ListBox.

    RuyRamos

      Hi,

       

      I want my list box to display all paragraphs in a textFrame. That is possible, I just add the paragraph as an Item in the list.

       

      BUT the label displayed is [Object Paragraph]. Is it possible to select a label function or something like that to the Listbox?

       

       

      Regards,

      Ruy

        • 1. Re: Label function in ListBox.
          Peter Kahrel Adobe Community Professional & MVP

          You should add the paragraph's contents as a list item, not the paragraph.

           

          Peter

          • 2. Re: Label function in ListBox.
            RuyRamos Level 1

            Hi, tanks for your answer.

             

            I want the object in the list to be a paragraph not a String.

             

            I'm doing a Paragraph sorter. In my solution I have two listbox a Original and a Output. I select the paragraphs in the original list and "send" it over to the Output list. After the sorting has been done I want to replace the paragraphs list in the textframe to be the new sorted list(output). So by passing the paragraphs content I just pass the content and not the xml/tags of the paragraphs.

             

            Thanks

            • 3. Re: Label function in ListBox.
              Peter Kahrel Adobe Community Professional & MVP

              I see. You would probably need to create a keyed object, with each item in the object a key-value pair in which the paragraph contents is the key and the paragraph object the value. You use the keys to display in the list boxes and sort them. Then when you quit the dialog you rearrange the paragraphs in the text frame.

               

              Peter

              • 4. Re: Label function in ListBox.
                RuyRamos Level 1

                I have tried several different ways of doing this but I havent tried a key-value pair.

                I tried to to something like this:

                   

                list.add ("item", {key: paragraph.contents, value: paragraph}, 0);

                But it didint work. It just shows [Object object]. How did you mean I should do it?

                 

                After reading the documentation for the Listbox (over and over) I can only make the conclucion that it wont work. It says that the text argument must be a String, so me passing an object won't work.

                 

                ListBox.add (type: String , text: String ): ListItem

                ScriptUI Classes

                Adds an item to the choices in this list.

                Returns the item control object. If this is a multi-column list box, each added  ListItem  represents one selectable row. Its  text  and  image  values specify the label in the first column, and the  subitems  property specifies the labels in the additional columns.

                type: Data Type: String

                The type of the child element, the string "item".

                text (optional): Data Type: String

                The localizable text label for the item.

                 

                Any more ideas? Maybe i shoulden't use a ListBox for my solution?

                 

                Thanks so much for your help, been stuck all day.

                • 5. Re: Label function in ListBox.
                  Peter Kahrel Adobe Community Professional & MVP

                  I meant something like this:

                   

                  p = app.documents[0].textFrames[0].paragraphs.everyItem().getElements();
                  
                  obj = {};
                  for (i = 0; i < p.length; i++)
                      obj[p[i].contents] = p[i];
                  
                  w = new Window ('dialog'); w.orientation = 'row';
                      list1 = w.add ('listbox');
                      for (i in obj) list1.add ('item', i);
                  
                      list2 = w.add ('listbox');
                          list2.preferredSize = list1.preferredSize;
                  
                  w.show();
                  

                  I don't even know if this is practicable: if the paragraph contents is long it isn't workable.

                  But I meant to ask you earlier: why do you want to sort paragraphs via a dialog? To get non-standard orders?

                   

                  Peter

                  • 6. Re: Label function in ListBox.
                    RuyRamos Level 1

                    Thank you.

                     

                    I got it working by creating a class with a toString() function (It feels obvious now):

                     

                    function myParagraph(paragraph)

                    {

                       this.paragraph = paragraph;

                       this.toString = function()

                       {

                           return this.paragraph.contents;

                       };

                    }

                     

                    The problem I'm trying to solve is when I have a text frame with text on several rows that are unsorted and I want it sorted. The problem is that the sorting dosen't have a logical sorting it's just text that the user wants in a different order.

                     

                    E.g below you see my dialog (I have a text frame with the text one to ten on ten different rows). Imagen now that you want the rows to have a different order. Therefor my dialog.

                     

                    Screen Shot 2012-09-21 at 3.52.22 PM.png

                     

                    Thanks for the help.

                    Regards,

                    Ruy

                    • 7. Re: Label function in ListBox.
                      Peter Kahrel Adobe Community Professional & MVP

                      > Imagine now that you want the rows to have a different order.

                       

                      See http://www.kahrel.plus.com/indesign/scriptui.html pp. 25-27.

                       

                      Peter

                      • 8. Re: Label function in ListBox.
                        RuyRamos Level 1

                        Yeah, that part I have already figure out. Thanks anyways.

                         

                        Now I just use the move function for the paragraphs to move them to the correct position.

                        paragraph.move(LocationOptions.AT_BEGINNING);

                         

                        Thanks for all your help and have a nice weekend.

                        Regards,

                        Ruy