Using Editor Scripts
Editor Scripts is the class that is responsible for displaying the scripts options and taking actions based on your selection. You can customize this Editorscripts class to add or change your customizations, and this would be the topic of this post…………..
Fig .1(refer to the image below) Scripts in X++ Editor Window.
Let us try to add an simple option to it, say a change log which will insert a comment line with the current user name and date stamp, something like this…….
//Modified by Kamal on 04/11/06
Let this appear as direct submenu of Scripts, all you need to do to add is create a new method in the editor scripts class. The name of the method has to be the name as you wanted it in the Scripts menu. An important aspect while creating your method is you must have a parameter of type editor. So the method should be typically like this…
Void modifyComment(editor e)
The parameter e received as parameter has several methods and functions to help you identify the current cursor position in the editor, the current line number ….. and much more. I leave it to you to explore further. For our case we have to insert the comment in the cursor position so all we have to do is form a string in the required pattern and then insert it. The code would look something like this…
void modifyComment(editor e)
select firstonly name from userInfo where userInfo.id == curuserid();
insertString = ‘//Modified by ‘ + userInfo.name + ‘ on ‘ + date2str(systemdateget(), 123, 2, 3, 3, 3, 4);
Just compile and go ahead, our new scripts menu will list our option also along with the others available.
Note : if you want to get your option under any of the available option then you will have to prefix the submenu name with your method name using an underscore. Say we want to put our option under the already existing comment options then our method name would be something like this
void comments_modifyComment(editor e)
I have developed a simple editor script that will help to insert and remove block comments, something like
You can download it from Axapatapedia from the following link
There is also one more article about editor scripts in Axaptapedia check out