2 Replies Latest reply on Sep 10, 2014 3:18 PM by tusharde

    Indesign CC HTML Panel Undo Issue

    tusharde

      I know this might be a Extension Builder forum question, but the community there isn't as active. I was hoping someone may have encountered the same issue here.

      I have ported over some panels I created in Configurator for CS6 over to the new HTML based panels in Indesign CC.

      I'm running into some "Undo" issues. My panel has some buttons that are one click solutions. For example my "uppercase" button turns selected text into uppercase. The problem with these buttons is that i cannot undo the script right after I have clicked on the button and the script has executed. The only way i can get it to undo is to CLICK ONCE somewhere else (ideally on the page) in indesign. However, when i have any script that opens a dialog or window, and then executes, the Undo function runs fine. Does anyone know why this may be happening? I do not run into this issue when i run those scripts from the scripts panel or when i had CS6 panel made in Configurator.

       

      Below is a sample JS file for one of those buttons

       

      $._ext_TUC={
          run : function() {
          
              if (parseFloat(app.version) < 6) {
                 main();
              } else {
                 app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Smart Uppercase");
              }
      
      
              function main() {
                 var myObjectList = new Array;
                 if (app.documents.length !=0){
                    if (app.selection.length !=0){
                       for (var i = 0; i < app.selection.length; i++) {
                          switch(app.selection[i].constructor.name) {
                             case "Word":
                             case "Line":
                             case "Paragraph":
                             case "Text":
                                myObjectList.push(app.selection[i]);
                                if (myObjectList.length != 0){
                                   for (var i = 0; i < myObjectList.length; i++) {
                                      findWords(myObjectList[i]);
                                   };
                                }
                                break;
                             case "TextColumn":
                             case "TextFrame":
                             case "Story":
                                myObjectList.push(app.selection[i]);
                                if (myObjectList.length != 0){
                                   for (var k = 0; k < myObjectList.length; k++) {
                                      findParagraphs(myObjectList[k]);
                                   };
                                }
                                break;
                             default:
                                alert("Please select some Text or a Text Frame");
                          }
                       }
      
      
                    } else {
                       alert ("Please select a Text Frame and try again.");
                    }
                 } else {
                    alert ("Please open a document, select an object, and try again.");
                 }
      
      
      
      
                 function findParagraphs(obj) {
                    var numOfParas = obj.paragraphs.length;
      
      
                    for (var p = 0; p < numOfParas; p++) {
                     theParaContent = obj.paragraphs[p].contents;
                     changeCase(theParaContent, obj.paragraphs[p]);
                    }
                 }
      
      
                 function findWords(obj) {
                    theParaContent = obj.contents;
                    changeCase(theParaContent, obj);
                 }
      
      
                 function changeCase(myText, obj) {
                    
                    var theWords = myText.split(" ");
                    var myNewText = "";
                    for (var j = 0; theWords.length > j; j++) {
                       if (!isURL(theWords[j]))
                       {
                         myNewText = myNewText + theWords[j].toUpperCase() + " ";
                       } else {
                          myNewText = myNewText + theWords[j] + " ";
                       }
                    }
                    
                    myNewText = myNewText.substring(0,myNewText.length - 1);
                    obj.contents = myNewText;
      
      
                 }
      
      
                 function isURL(str) {
                    // var patt=/(http(?s)|ftp|www).+?(?=\s)/gi;
                    var patt=/\b(?=(http|https|ftp|www))\w\S*/gi;
                    return patt.test(str);
                 }
      
      
              } // END MAIN FUNCTION
      
          },
      };