Hooray [Flex Builder] Snippets! (Follow-up)

UPDATE: I gave up on using the CFEclipse plugin a while ago mainly due to it’s inoperability in MXML files and have switched to using Sourcemate; The templates feature is pretty much everything i could ask for and it’s loaded with a ton of other great features. With Sourcemate and the Flexformatter, I’m pretty pleased with my IDE setup but I’ve been meaning to check out FDT now that it has progressed significantly.

I really love the CFEclipse snippets feature that I mentioned in my previous post. It is exactly what I’ve been after for quite a while. The snippets are stored as simple XML files in a folder in your workspace, which makes them really easy to edit and move from one workspace to another.

<?xml version="1.0" encoding="utf-8"?>
<snippet filetemplate="false" extension="cfm">
<name>Insert ActionScript Header</name>
<help>Insert top-level ActionScript header.</help>
<starttext>
	<![CDATA[
		//----------------------------------------------------------------------
		//
		//	$${header text}
		//
		//----------------------------------------------------------------------
	]]>
</starttext>
<endtext><![CDATA[]]></endtext>
</snippet>

Oh, and get this! You can specify that a snippet as a class template, and then you can use it to create new files that are pre-filled with the syntax you want. Hot damn! I remember digging through a ton of folders in the FlexBuilder plugin trying to figure out how to customize the default ActionScript class template. The interface for creating a new class from a template is a little strange since you have to browse to the package in which you want to create the class and explicitly specify the class name and the file name. But still…

As far as sharing snippets via SnipEx, it’s not quite what I had hoped for. SnipEx is a ColdFusion application that allows you to share your snippets with others. There is a public repository at http://www.cfsnippets.org/ that you can use if you don’t have access to a ColdFusion server where you can install the application. The CFEclipse plug-in offers an “Export to SnipEx server” option, but it’s not yet compatible with cfsnippets.org. :(

Mrinal Wadhwa and I talked briefly about teaming up and cranking out a bunch of useful Flex Actionscript and MXML snippets and posting them to cfsnippets.org, but the disappointing thing is that I can’t figure out how to pair a remote snippet with an abbreviation the way you can with your local snippets. Because of that, I’m not sure if it’s worth the effort to post to cfsnippets.org, but I’d be happy to zip up my snippets folder and share it with anyone who’s interested.

Perhaps my favorite feature about this plugin is that it intelligently indents multi-line snippets. All other solutions I’ve worked with screwed up the first line if you were trying to indent it at a level other than the one it was created at. Props to CFEclipse for figuring this one out.

The variable support is what other text expander are really lacking, and I’m really impressed with the implementation of it in CFEclipse.

Read more about some of the things you can do with your snippets here.

This entry was posted in Flash. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

6 Comments

  1. Posted April 11, 2009 at 3:48 pm | Permalink

    Maybe you’d loot at FDT (http://fdt.powerflasher.com/) for greater control script editing…

  2. Posted April 12, 2009 at 10:11 pm | Permalink

    What version of FlexBuilder are you using? The text expanding does not work for me at all and if I use the snip tree buttons to insert something the indentation is fubar.

  3. Posted April 13, 2009 at 9:43 am | Permalink

    I had the same problem. You have to customize your Flex Debug/Dev perspective so that the CFEclipse toolbar shows up, and then text expanding will work, which Lee doesn’t mention in his tutorial. There is another step he does mention in the video about associating *.as with the CFML editor (which might actually enable the toolbar for you, I can’t remember). Check out this image.

    And, the indention is definitely screwed up if you insert a snippet by clicking. It took me a while to figure out to always test the snippets with the text expanding.

  4. Ryan Bell
    Posted April 14, 2009 at 9:11 am | Permalink

    I’ll have to check this out. Thanks for sharing!

    It’s a cryin’ shame though in my opinion that NeXTSTEP Services have never quite gotten their due in OS X. In theory, we already have an app that can do what we want (as you said, TextMate), and all we should have to do is say, from somewhere in Flex Builder, “invoke TextMate and run this bundle item against my selected text” and result comes right back into Flex Builder.

    Three problems though:

    1. Apple buried the Services menu, that was top-level in NeXT, under the application menu in OS X, so it’s a pain to get to. They also removed the configuration UI for choosing what services you want available and setting key shortcuts.

    2. TextMate doesn’t provide any Services as far as I can tell. Perhaps because no one knows they’re there or how to use them, thanks to Apple’s decision above.

    3. Java applications like FlexBuilder can’t access Services. Flex Builder > Services is greyed out. Given that Services are implemented with a variation on copy & paste, and you can already copy and paste between Java apps and native apps, this shouldn’t be that hard to support. Apple is already way slow in releasing updated Java Runtimes for OS X; what’s a couple more weeks to make this work?

    For further reading:

    http://www.macobserver.com/columns/whatsnext/articles/102297.shtml
    http://pmougin.wordpress.com/2008/01/28/become-a-mac-os-x-services-ninja/

  5. sideDoor
    Posted January 19, 2010 at 9:04 pm | Permalink

    You’ve mentioned both that you can specify variables to be “filled-in” when inserting a CFEclipse snippet, and using a CFEclipse snippet as a template for an Actionscript Class: would you be so kind as to be more specific with an example, or could you point to some resources explaining the steps – I would be grateful!

    Thanks
    sd

  6. sideDoor
    Posted January 19, 2010 at 9:13 pm | Permalink

    Ok, for anyone needing to know:

    To insert variable prompts into your snippet, you can simply type:

    $${MY VARIABLE NAME}

    …in the position in your snippet code where you need this variable to appear – when inserting the snippet, you’ll be prompted for the variables, etc.

    Thanks!

One Trackback

  1. [...] still searching for a good solution for this in Flash Builder, till now I’ve been using CFEclipse’s SnipTreeView but the problem is it only works with AS3 code and can’t handle MXML. I was so desperate one [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">