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

  1. !!script
  2. //@Created build 475 mg20001218 (Miguel Angel Rojas Gonzalez)
  3.  
  4. var gOutput = getOutput();
  5.  
  6. function DoCommand() 
  7. {    
  8.     var editor = getActiveEditor();
  9.     if ( editor )
  10.     {
  11.         var selection = editor.getSelection();
  12.         var text      = editor.copy( selection );
  13.         
  14.         if ( text.length == 0 )
  15.         {
  16.             return;
  17.         }
  18.         
  19.         var findData = chooseReplaceParameters( "Replace in Selection" );
  20.         
  21.         if ( findData )
  22.         {   
  23.             
  24.             findData.startCharIndex = selection.startCharIndex;
  25.             findData.startLineIndex = selection.startLineIndex;
  26.             
  27.             editor.findNext( findData );
  28.             
  29.             while ( findData && findData.found )
  30.             {
  31.                 if (findData.startCharIndex >= selection.endCharIndex && findData.startLineIndex >= selection.endLineIndex)
  32.                 {
  33.                     break;
  34.                 }
  35.                 else
  36.                 {
  37.                     editor.replace( findData.getReplaceValue(), findData );
  38.                 }
  39.             
  40.                 editor.findNext( findData );
  41.             }
  42.             
  43.             gOutput.clear();
  44.             gOutput.writeLine( "Searching for: '" + findData.key + "', Replacing with: '" + findData.getReplaceValue() + "' whithin: \n\n" + text );
  45.             gOutput.writeLine( "Replace in Selection done");
  46.             
  47.             editor.setActive("Replace in Selection");
  48.         }
  49.     }
  50. }
  51.  
  52. !!/script
  53.  
  54.