home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / COLUMNCOPY.SCRIPT < prev    next >
Encoding:
Text File  |  1999-04-27  |  2.7 KB  |  104 lines

  1. !!Script
  2. // Copyright ⌐ 1999 - Modelworks Software
  3. // @Created build 285 cm19990331
  4. // @Modified build 290 cm19990427
  5.  
  6.  
  7. /**
  8. @Tool: columnCopy~copies the data from the 
  9. current selection from the starting column of the
  10. selection to the ending column of the selection 
  11. for each line to the clipboard.
  12. To use this script first make a selection in the 
  13. starting line at the starting column and select 
  14. to the ending line ending column. Then run the 
  15. script.
  16. @EndTool: 
  17. @Summary: columnCopy~copies a column of data
  18. */
  19.  
  20. var gOutput = getOutput();
  21.  
  22. function DoCommand()
  23. {
  24.     var editor = getActiveEditor();
  25.     if (editor)
  26.     {   
  27.         var range = editor.getSelection();
  28.         
  29.         var startLine = editor.copy(range.startLineIndex);
  30.         var endLine = editor.copy(range.endLineIndex);
  31.         
  32.         var tabWidth = editor.tabWidth;
  33.         var startColumn = CharacterToColumn(startLine, range.startCharIndex, tabWidth);
  34.         var endColumn = CharacterToColumn(endLine, range.endCharIndex, tabWidth);
  35.         if (startColumn <= endColumn) //cm19990427
  36.         {
  37.             var data = "";
  38.             for (var i = range.startLineIndex; i < range.endLineIndex; i++)
  39.             {
  40.                 var line = editor.copy(i);
  41.                 var start = ColumnToCharacter(line, startColumn, tabWidth);
  42.                 var end = ColumnToCharacter(line, endColumn, tabWidth);
  43.                 data += line.substring(start, end) + '\r\n';
  44.                 
  45.             }
  46.             var start = ColumnToCharacter(endLine, startColumn, tabWidth);
  47.             var end = ColumnToCharacter(endLine, endColumn, tabWidth);
  48.             data += endLine.substring(start, end);
  49.             
  50.             Application.setClipboardText(data);
  51.             
  52.             editor.setActive("Copy Column");
  53.         }
  54.         else
  55.         {
  56.             alert("The starting column of the selection must be \nless than or equal to the ending column of \nthe selection"); 
  57.         }
  58.     }
  59. }
  60.  
  61. function CharacterToColumn(line, charIndex, tabWidth)
  62. {
  63.     var column = 0;
  64.     for (var i = 0; i <= charIndex; i++)
  65.     {
  66.         if (line.charAt(i) == '\t')
  67.         {
  68.             column += tabWidth - (column % tabWidth);
  69.         }
  70.         else
  71.         {
  72.             column += 1;
  73.         }
  74.     }
  75.     return column;
  76. }
  77.  
  78. function ColumnToCharacter(line, column, tabWidth)
  79. {
  80.     var columnCount = 0;
  81.     var length = line.length;
  82.     
  83.     for (var i = 0; i < length; i++)
  84.     {
  85.         if (line.charAt(i) == '\t')
  86.         {
  87.             columnCount += tabWidth - (columnCount % tabWidth);
  88.         }
  89.         else
  90.         {
  91.             columnCount += 1;
  92.         }
  93.         
  94.         if (columnCount >= column)
  95.         {
  96.             return i;
  97.         }
  98.     }
  99.     return length;
  100. }
  101.  
  102. !!/Script
  103.  
  104.