Friday, 17 October 2014

Open any object from code editor to in AOT node (Editor Script)

Using below code developer will have ease of opening any object from AX code editor to AOT node.
Below image shows how to move in to AOT just by right clicking an object.



And once you click on “OpenInAOT” that particular object pop up. As shown below.


TO GET THIS ADDINS “OPENINAOT” JUST COPY THE CODE AND PASTE IT IN EDITOR SCRIPT CLASS AS A METHOD.


void addIns_OpenInAOT(Editor e)
{
    #AOT
    TreeNode        treeNode;
    FreeText        selectedLine;
    str 1           curSymbol;
    int             iCopyFrom;
    int             iCopyTo;
    Set             selectedNodesSet = new Set(Types::Class);
    SetIterator     setIterator;
    Map             map;

    void add2Set(TreeNodePath _path)
    {
        ;
        treeNode = TreeNode::findNode(_path + #AOTRootPath + selectedLine);
        if (treeNode)
            selectedNodesSet.add(treeNode);
    }
    ;
    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) : '';
    }

    if (selectedLine)
    {
        add2Set(#ExtendedDataTypesPath);
        add2Set(#BaseEnumsPath);
        add2Set(#TablesPath);
        add2Set(#ClassesPath);
        add2Set(#MacrosPath);

        if (selectedNodesSet.elements() == 0)
        {
            add2Set(#SystemFunctionsPath);
            add2Set(#SystemTablesPath);
            add2Set(#SystemTypesPath);
            add2Set(#SystemEnumsPath);
            add2Set(#SystemClassesPath);
            add2Set(#ClassesPath + #AOTRootPath + classStr(Global));
        }

        if (selectedNodesSet.elements() > 0)
        {
            setIterator = new SetIterator(selectedNodesSet);
            setIterator.begin();
            if (selectedNodesSet.elements() == 1)
            {
                treeNode = setIterator.value();
            }
            else
            {
                map = new Map(Types::String, Types::String);
                while (setIterator.more())
                {
                    treeNode = setIterator.value();
                    map.insert(treeNode.treeNodePath(), treeNode.AOTparent().treeNodeName());
                    setIterator.next();
                }
                treeNode = TreeNode::findNode(pickList(map, "Location", "Select element type"));
            }
            if (treeNode && treeNode.treeNodePath() != TreeNode::rootNode().treeNodePath())
            {
                if (SysTreeNode::hasSource(treeNode))
                {
                    if (treeNode.AOTparent().treeNodePath() == #macrosPath && subStr(e.currentLine(), e.selectionStartCol() - 1, 1) != '#')
                        return;
                    treeNode.AOTedit();
                }
                else
                {
                    treeNode.AOTnewWindow();
                }
            }
        } 

No comments:

Post a Comment