4 Replies Latest reply on Oct 13, 2011 6:13 AM by bduffy323

    closing a custom window

    bduffy323 Level 1

      Is there anyway to close an Indesign window other than using this functionality:

       

      var myDialog = new Window('dialog', 'From the list of offers');

       

      var myButtonGroup = myDialog.add("group");

           myButtonGroup.alignment = "center";

           var ok = myButtonGroup.add ("button", undefined, "OK");

           var cancel = myButtonGroup.add ("button", undefined, "Cancel");

           var filter = myButtonGroup.add ("button", undefined, "Filter");

       

           filter.onClick = function() {

                                                   myDialog.close();

                                                   buildFilterWindow();

                                              }

       

       

       

      if (myDialog .show()==true)

      {

                          processOffer();

      }

      else

      {

                          exit();

      }

       

       

       

      This is okay for a window that only has an OK and CANCEL but I have a third button that should close this window and create a different window. In the next window when I press OK it gives me the "cannot handle the request because a modal dialog or alert is active." error. However If I put the functionality from my third button into the OK button then the original window closes properly and my other windows functionality works without giving me the error. So clearly it is that the orginal window is not being closed properly when my third button is clicked.

        • 1. Re: closing a custom window
          csm_phil Level 4

          Hi Duffy,

           

          Can you please try the below JS code.

           

           

          var win = new Window('dialog', 'From the list of offers');
          var myClickButton = win.add ("group"); 
          with (myClickButton){
              var myOkbutton = myClickButton.add ("button", undefined, "OK", {name: "ok"}); 
              var myCancel =myClickButton.add ("button", undefined, "Cancel"); 
              var myReset = myClickButton.add ("button", undefined, "Filter"); 
              }
          
          myOkbutton.onClick = function () { 
              alert("OK");
              win.close();
              };
          myCancel.onClick = function () { 
              alert("Cancel");
              win.close();
              };
          myReset.onClick = function () { 
              alert("Filter");
              win.close();
              };
          
          win.center();
          win.show();
          
          

           

          thx

          csm_phil

          • 2. Re: closing a custom window
            Marijan Tompa [tomaxxi] Level 4

            Hi Duffy,

             

            Unfortunately, solution by csm_phil will not work correctly either.

             

            Here is working solution:

             

            var win = new Window('dialog', 'From the list of offers');
            var myClickButton = win.add ("group"); 
            with (myClickButton){
                var myOkbutton = myClickButton.add ("button", undefined, "OK", {name: "OK"}); 
                var myCancel =myClickButton.add ("button", undefined, "Cancel", {name: "Cancel"}); 
                var myReset = myClickButton.add ("button", undefined, "Filter"); 
            }
            
            myReset.onClick = function () { 
                win.close(3);
            };
            
            win.center();
            var myRet = win.show();
            
            switch(myRet){
                case 1:
                    alert("You clicked OK");
                    processOffer();
                    break;
                case 2:
                    alert("You clicked Cancel");
                    break;
                case 3:
                    alert("You clicked Filter");
                    buildFilterWindow();
                    break;
            }
            
            function buildFilterWindow(){
                alert("buildFilterWindow()");
            }
            
            function processOffer(){
                alert("processOffer()");
            }
            

             

            Hope that helps.

             

            --

            Marijan (tomaxxi)

            http://tomaxxi.com

            • 3. Re: closing a custom window
              csm_phil Level 4

              Hi Marijan,

               

              Thanks for your nice update, here after i will also use your method.

               

              thx

              csm_phil

              • 4. Re: closing a custom window
                bduffy323 Level 1

                Awesome code segment! Not only does it work but I understand HOW it works now. Great post.