Доработано:
- Устранено возможное срабатывание индикации синтаксических ошибок в окне кода после обработки блока объявления переменных;
X++:
//AXAligner ver. 1.1 beta (for AX 2009, AX 2012)
//Developed by alex55 (AXforum.info), 23.01.2013
//Home page: axforum.info/forums/showthread.php?t=45984
//Aligns first and second borders from the left for selected block of a code
public void aAXAligner(Editor _editor)
{
#define.EmptyString('')
#define.Space(' ')
#define.LineDelimiter('\n')
#define.FirstColumnNum(1)
#define.OneLine(1)
#define.AllFirstNonSpaceChars('<[^: ]*')
int i;
int leftBorderWidth;
int firstRowLength;
int maxSecondLeftBorderWidth = 0;
int startLine = _editor.selectionStartLine();
int endLine = _editor.selectionEndLine();
int columnNum = _editor.selectionEndCol();
List list = new List(Types::Container);
TextBuffer textBuffer = new TextBuffer();
ListIterator iterator;
void getMaxSecondLeftBorderWidth(str _row)
{
int newRowLength;
int secondLeftBorderWidth;
int rowLength;
;
_row = strltrim(_row);
rowLength = strlen(_row);
textBuffer.setText(_row);
textBuffer.replace(#AllFirstNonSpaceChars, #EmptyString);
newRowLength = strlen(strltrim(textBuffer.getText()));
secondLeftBorderWidth = rowLength - newRowLength;
list.addEnd([secondLeftBorderWidth, rowLength, _row]);
if (secondLeftBorderWidth > maxSecondLeftBorderWidth)
{
maxSecondLeftBorderWidth = secondLeftBorderWidth;
}
}
str alignSecondLeftBorder()
{
int secondLeftBorderWidth;
int rowLength;
str secondLeftBorderString;
str row;
;
[secondLeftBorderWidth, rowLength, row] = iterator.value();
secondLeftBorderString = substr(row, 1, secondLeftBorderWidth);
secondLeftBorderString += strrep(#Space, maxSecondLeftBorderWidth - secondLeftBorderWidth);
return strrep(#Space, leftBorderWidth) + secondLeftBorderString + substr(row, secondLeftBorderWidth + 1, rowLength - secondLeftBorderWidth);
}
str getEditorRow(int _rowNum)
{
_editor.gotoLine(_rowNum);
return _editor.currentLine();
}
void replaceEditorRow(int _rowNum, str _row)
{
_editor.gotoLine(_rowNum);
_editor.gotoCol(#FirstColumnNum);
_editor.deleteLines(#OneLine);
_editor.insertLines(#LineDelimiter);
_editor.gotoLine(_rowNum);
_editor.gotoCol(#FirstColumnNum);
_editor.insertLines(_row);
}
//Fixes editor's errors indication
void refreshEditor()
{
_editor.gotoLine(endLine + 1);
_editor.gotoCol(#FirstColumnNum);
_editor.insertLines(#LineDelimiter);
_editor.gotoLine(endLine + 1);
_editor.deleteLines(#OneLine);
_editor.gotoLine(endLine);
_editor.gotoCol(columnNum);
}
;
if (startLine >= endLine)
{
return;
}
firstRowLength = strlen(getEditorRow(startLine));
leftBorderWidth = firstRowLength - strlen(strltrim(getEditorRow(startLine)));
for (i = startLine; i <= endLine; i++)
{
getMaxSecondLeftBorderWidth(getEditorRow(i));
}
iterator = new ListIterator(list);
i = startLine;
while (iterator.more())
{
replaceEditorRow(i, alignSecondLeftBorder());
iterator.next();
i++;
}
refreshEditor();
}