home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Misc / replaceInLines.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  3.3 KB  |  99 lines

  1. !!script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: replaceInLines~replaces a findWhat expression with a replaceWith 
  6. value for all lines listed Library/Output/replaceInLines.out file. To use 
  7. first generate a list of lines with a format 
  8. "File "<path>" Line n:" 
  9. in the replaceInLines.out file. Then run this script. 
  10. @EndTool: 
  11. @Summary: replaceInLines~does a replace for specified lines in files 
  12. */
  13.  
  14. var gReplaceInAllSubdirectories = true;
  15. var gReplaceInFileTypes = "*.*";
  16.  
  17. var gOutput = getOutput();
  18.  
  19. function DoCommand() 
  20. {
  21.   var findParameters = getGlobal("FindParameters", null);
  22.  
  23.   var findData = chooseReplaceParameters("Replace in lines", 
  24.     findParameters.findWhat,
  25.     findParameters.replaceWith, 
  26.     findParameters.caseSensitive, 
  27.     findParameters.wholeWord, 
  28.     findParameters.regularExpression);
  29.         
  30.   if (findData)
  31.   {   
  32.     findParameters.findWhat = findData.key; 
  33.     findParameters.replaceWith = findData.getReplaceValue();
  34.     findParameters.caseSensitive = findData.caseSensitive;  
  35.     findParameters.wholeWord = findData.wholeWord;  
  36.     findParameters.regularExpression = findData.regularExpression;   
  37.     findParameters.searchDown = findData.searchDown;
  38.     findParameters.updateHistory();
  39.     
  40.     var findExpression = findParameters.findWhat;
  41.     var caseSensitive = findParameters.caseSensitive;
  42.     var replaceValue = findParameters.replaceWith;
  43.     
  44.     gOutput.clear();
  45.     gOutput.writeLine("Searching for: '" + 
  46.     findData.key + "', Replacing with: '" + findData.getReplaceValue() + "'");
  47.  
  48.     var path = File.getLibraryPath() + "\\Output\\replaceInLines.out";
  49.     var replaceInLinesFileList = openEditor(path, false);
  50.   
  51.     if (replaceInLinesFileList)
  52.     {
  53.       saveAll();
  54.       
  55.       var maxLineIndex = replaceInLinesFileList.getLineCount();
  56.       for (var i = 0; i < maxLineIndex; i++)
  57.       {
  58.         var lineData = replaceInLinesFileList.copy(i);
  59.         var foundPath = searchInString(lineData, '"[^"]*"');
  60.         if (foundPath)
  61.         {
  62.           var path = foundPath.key;
  63.           path = path.substring(1, path.length-1); // stript quotes
  64.           var editor = openEditor(path, false);
  65.           if (editor)
  66.           {
  67.             var foundLine = searchInString(lineData, 'Line[^:]*:');
  68.             if (foundLine && foundLine.key.length > 5)
  69.             {
  70.               var lineIndex = new Number(foundLine.key.substring(4, foundLine.key.length-1)) - 1;
  71.               var string = editor.copy(lineIndex);
  72.               if (string)
  73.               {
  74.                 var found = searchInString(string, findExpression, 0, caseSensitive);
  75.                 if (found)
  76.                 {
  77.                   gOutput.writeLine("Replaced found value in: " + path + " at line: " + lineIndex);
  78.                   var changedString = replaceInString(string, found.value, 
  79.                     found.key.length, replaceValue);
  80.                   
  81.                   editor.replace(changedString, lineIndex);
  82.                 }
  83.               }
  84.               if (!editor.visible)
  85.               {
  86.                 editor.close();
  87.               }
  88.             }
  89.           }
  90.         }
  91.       }
  92.     }
  93.     gOutput.writeLine("Replace in lines completed");
  94.   }
  95. }
  96.  
  97. !!/script
  98.  
  99.