2 Replies Latest reply on Dec 23, 2008 9:12 AM by Eric @ MCA

    [CS3, JS] Stuck on DropDownList again

    Eric @ MCA Level 3
      Hi all. Trying to build a simple dialog in JS via resource and having a heck of a time!

      Anyone able to tell me why my drop down list is always blank in the following resource?
      res =
      "dialog { \
      orientation: 'column', \
      alignChildren: 'right', \
      range: Group { \
      orientation: 'row', \
      s: StaticText { text:'Range:' }, \
      e: EditText { preferredSize: [200, 20] } \
      }, \
      master: Group { \
      orientation: 'row', \
      s: StaticText { text: 'Apply Master:' }, \
      l: DropDownList { \
      stringList:['A-Master', 'B-Master'], \
      preferredSize: [200, 20] }, \
      }, \
      buttons: Group { \
      orientation: 'row', \
      alignment: 'right', \
      okBtn: Button { \
      text:'OK', properties:{ name:'ok' } \
      }, \
      cancelBtn: Button { \
      text:'Cancel', properties:{ name:'cancel' } \
      } \
      } \
      }";


      Sorry if this a really bone-headed question. I always have a heck of a time with the Dialog class it seems. :-/
        • 1. Re: [CS3, JS] Stuck on DropDownList again
          Peter Kahrel Adobe Community Professional & MVP
          Eric,

          stringList is a property in the 'classic' dialog model, not in scriptUI. There's a creation problem with dropdowns in scriptUI in that the property name to use is "items", which throws an error:
          l: DropDownList { \
          
          items: ['A-Master', 'B-Master'], \
          preferredSize: [200, 20] }, \

          So you'd have to use something like this:
          l: DropDownList { \
          
          {properties: {items: ['A-Master', 'B-Master']}}, \
          preferredSize: [200, 20] }, \

          To show some item after the window has been created, do this:
          w = new Window (res);
          
          w.master.l.selection = 1;
          w.show()

          I stopped using resource strings for various reasons, the above problem is just one of them. The reason cited most often for using resource strings is that they allow you to separate design features from code. But this separation is also possible without using resoource strings. And ironically, you used code in your res. string. I'd think that the purist would do something like this:
          res = "dialog ...
          
          ...
          ...
          <pre>l: DropDownList {preferredSize: [200, 20]}, \
          ...
          ...
          }";
          w = new Window (res);
          w.master.l.add ('item', 'A-Master');
          w.master.l.add ('item', 'B-Master');
          w.master.l.selection = 1;
          w.show()


          After all, the contents of the array is not part of the design.

          Peter
          • 2. Re: [CS3, JS] Stuck on DropDownList again
            Eric @ MCA Level 3
            Hi Peter,

            Thanks for your help!

            Yes, I actually started out initially in "purist mode". Apparently, I fell off the tracks due to wanting to add all the items at once via something like:

            w.master.l.stringList = masterSpreads.everyItem().name

            As near as I can tell (now), that's just not possible. When I use "items" rather than "stringList", I get back a read-only error. Which is a step up from a broken dialog box at least, but still--argh.

            This loop works at least, though, so I am back on track.
            for( i=0; i < masterSpreads.count(); ++i ) {
            
                win.master.l.add( 'item', masterSpreads[i].name );
            }


            At least now I have a better idea of how things work. It looks like the golden rule when writing resources is that anything that is not a "global" property to all ScriptUI items must be enclosed in the properties area, eh?

            Thanks again for taking the time to write all that all up. Very useful info!