AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX: Программирование
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.01.2013, 22:27   #5  
alex55 is offline
alex55
MCTS
MCBMSS
 
224 / 145 (5) +++++
Регистрация: 13.02.2007
Адрес: Москва
Доработано:
- Устранено возможное срабатывание индикации синтаксических ошибок в окне кода после обработки блока объявления переменных;

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();
}
Теги
ax2009, ax2012, ax3.0, ax4.0, tools, x++, законченный пример, инструменты, полезное, форматирование кода

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Размер шрифта в окне редактора кода Jox DAX: Администрирование 3 09.11.2022 11:49
Удобство чтения кода - залог и определенная гарантия его работоспособности sukhanchik DAX: Программирование 29 11.04.2013 10:52
Скрипт для переноса данных Ax3.0 (Oracle) - Ax2009 (MSSQL) someOne DAX: Программирование 2 14.06.2011 14:53
axforum blogs: О заполнении Наименования и Кода номенклатуры в печатной форме Накладной (Ax2009 ru7) Blog bot DAX Blogs 0 07.06.2011 09:11
проблема с настройкой штрихового кода Nic DAX: Функционал 4 27.12.2004 09:04

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 19:24.