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

  1. !!Script
  2. // Copyright ⌐ 1997-2001 - Modelworks Software
  3.  
  4. /**
  5. @Tool: wrapOutput~breaks long lines into multiple 80 column or less lines. To 
  6. use select one or more lines and then run the script. 
  7. @EndTool: 
  8. @Summary: wrapOutput~breaks long lines into multiple 80 column or less lines
  9. */
  10.  
  11. var gOutput = getOutput("$active");
  12. var gMaxLineLength = 80;
  13. var gWordBreak = " \t";
  14.  
  15. function DoCommand()
  16. {
  17.     var editor = gOutput.getEditor();
  18.     if (editor)
  19.     {    
  20.         var numberOfLines = editor.getLineCount();
  21.         for (var lineIndex = numberOfLines-1; 
  22.             lineIndex >= 0; lineIndex--)
  23.         {     
  24.             var line = editor.copy(lineIndex);
  25.             var newLine = "\n     ";
  26.             
  27.             if (line.length > gMaxLineLength)
  28.             {
  29.                 var array = new Array();
  30.                 
  31.                 array[0] = 0;
  32.                 array[1] = gMaxLineLength;
  33.                 var i = 1;
  34.                 while (line.length > array[i])
  35.                 {
  36.                     var index = LastSpace(line, array[i]);
  37.                     if (index > array[i-1])
  38.                     {
  39.                         var value = line.charAt(index);
  40.                         if (value == ' ' || value == '\t')
  41.                         {
  42.                             array[i] = index + 1;
  43.                         }
  44.                         else
  45.                         {
  46.                             array[i] = index;
  47.                         }
  48.                     }
  49.                     array[i+1] = array[i] + gMaxLineLength;
  50.                     i += 1;
  51.                 }
  52.                 
  53.                 for (j = i - 1; j > 0; j--)
  54.                 {
  55.                     line = replaceInString(line, array[j], 0, newLine);
  56.                 }
  57.                 editor.replace(line, lineIndex);
  58.             }
  59.         }
  60.         
  61.         editor.setActive("Wrap Lines");
  62.     }
  63. }
  64.  
  65. function LastSpace(line, fromIndex)
  66. {
  67.     var toIndex = Math.max(0, fromIndex - gMaxLineLength - 1);
  68.     for (var i = fromIndex; i > toIndex; i--)
  69.     {
  70.         var value = line.charAt(i);
  71.         if (gWordBreak.indexOf(value) > -1)
  72.         {
  73.             return i;
  74.         }
  75.     }
  76.     return -1;
  77. }
  78.  
  79. !!/Script
  80.