Wednesday, December 8, 2004

Code Clips

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


There's a new review of Creator on developer.com written by Dick Wall. A nice write-up.



One minor note:


"Adding a new clip is as simple as putting some code into the copy/paste buffer, then choosing a menu option to add it to the clips using a given name."

Actually, it's as simple as selecting the text in the editor, and dragging it and dropping it on the palette! I've seen a lot of comments on Creator that mention the code clips -- I guess it really addresses a need.



There's a cool, but hidden feature related to code clips: if you surround some text in the code clip with "@", it will be become a parameterized code clip. When you drop the code clip, you get a dialog asking you to submit the values for these parameters.

For example, you might have some code like this in the editor for doing a bundle lookup:


NbBundle.getMessage(this.getClass(), "MyKey")


If you change this into

NbBundle.getMessage(this.getClass(), "@key@")


and drag this on the palette, then the next time you drop the clip you get this dialog:





If you enter say the text "Hello" into the value field and hit OK, the text inserted in the editor
at the clip drop point is:

NbBundle.getMessage(this.getClass(), "Hello")



Unfortunately, there's a bug (fixed in the next patch) which prevents this code from working
correctly with code clips where the parameters are repeated in the code (such as the iterator variable in a for loop), but the fix for that should be available soon.


No comments:

Post a Comment