Customizing MorphX using EditorScripts Class

Most IDEs have some cool build-in tools to help you write faster and more efficient code, and MorphX is no different. In case you hate repetitive typing as much as I do, here is a quick tweak that can help.

There are a couple of ways to add functionality to the MorphX Editor, and the easiest and fastest way is by adding a new method to the Class EditorScripts in the AOT.

Every new Method in the class can be called from the Editor by Right Click > Scripts.

MSDYNAX EditorScripts Comment

So let’s write a very basic Method, just to get an idea of what we can do with this Class. This method will comment the line in which the cursor is, or the highlighted lines in the code.

In the AOT go to Classes-EditorScripts and create a new Method which will look something like this:

private void method1()
{
}

Please note the name convention: pcoNewNode is the new node under the Scripts menu and everything after the underscore is the node under pcoNewNode. The parameter _editor is just our Editor instance.

First we want to get where the line number where the code highlighting starts and where it ends. Next, we deselect the highlighted text and for each line we write in the first position the string “//”.

public void pcoNewNode_CommentScript(Editor _editor)
{
    //getting the line number of the start and end of the highlithing
    int startLine = _editor.selectionStartLine();
    int endLine   = _editor.selectionEndLine();
    int i;
 
    //unmark the highlighted text
    _editor.unmark();
 
    //for every line
    for (i = startLine; i <= endLine; i++)
    {
        //put the cursor on that line number
        _editor.gotoLine(i);
        //put it in the first position (column) of that line
        _editor.gotoCol(1);
        //insert the string
        _editor.insertString('//');
    }
}

This is a very easy and fun way of customizing MorphX, because all you have to do is write good old  X++ code.

 

Posted in Tools and tagged , , .

Leave a Reply

Your email address will not be published. Required fields are marked *