Code Snippets and Custom Scripts in Flex Builder
Well not exactly in Flex Builder but in Aptana. If you download and install the latest release of Aptana, it features two panels that you can use with your Flex and Actionscript projects. One is called the snippet panel which can provide you with code snippets. One of the snippets I use frequently is ASdoc class header comments. To test it out go to Window > Other Views > Aptana Standard Views and select Snippets. Then in the root of your project folder add a directory called snippets. Create a new regular file in there and name it Asdoc_class.as. Its important to name your file with the actionscript extension. If you’re making a snippet for html name it with the .html file extension. Now open up the file and copy and paste this code in…
/* category: Actionscript name: Asdoc Class Header toolTip: Asdoc Class Header toolbar: true language: text/actionscript icon: com.aptana.ide.snippets/icons/wrap_js_function.png prompt(description): Description of the class prompt(author): Name of the author prompt(date): Date */ /** * ${description} * * @langversion ActionScript 3 * * @author ${author} * @since ${date} */
Alright so you’ll notice that there is a custom comment at the top, the category assigns it to whatever category you want in the snippets panel. If you save the file you can look in the snippets panel and you’ll notice an Actionscript folder. The name, which we named “Asdoc class header” should be referenced in that Actionscript snippet folder. Language is of course whatever language you’re creating the snippet for. The tooltip, toolbar, and icon params I’m figuring are involved with getting it to display a button on the toolbar but I haven’t gotten that to work yet. If anyone can fill in here and help me out with that. And last but not least are the prompts. Each prompt has a parameter and a description. The parameter in the prompt function references the variable in the found in the actual code so when the prompt displays for the description, it gets filled out at the ${description} variable.
As far as ideas go, I’ve created one for getters and setters and for singleton code.
Now one thing to note. Snippets are fairly cool, but that’s all they do. Seriously that’s it. I even wanted to make the description field a little higher in the prompt but no go. But if you want to get really crazy I’d check out the scripts panel. Scripts are way more robust and you can even call snippets through a script, aka calling a snippet through a keyboard command. One of the scripts I created was a simple thing to open a new panel for actionscript help based on the keyword selection in your editor panel.
/* * Menu: Actionscript > Actionscript Help * Toolbar: Header * Key: M3+1 * Kudos: Jody Brewster * OnLoad: main() * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript */ function main() { var sourceEditor = editors.activeEditor; var range = sourceEditor.selectionRange; var deleteLength = range.endingOffset - range.startingOffset; var selection = sourceEditor.source.substring(range.startingOffset,range.endingOffset); webView = views.getView("AS3RefWebView"); webView.showView(true); webView.setTitle("Actionscript Reference"); webView.url = "http://www.google.com/search?hl=en&safe=off&rls=en-us&q=site%3Alivedocs.adobe.com%2Fflash%2F9.0%2FActionScriptLangRefV3%2F++" + selection + "&btnG=Search"; }
So there you go, some new little features that hopefully have opened up some possibilities to you. If you have any snippets or scripts, post a link to them in the comments field so we can all take a look.
Similar Posts
June 11th, 2008 at 2:08 pm
Great tip. Poking around in Eclipse, and can’t find the same snippets functionality. Wondering if you know if the same thing exists for Eclipse? Where would someone look to find if a plug-in like that exists?