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

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3. // @Modified build 270 cm19990226 - changed to remove '//' at the begining of each line
  4. // @Modified build 272 cm19990301 - fixed case where the caret is not at the beginning of the line
  5.  
  6. /**
  7. @Tool: unSlashSlashComment~removes Java/JavaScript line comments from 
  8. selected lines. 
  9. @EndTool: 
  10. @Summary: unSlashSlashComment~removes line comments from a selection
  11. */
  12.  
  13. function DoCommand()
  14. {
  15.     var editor = getActiveEditor();
  16.     if (editor)
  17.     {
  18.         var range = editor.getSelection();
  19.         
  20.         // Clear selection
  21.         editor.select(range.startLineIndex, range.startCharIndex, 
  22.             range.startLineIndex, range.startCharIndex);
  23.         
  24.         // Select at lease one line
  25.         if (range.empty())
  26.         {
  27.             range.startCharIndex = 0; // cm19990301
  28.             range.endCharIndex = 0; // cm19990301
  29.             range.endLineIndex = range.startLineIndex + 1;
  30.         }
  31.         
  32.         // Don't include the last line if no characters are selected on the line
  33.         if (range.endCharIndex != 0)
  34.         {
  35.             range.endLineIndex += 1;
  36.         }
  37.  
  38.         var indentLevel = -1;
  39.         var findData = editor.findFirst("[ |\t]*(//)", range.startLineIndex, 0 , true, true, true);
  40.             
  41.         if (findData)
  42.         {
  43.             var foundRange = findData.getSubRange(0);
  44.             if (foundRange.startLineIndex != range.startLineIndex || foundRange.startCharIndex != 0)
  45.             {
  46.                 findData = null;
  47.             }
  48.         }
  49.         
  50.         for (var i = range.startLineIndex; i < range.endLineIndex; i++)
  51.         {
  52.             if (findData)
  53.             {
  54.                 var topRange = findData.getSubRange(0);
  55.                 if (topRange.startLineIndex == i && topRange.startCharIndex == 0)
  56.                 {
  57.                     var slashslashRange = findData.getSubRange(1);
  58.                     if (slashslashRange)
  59.                     {
  60.                         editor.remove(slashslashRange);
  61.                     }
  62.                 }
  63.             }
  64.             findData = editor.findFirst("[ |\t]*(//)", i + 1, 0 , true, true, true);    
  65.         }
  66.         
  67.         range.startCharIndex = 0;
  68.         range.endCharIndex = 0;
  69.         
  70.         editor.select(range);
  71.         editor.setActive(); 
  72.     } 
  73. }
  74.  
  75. !!/Script
  76.