28.10.2006, 16:40 | #1 |
Участник
|
Dynamics AX Geek: Productivity tip: classes EditorScripts & xppSource
Источник: http://AxGeek.spaces.live.com/Blog/c...DB13!139.entry
============== Did you ever notice that little service icon in the Axapta source editor? When you open it, it reveals some tools like commenting a source-block or inserting a template. That can for example be a while() loop or an if() block. It is actually surprisingly easy to hook your own little scripts up to this menu. All you need is a method in Classes\EditorScripts. comments_insertHeader() is one of the standard methods, but you can add your own methods. Use the underscore to define the menu path. Having defined a method you need to add some task. The example I will show here is adding a block to iterate a map. I will add the template to \Classes\xppSource and call it from my EditorScripts method. And that's it. You are ready to use your new tool. This is the template we will build: miMap = new mapIterator(map); miMap.begin(); while (miMap.more()) { miMap.next() } ..and this is how we do it: \Classes\EditorScripts void template_flow_iterateMap(Editor editor) { xppSource xppSource = new xppSource(editor.columnNo()); ; editor.insertLines(xppSource.iterateMap()); } \Classes\xppSource Source iterateMap(Source _mapName = 'map') { str miMapName = "mi"+StrUpr(substr(_mapName,1,1))+substr(_mapName,2,strlen(_mapName)); ; source += strfmt("%1 = new mapIterator(%2);",miMapName,_mapName); source += '\n'; source += this.indent(); source += strfmt("%1.begin();",miMapName); source += '\n'; source += this.indent(); this.while(strfmt("%1.more()",miMapName),strfmt("%1.next()",miMapName)); return source; } Now obvisouly there’s some room for improvement here. We could search the code for defined maps / mapIterator and use those etc. This is just to show how it works in general. ============== Источник: http://AxGeek.spaces.live.com/Blog/c...DB13!139.entry |
|