To simplify and bring consistency to code commenting, we use an editor script to add comments. This is a simplified version of what we use internally.
We need to edit a standard class to do this, and since some scripts are better when split into methods, we'll create a new class in order to minimize the number of changes.
Create a new class, ConXppCodeSnippets
, and add the following method:
public static NotesLine commentText() { return strFmt("%1 modification by %4 on %5: ", "Con", currentAOLayer(), curUserId(), date2str(systemDateGet(), 321,2,4,2,4,4)); }
We can also use this in other methods and extend it, so that we can get data from a parameter table. In the EditorScripts
class, create the following method:
public void contoso_comment(Editor editor) { int currentLine = editor.currentLineNo(); int currentCol = editor.columnNo(); str prefix = ""; editor.unmark(); if(currentCol == 0) { currentCol = 4; prefix = strRep(' ', 4); } editor.insertLines(prefix+'// ' + ConXppCodeSnippets::commentText() + ' '), editor.gotoLine(currentLine+2); editor.insertString(strRep(' ', currentCol)); }
Restart AX, and look at the Scripts menu. It has created the Contoso submenu, with Comment as an option.
18.188.139.172