5 Replies Latest reply on Sep 5, 2016 4:58 AM by Loic.Aigon

    Indesign Script UI copy text in list item

    jakec88782761 Level 2

      Hi Everyone,

       

      I've written a script UI code to create a termbase.

       

      I want to be able to click an item in the list in any column and copy the text into the edittext field.

       

      I'm not sure if I need to create a button for this or is it possible to right click the mouse to copy the text?

       

      Here is the code:

       

      var w = new Window ('dialog {text:"Blatchford Termbase",alignChildren:"fill"}');
      w.spacing=0;

      var headers = w.add('group');
      headers.spacing=0;
      headers.margins=[0,5,0,0];
      var dimH = [0,0,200,20];

      headers.add('statictext', dimH, '\u00A0English');
      headers.add('statictext', dimH, '\u00A0French');
      headers.add('statictext', dimH, '\u00A0German');
      headers.add('statictext', dimH, '\u00A0Italien');
      headers.add('statictext', dimH, '\u00A0Spanish');
      headers.add('statictext', dimH, '\u00A0Norwegian');
      headers.add('statictext', dimH, '\u00A0Russian');
      headers.add('statictext', dimH, '\u00A0Turkish');

      headers.graphics.backgroundColor=w.graphics.newBrush(w.graphics.BrushType.SOLID_COLOR, [0.7,0.7,0.7],1);

      for (var i = 0; i<headers.children.length; i++)

      headers.children[i].graphics.font=ScriptUI.newFont ('Myriad Pro', 'bold' , 16)

       

      var columns = w.add('group{multiselect:true}');
      columns.spacing=0;

      var dimC = [0,0,200,600];

      var col1 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col2 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col3 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col4 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col5 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col6 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col7 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);
      var col8 = columns.add('listbox', dimC, ["Dorsiflexion", "Plantarflexion","trans-tibial","trans-femoral"]);

       

      var user_input = w.add('group')
      var entry = user_input.add('edittext',dimH, '');
      entry.characters=30;
      entry.alignment='left';
      entry.active=true;

      col1.selection=0;

      var convert = user_input.add('button', undefined, 'Convert to lower case');
      convert.onClick=function() {entry.text=entry.text.toLowerCase();}
      user_input.orientation='row';
      user_input.alignment='left';

       

      w.show();

       

      Any help or comments would be greatly appreciated

        • 1. Re: Indesign Script UI copy text in list item
          Loic.Aigon Adobe Community Professional

          Try this

           

          col1.onChange = 
           col2.onChange =
           col3.onChange = 
           col4.onChange = 
           col5.onChange = 
           col6.onChange = 
           col7.onChange = 
           col8.onChange =
           function() {
            entry.text = this.selection? this.selection.text : "";
            }
          

           

          Loic

          Ozalto | Productivity Oriented - Loïc Aigon

          1 person found this helpful
          • 2. Re: Indesign Script UI copy text in list item
            Skemicle Level 3

            Just out of curiosity.. Could you not use dropdowns instead of listboxes? Something like this UI:

             

            var win = app.dialogs.add ({name:"Blatchford Termbase"});

            var langs = ["English", "French", "German", "Italian", "Spanish", "Norwegian", "Russian", "Turkish"]

            var terms = ["Dorsiflexion", "Plantarflexion", "trans-tibial", "trans-femoral"];

            with(win.dialogColumns.add()){

                staticTexts.add({staticLabel:"Select Language:"});

                staticTexts.add({staticLabel:"Select Term:"});

            }with(win.dialogColumns.add()){

                var selLangField = dropdowns.add({stringList:langs, selectedIndex:0});

                var selTermField = dropdowns.add({stringList:terms, selectedIndex:0});

            }if(win.show() != true){

                exit();

            }else{

                    var selLang = langs[selLangField.selectedIndex];

                    var selTerm = terms[selTermField.selectedIndex];

            }alert(selLang + " " + selTerm);

            • 3. Re: Indesign Script UI copy text in list item
              jakec88782761 Level 2

              This does look interesting but We would need to see the languages in a row to be able to see the translation from English.

               

              Thanks for your comment.

              • 4. Re: Indesign Script UI copy text in list item
                jakec88782761 Level 2

                This was really helpful thanks.

                 

                I also tried this:

                col1.onDoubleClick=function(){

                    entry.text=col1.selection;

                    };

                col2.onDoubleClick=function(){

                    entry.text=col2.selection;

                    };

                col3.onDoubleClick=function(){

                    entry.text=col3.selection;

                    };

                col4.onDoubleClick=function(){

                    entry.text=col4.selection;

                    };

                col5.onDoubleClick=function(){

                    entry.text=col5.selection;

                    };

                col6.onDoubleClick=function(){

                    entry.text=col6.selection;

                    };

                col7.onDoubleClick=function(){

                    entry.text=col7.selection;

                    };

                col8.onDoubleClick=function(){

                    entry.text=col8.selection;

                    };

                 

                This works but I'm sure there is a more efficient way to write it.

                • 5. Re: Indesign Script UI copy text in list item
                  Loic.Aigon Adobe Community Professional

                  You can apply the same function to every single 'column' instance as I did higher. It's still less code.