home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1999 - Modelworks Software
- // @Created build 290 cm19990420
- // @Modified build 290 cm19990427
-
- /**
- @Tool: columnInsert~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 specified string.
- To use this script first make a selection in the
- starting line at the starting column and select
- to the ending line ending column. Then run the
- script.
- @EndTool:
- @Summary: columnInsert~inserts data in 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 insertData = prompt("Enter data to insert in this coloumn", "");
-
- 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);
-
- editor.replace(insertData, i, start, i, end);
- }
- var start = ColumnToCharacter(endLine, startColumn, tabWidth);
- var end = ColumnToCharacter(endLine, endColumn, tabWidth);
-
- editor.replace(insertData, i, start, i, end);
- editor.select(range.startLineIndex, range.startCharIndex, range.endLineIndex, start + insertData.length);
-
- editor.setActive("Insert Column");
- }
- else
- {
- alert("The starting column of the selection must be \nless than or equal to the ending column of \nthe selection");
- }
- }
- }
-
- 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
-
-