2 Replies Latest reply on May 28, 2018 9:24 AM by Loic.Aigon

    Push to newlist

    bena10018036 Level 1

      Hey,

       

      Basicly i have a list of all the files that are open in photoshop.
      I was wondering if I could push a variable called "New file" into this list.
      And check afterwards if the file is called like this.

       

      var itemDoc = null;
      
      //Dropdown list
      w.NewList=w.add ("dropdownlist", undefined, app.documents);
      w.NewList.preferredSize.width = 275;
      
      //Place open files in list
      w.NewList.selection = 0;  
      itemDoc = w.NewList.selection.index;
      
      //Get selected document from list
      w.NewList.onChange= function ()
      {  
      itemDoc = w.NewList.selection.index;      
      return itemDoc;  
      }  
      
        • 1. Re: Push to newlist
          Chuck Uebele Adobe Community Professional & MVP

          Something like this?

           

          #target photoshop
          
          var fileList = new Array()
          getList ();
          
          var dlg = new Window('dialog','List of open files')
              var dropList = dlg.add('dropdownlist',undefined,fileList);
              dropList.selection = 0;
              dropList.onChange = function(){
                  //some code here
                  }
              dlg.show();
              
          function getList(){
              fileList = new Array();
              for(var i=0;i<app.documents.length;i++){
                  fileList.push(app.documents[i].name)
              }
              fileList.push('New File')
          }
          
          • 2. Re: Push to newlist
            Loic.Aigon Adobe Community Professional
            var w = new Window("dialog");
            var itemDoc = null;  
            
            
            
            
            var docs = app.documents;
            var arr = [];
            var n = docs.length;
            while ( n--) arr[n] = docs[n].name;
            arr.push ( "New file" );
            
            
            //Dropdown list  
            w.NewList=w.add ("dropdownlist", undefined,  arr);  
            w.NewList.preferredSize.width = 275;  
              
            //Place open files in list  
            w.NewList.selection = 0;    
            itemDoc = w.NewList.selection.index;  
              
              
             var btn = w.add('button',undefined,"go");
            
            //Get selected document from list  
            w.NewList.onChange= function ()  
            {    
            itemDoc = w.NewList.selection.index;        
            return itemDoc;    
            } 
            
            
            
            
            btn.onClick = function() {
            alert("You want to open"+(w.NewList.selection.index == w.NewList.children.length-1? " a new file" : "an existing file") );
            }
            w.show();