Showing posts with label Editor Script. Show all posts
Showing posts with label Editor Script. Show all posts

Monday, April 26, 2010

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


I have posted a editor script method earlier that can open and browse table for code editor.using below code developer will have ease of opening any object from AX code editor to AOT node

TO USE THIS CODE COPY AND PASTE THE METHOD IN EDITOR SCRIPT CLASS

void AX_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))
break;
}
for (iCopyTo = e.columnNo()+1; iCopyTo <= strLen(selectedLine); iCopyTo++) { curSymbol = subStr(selectedLine, iCopyTo, 1); if (!strAlpha(curSymbol)) break; } selectedLine = (iCopyFrom <> 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();
}
}
}
}
}

Thursday, June 12, 2008

Open table or browse from editor code


Many times Developer needs to open the table or browse while coding. Developer has to go to AOT then search for that table. To ease of this situation by following code developer can easily open the table or browse from Editor windows itself.

Copy paste the following methods in EditorScript Class of axapta
//------------------------
void AX_openTable(Editor e)
{

#AOT
TreeNode tr;
XInfo xInfo = new xInfo();
str selection;
;
selection= strltrim((strrtrim(Editorscripts::getSelectedText_n(e)))); // modified standard method getSelectedText
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
if(tr)
tr.AOTnewWindow();
else
Throw error(strfmt("Table %1 not found",selection));

return;

}

//----------
static str getSelectedText_n(Editor e)
{
int i;
str text;
str line;
int startLine = e.selectionStartLine()+1;
int endLine = e.selectionEndLine()+1;
int startCol = e.selectionStartCol();
int endCol = e.selectionEndCol();

if (startLine == endLine && startCol == endCol)
{
e.firstLine();
while (e.moreLines())
{
text += e.getLine();
e.nextLine();
}
}
else
{
e.firstSelectedLine();
for (i = startLine; i <= endLine; i++)
{
line = e.getLine();
if (i == startLine && i == endLine)
{
line = substr(line, startcol, endCol-startCol);
}
else
if (i == endLine)
{
line = substr(line, 1, endCol-1);
}
else
if (i == startLine)
{
line = strrep(' ', startCol-1)+substr(line, startCol, strlen(line));
}

text += line;
e.nextSelectedLine();
}
}
return text;
}

//---------
To Browse the Table Add
//-------
void AX_browseTable(Editor e)
{

#AOT
TreeNode tr;
TableId TableId;
XInfo xInfo = new xInfo();
str selection;
SysTableBrowser SysTableBrowser;
;
selection= strltrim((strrtrim(Editorscripts::getSelectedText_n(e)))); // modified standard method getSelectedText
tr = TreeNode::findNode(#TablesPath + '\\'+selection);
if(tr)
{
TableId = tablename2id(selection);
if(TableId)
new SysTableBrowser().run(tableID);
}
else
Throw error(strfmt("Table %1 not found",selection));

return;

}

Wednesday, June 11, 2008

Block Comment in axapta Editor Script(class)

To Comment a code axpta in a Block Like
/*
Some Code
*/
Add the Below Code in Editor Scripit Class in Axapta

void AX_BlockComment(Editor e)
{
int FLine,Eline;
int FCol,ECol;


FLine = e.selectionStartLine();
FCol = e.selectionStartCol();

ECol = e.selectionEndCol();
Eline = e.selectionEndLine();
e.unmark();

e.gotoLine(FLine-1);
e.gotoCol(1);
e.insertLines('//'+' Commented by ' + curUserId()+', on '+date2str(today(),123,2,1,3,1,4 ) + ',' +time2str(timeNow(), 1, 2)+'\n');

e.gotoLine(FLine);
e.gotoCol(FCol);
e.insertString('/*');

e.gotoLine(Eline+1);
e.gotoCol(1);
e.insertString('*/');


}