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

  1. !!script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: replaceInOpenDocuments~replaces a findWhat expression with a replaceWith 
  6. value in all open documents. 
  7. @EndTool: 
  8. @Summary: replaceInOpenDocuments~replaces in open documents 
  9. */
  10.     
  11. var output = getOutput();
  12.  
  13. function DoCommand() 
  14. {
  15.   var findParameters = getGlobal("FindParameters", null);
  16.  
  17.   var findData = chooseReplaceParameters("Replace in open windows", 
  18.     findParameters.findWhat,
  19.     findParameters.replaceWith, 
  20.     findParameters.caseSensitive, 
  21.     findParameters.wholeWord, 
  22.     findParameters.regularExpression);
  23.         
  24.   if (findData)
  25.   {   
  26.     findParameters.findWhat = findData.key; 
  27.     findParameters.replaceWith = findData.getReplaceValue();
  28.     findParameters.caseSensitive = findData.caseSensitive;  
  29.     findParameters.wholeWord = findData.wholeWord;  
  30.     findParameters.regularExpression = findData.regularExpression;   
  31.     findParameters.searchDown = findData.searchDown;
  32.     findParameters.updateHistory();
  33.     
  34.     output.clear();
  35.     output.writeLine("Searching for: " + 
  36.       findData.key + ": Replacing with: " + findData.getReplaceValue());
  37.  
  38.     var index = 0;  
  39.     var lineIndex = -1;
  40.     var editor = getEditor(index++);
  41.     while (editor)
  42.     {
  43.       var fileName = editor.path;
  44.  
  45.       findData.startCharIndex = 0;
  46.       findData.startLineIndex = 0;
  47.       
  48.       editor.findNext(findData);
  49.       while (findData && findData.found)
  50.       {
  51.         editor.replace(findData.getReplaceValue(), findData);
  52.  
  53.         var range = findData.range;
  54.           
  55.         // Only print out one message per line
  56.         if (lineIndex != range.startLineIndex)
  57.         {
  58.           lineIndex = range.startLineIndex;
  59.           output.writeMessage(fileName, lineIndex, editor.copy(lineIndex));
  60.         }
  61.  
  62.         editor.findNext(findData);
  63.       }
  64.       lineIndex = -1;
  65.       editor.update();
  66.       editor = getEditor(index++);
  67.     }
  68.     output.writeLine("Replace in open files completed");
  69.   }
  70. }
  71.  
  72. !!/script
  73.  
  74.