7 Replies Latest reply on Jul 5, 2010 3:56 AM by schiuma24

    Drop Down for opening libraries

    schiuma24 Level 1

      Im a complete noob at javascript...ive been reading some tutorials and stuff..but its not enough!

      what im trying to accomplish here is to have a drop down menu for opening the selected file.

       

       

      var myDialog = app.dialogs.add({name:"Iconos Travelplan", canCancel:true});
      with(myDialog){
      with(dialogColumns.add()){
      with(borderPanels.add()){
      with(dialogColumns.add()){
      staticTexts.add({staticLabel:"Selecciona una biblioteca:"});
      }
      with(dialogColumns.add()){
      var myIcons = dropdowns.add({stringList:
      ["Iberrail","Costas","Teletipos"], selectedIndex:0});
      if(myDialog.show() == true){
      var Iberrail = app.open(File("/c/iberrail.indl"), false);
      var Costas = app.open(File("/c/costas.indl"), false);
      var Teletipos = app.open(File("/c/teletipos.indl"), false);
      }
      }
      }
      }
      }
      myDialog.destroy();

        • 1. Re: Drop Down for opening libraries
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          Here is my solution. Maybe there is some other ways too..

           

          var myFiles = Array(
               ["Iberrail","Costas","Teletipos"], // names in list box
               ["/c/iberrail.indl","/c/costas.indl","/c/teletipos.indl"] // file names
               );
          
          var myDialog = app.dialogs.add({name:"Iconos Travelplan", canCancel:true});
               with(myDialog){
                    with(dialogColumns.add()){
                         with(borderPanels.add()){
                              with(dialogColumns.add()){
                                   staticTexts.add({staticLabel:"Selecciona una biblioteca:"});
                              }
                              with(dialogColumns.add()){
                                   var myIcons = dropdowns.add({stringList:myFiles[0], selectedIndex:0});
                              }
                         }
                    }
               }
          
          if(myDialog.show() == true){
               app.open(File(myFiles[1][myIcons.selectedIndex]),false);
          }
          
          myDialog.destroy();
          

           

          tomaxxi

          • 3. Re: Drop Down for opening libraries
            Marijan Tompa [tomaxxi] Level 4

            You are welcome!

             

            tomaxxi

            • 4. Re: Drop Down for opening libraries
              Marijan Tompa [tomaxxi] Level 4

              Hey!

               

              It's me again I've got good idea how to make it more user friendly...

              You just have to insert path where you have your libraries,

              and script will automatically fill drop down box with filenames.

               

              You can adjust labels to your wish,

              and you can show/hide working folder in dialog too.

               

              var myWorkFolder = Folder("/d/!myWork"); // working folder
              var showWorkFolder = Boolean(true); // shows(true)/hides(false) working folder in dialog
              
              var strWinTitle = String("Library opener");
              var strWorkFolder = String("Working folder:");
              var strSelectLib = String("Select library:");
              var strNoFiles = String("-- No libraries found --"); // shows if no libraries found
              
              ///////////////////////// SCRIPT /////////////////////////
              
              var myFiles = myWorkFolder.getFiles("*.indl");
              var myFilesNo = myFiles.length;
              var myLibFiles = Array();
              
              if(!myFilesNo){
                   myLibFiles[0] = strNoFiles;
              }else{
                   for(var i=0; i < myFilesNo; i++){
                        myLibFiles.push(myFiles[i].displayName.substr(0,myFiles[i].displayName.lastIndexOf(".")));
                   }
              }
              
              var myDialog = app.dialogs.add({name:strWinTitle, canCancel:true});
                   with(myDialog){
                        with(dialogColumns.add()){
                             if(showWorkFolder){
                                  with(dialogRows.add()){
                                       with(borderPanels.add()){
                                            with(dialogColumns.add()){
                                                 staticTexts.add({staticLabel:strWorkFolder});
                                            }
                                            with(dialogColumns.add()){
                                                 staticTexts.add({staticLabel:myPath.fsName});
                                            }
                                       }
                                  }
                             }
                             with(dialogRows.add()){
                                  with(borderPanels.add()){
                                       with(dialogColumns.add()){
                                            staticTexts.add({staticLabel:strSelectLib});
                                       }
                                       with(dialogColumns.add()){
                                            var myLib = dropdowns.add({stringList:myLibFiles, selectedIndex:0});
                                       }
                                  }
                             }
                        }
                   }
              
              if(myDialog.show() == true){
                   if(myFilesNo){
                        app.open(File(myFiles[myLib.selectedIndex]),false);
                   }
              }
              
              myDialog.destroy();
              

               

              tomaxxi

              • 5. Re: Drop Down for opening libraries
                Kasyan Servetsky Level 5

                Tomaxxi,

                 

                I think

                staticTexts.add({staticLabel:myPath.fsName});

                should be

                staticTexts.add({staticLabel:myWorkFolder.fsName});

                 

                Kasyan

                1 person found this helpful
                • 6. Re: Drop Down for opening libraries
                  Marijan Tompa [tomaxxi] Level 4

                  Hey Kasyan!

                   

                  Thanks for your reply!

                  I forgot to change that after variable name change!

                   

                  So, here is corrected script:

                   

                  var myWorkFolder = Folder("/d/!myWork"); // working folder
                  var showWorkFolder = Boolean(true); // shows(true)/hides(false) working folder in dialog
                   
                  var strWinTitle = String("Library opener");
                  var strWorkFolder = String("Working folder:");
                  var strSelectLib = String("Select library:");
                  var strNoFiles = String("-- No libraries found --"); // shows if no libraries found
                   
                  ///////////////////////// SCRIPT /////////////////////////
                   
                  var myFiles = myWorkFolder.getFiles("*.indl");
                  var myFilesNo = myFiles.length;
                  var myLibFiles = Array();
                   
                  if(!myFilesNo){
                       myLibFiles[0] = strNoFiles;
                  }else{
                       for(var i=0; i < myFilesNo; i++){
                            myLibFiles.push(myFiles[i].displayName.substr(0,myFiles[i].displayName.lastIndexOf(".")));
                       }
                  }
                   
                  var myDialog = app.dialogs.add({name:strWinTitle, canCancel:true});
                       with(myDialog){
                            with(dialogColumns.add()){
                                 if(showWorkFolder){
                                      with(dialogRows.add()){
                                           with(borderPanels.add()){
                                                with(dialogColumns.add()){
                                                     staticTexts.add({staticLabel:strWorkFolder});
                                                }
                                                with(dialogColumns.add()){
                                                     staticTexts.add({staticLabel:myWorkFolder.fsName});
                                                }
                                           }
                                      }
                                 }
                                 with(dialogRows.add()){
                                      with(borderPanels.add()){
                                           with(dialogColumns.add()){
                                                staticTexts.add({staticLabel:strSelectLib});
                                           }
                                           with(dialogColumns.add()){
                                                var myLib = dropdowns.add({stringList:myLibFiles, selectedIndex:0});
                                           }
                                      }
                                 }
                            }
                       }
                   
                  if(myDialog.show() == true){
                       if(myFilesNo){
                            app.open(File(myFiles[myLib.selectedIndex]),false);
                       }
                  }
                   
                  myDialog.destroy();
                  

                   

                  tomaxxi

                  1 person found this helpful
                  • 7. Re: Drop Down for opening libraries
                    schiuma24 Level 1

                    tnx for your help guys!