2 Replies Latest reply on Feb 11, 2011 7:30 AM by swingcarlos

    ScriptUI Treeview selected values




      I'm running on a new Powerbook running OSX 10.6.6, InDesign CS5.


      I have a ScriptUI javascript snippet below that should bring up a treeview object inside a dialog:


      // Start Snippet

      var myTree = w.add ("treeview", [0, 0, 400, 170]);


      myApparel = myTree.add ("node", "Apparel");


      myWomens = myApparel.add ("node", "Womens");


      myWomens.add ("item", "Blouses");


      myWomens.add ("item", "Pants");


      myWomens.add ("item", "Skirts");


      myMens = myApparel.add ("node", "Mens");


      myMens.add ("item", "Shirts");


      myMens.add ("item", "Pants");


      myMens.add ("item", "Suits");


      saveButton = w.add('button', undefined, 'Save');


      saveButton.onClick = function()




          alert('myCategories: ' + myApparel.expanded + ' ' + myApparel.selected +


                  '\nmyMens: ' + myMens.expanded + ' ' +myMens.selected +


                  '\nmyWomens: ' + myWomens.expanded +  ' '  + myWomens.selected






      // End Snippet.


      The problem I have is with the expected values for the "expanded" values that are coming back.


      If I select Apparel->Womens->Skirts, I expect the myApparel.expanded and myWomens.expanded

      values to come back as 'true'. They do not.  Is this a bug?


      How else can I get the full hierarchy/path of my selection?



        • 1. Re: ScriptUI Treeview selected values
          Peter Kahrel Adobe Community Professional & MVP

          selection is a property of trees, not of listItems. So you get the labelof the selected treenode like this:





          • 2. Re: ScriptUI Treeview selected values
            swingcarlos Level 1


            I have no problem getting the value/index of the selected item.


            What I think is a bug is that the ancestor/parental nodes 'expanded' and 'selected'

            flags of my selected item are not set to true, when clearly they are expanded.


            Anyway, here is my implementation to get all the nodes including my selection:


            // Start Snippet

                    var sel = myTree.selection;


                    var depth=0;

                    var parent = null;
                    var nodes = new Array();
                    if(sel != null)
                        nodes[depth] = sel;

                        parent = sel.parent;
                    while(parent != null && parent != myTree)
                        nodes[depth] = parent;       
                        parent = parent.parent;

            // End Snippet


            I would have liked to have a utility function that returned an array

            of listItems or an array of strings, similar to what I have done above.