home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1999 - Modelworks Software
- // @Created build 285 cm19990331
- // @Modified build 290 cm19990427
-
- /**
- @Tool: columnPaste~replaces the data in the
- current selection from the starting column of the
- selection to the ending column of the selection
- for each line with the contents of the clipboard.
- @EndTool:
- @Summary: columnPaste~paste data to a column
- */
-
- var gOutput = getOutput();
-
- function DoCommand()
- {
- var editor = getActiveEditor();
- if (editor)
- {
- var range = editor.getSelection();
-
- var startLine = editor.copy(range.startLineIndex);
- var endLine = editor.copy(range.endLineIndex);
-
- var tabWidth = editor.tabWidth;
- var startColumn = CharacterToColumn(startLine, range.startCharIndex, tabWidth);
- var endColumn = CharacterToColumn(endLine, range.endCharIndex, tabWidth);
-
- if (startColumn <= endColumn) //cm19990427
- {
- var dataArray = GetDataArray(range.startLineIndex);
-
- for (var i = range.startLineIndex; i < range.endLineIndex; i++)
- {
- var line = editor.copy(i);
- var start = ColumnToCharacter(line, startColumn, tabWidth);
- var end = ColumnToCharacter(line, endColumn, tabWidth);
-
- if (dataArray[i] != null)
- {
- editor.replace(dataArray[i], i, start, i, end);
- }
- else
- {
- editor.remove(i, start, i, end);
- }
- }
- var start = ColumnToCharacter(endLine, startColumn, tabWidth);
- var end = ColumnToCharacter(endLine, endColumn, tabWidth);
-
- if (dataArray[i] != null)
- {
- editor.replace(dataArray[i], i, start, i, end);
- editor.select(range.startLineIndex, range.startCharIndex, range.endLineIndex, start + dataArray[i].length);
- }
- else
- {
- editor.remove(i, start, i, end);
- editor.select(range.startLineIndex, range.startCharIndex, range.endLineIndex, start);
- }
-
- editor.setActive("Paste Column");
- }
- else
- {
- alert("The starting column of the selection must be \nless than or equal to the ending column of \nthe selection");
- }
- }
- }
-
- function GetDataArray(lineIndex)
- {
- var data = Application.getClipboardText();
- var dataArray = new Array();
-
- var startIndex = 0;
- var endIndex = data.indexOf('\r\n');
-
- while (endIndex > -1)
- {
- dataArray[lineIndex] = data.substring(startIndex,endIndex);
-
- startIndex = endIndex + 2;
- endIndex = data.indexOf('\r\n', startIndex);
- lineIndex += 1;
- }
-
- dataArray[lineIndex] = data.substring(startIndex,data.length);
-
- return dataArray;
- }
-
- function CharacterToColumn(line, charIndex, tabWidth)
- {
- var column = 0;
- for (var i = 0; i <= charIndex; i++)
- {
- if (line.charAt(i) == '\t')
- {
- column += tabWidth - (column % tabWidth);
- }
- else
- {
- column += 1;
- }
- }
- return column;
- }
-
- function ColumnToCharacter(line, column, tabWidth)
- {
- var columnCount = 0;
- var length = line.length;
-
- for (var i = 0; i < length; i++)
- {
- if (line.charAt(i) == '\t')
- {
- columnCount += tabWidth - (columnCount % tabWidth);
- }
- else
- {
- columnCount += 1;
- }
-
- if (columnCount >= column)
- {
- return i;
- }
- }
- return length;
- }
-
- !!/Script
-
-