Показать сообщение отдельно
Старый 05.01.2010, 19:16   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Kashperuk Ivan: Editor script for simplifying the search in AOT
Источник: http://kashperuk.blogspot.com/2010/0...search-in.html
==============

When doing code refactoring, or when investigating a particular class or form to understand the functionality behind it, it is often handy to search for variables used in its methods, looking at where and how each variable is used.

It is tedious to manually go through the steps of copying the name of the variable into the clipboard, opening up the parent class/form, opening up the AOT Find dialog for it, pasting the variable name into the Selected Text field and pressing Find now.

I have automated these steps, putting the code into an editor script.

You can download the xpo, which contains the EditorScripts class with the additional method, by following this link.

Now you should be able to very easily and quickly find the required code.

The code of the editor script:

X++:
/// <summary>
/// Editor script for finding all occurrences of the selected text in the parent node of the selected method
/// </summary>
/// <param name="e">
/// Reference to the AX editor
/// 
/// <remarks>
/// 2010-01-05, ivanv
/// </remarks>
void addIns_FindAllOccurrencesInNode(Editor e)
{
    #AOT
    TreeNode    treeNode;
    FreeText    selectedText;

    FreeText GetSelectedTextFromEditor(Editor _e)
    {
        str 1       curSymbol;
        int         iCopyFrom;
        int         iCopyTo;
        FreeText    _selectedLine;
        ;
        if (_e.markMode() != MarkMode::NoMark && _e.selectionStartCol() != _e.selectionEndCol())
        {
            _selectedLine = strLRTrim(subStr(_e.currentLine(), _e.selectionStartCol(), _e.selectionEndCol() - _e.selectionStartCol()));
        }
        else
        {
            _selectedLine = _e.currentLine();
            for (iCopyFrom = _e.columnNo()+1; iCopyFrom >= 0; iCopyFrom--)
            {
                curSymbol = subStr(_selectedLine, iCopyFrom, 1);
                if (!strAlpha(curSymbol) && curSymbol != '_')
                    break;
            }
            for (iCopyTo = _e.columnNo()+1; iCopyTo <= strLen(_selectedLine); iCopyTo++)
            {
                curSymbol = subStr(_selectedLine, iCopyTo, 1);
                if (!strAlpha(curSymbol) && curSymbol != '_')
                    break;
            }
            _selectedLine = (iCopyFrom < iCopyTo) ? subStr(_selectedLine, iCopyFrom + 1, iCopyTo - iCopyFrom - 1) : '';
        }
        return _selectedLine;
    }

    void FindLinesContainingSelectedText(FreeText   _selectedLine)
    {
        Args                args = new Args(formstr(SysAOTFind));
        FormRun             sysAOTFindFormRun;
        FormStringControl   containingTextCtrl;
        FormButtonControl   findNowBtnCtrl;
        ;

        sysAOTFindFormRun = classFactory.formRunClass(args);
        sysAOTFindFormRun.init();
        sysAOTFindFormRun.run();

        // Set the text to find
        containingTextCtrl = sysAOTFindFormRun.design().controlName(identifierStr(ContainingText));
        containingTextCtrl.setFocus();
        containingTextCtrl.pasteText(_selectedLine);

        sysAOTFindFormRun.detach();

        // Launch the search process
        findNowBtnCtrl = sysAOTFindFormRun.design().controlName(identifierStr(FindNow));
        findNowBtnCtrl.clicked();
    }
    ;

    selectedText = GetSelectedTextFromEditor(e);
    if (selectedText)
    {
        // Find the currently open method node
        treeNode = TreeNode::findNode(e.path());
        // Find the parrent node of the method
        treeNode = TreeNode::findNode(xUtilElements::getNodePathRough(xUtilElements::parentElement(xUtilElements::findTreeNode(treeNode))));
        if (treeNode)
        {
            treeNode.AOTnewWindow();

            FindLinesContainingSelectedText(selectedText);
        }
    }
}
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
За это сообщение автора поблагодарили: alex55 (5).