Autocomplete text in MorphX Editor

One useful tool in Dynamics AX MorphX Editor is the Autocomplete function. For example, if you type if and click the Tab Button the if statement autocompletes.

ifScript

Nifty! But what if you want to add your own Autocomplete function: let’s say if you type info and click the Tab Button you want info(StrFmt(“%1”, )); to be inserted.

 

Just add following method to class xppSource

Source info(Source _variable = '')
{
 
    source += @'info(StrFmt("%1", ));';
 
    source += '\n';
    return source;
}

 

Add the following method to class EditorScripts

 

public void template_flow_if(Editor editor)
{
    xppSource xppSource = new xppSource(editor.columnNo());
 
    int currentLine = editor.currentLineNo();
 
    int currentCol = editor.columnNo();
 
    Source template = xppSource.if();
 
 
 
    editor.insertLines(template);
 
    editor.gotoLine(currentLine+1);
 
    editor.gotoCol(currentCol+5);
 
}

 

 

The result will look like this:

infoScript

Hope this helped.