TextMate + QuickSilver = Drag & Drop ActionScript imports.
by Martin on 18/06/2008I couldn’t possibly code in anything but TextMate. Hell, I even blog from TextMate. And since I’m lazy by nature I wanted a better way to import classes from my class library. The TextMate ActionScript 3 Bundle Simon Gregory offers a nice auto complete functionality that lets you define a list of classes to choose from on triggering.
While this is indeed very nice, the solution is really only suited for your most frequently used classes as putting your entire class library in the list would render it unusable. So something else was needed.
A quick glance shows that the ActionScript 3 bundle also features an import drag command. That is; If you drag and drop an .as file onto an AS3 document it’ll create the import statement for you.

Again; Nice feature, but with two irritating irritating shortcomings; None of which is really the developers fault. First off: Dragging and dropping a file from your library returns the absolute path to the class file. See below.

That’s not what I want. Let’s get to work on that bundle.
First off, locate the drag command within the ActionScript 3 bundle in TextMates bundle editor (?-?-?)

By default it should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # By default this will add an import statement for the dropped file. # For include functionality hold down command when you relase the mouse. extension=${TM_DROPPED_FILE##*.} if [[ "$TM_MODIFIER_FLAGS" == "COMMAND" ]]; then if [[ "$extension" == "mxml" ]]; then echo "//WARNING mxml files should not be used as includes."; fi echo "include "$TM_DROPPED_FILE";" exit 0; fi class=`basename "$TM_DROPPED_FILE" ".as"` class=`basename "$class" ".mxml"` file_path=`dirname "$TM_DROPPED_FILEPATH"` file_path="$file_path/$class" import_path=$(echo "$file_path" | sed -E -e "s#^.*(source|src|test|AS3Lib)/##g" -e 's#/#.#g') echo "import $import_path;" |
What we want to do is change this line
1 | file_path=`dirname "$TM_DROPPED_FILEPATH"` |
to this
1 | file_path=`dirname "${TM_DROPPED_FILEPATH//Users/martinjacobsen/Documents/ActionScript/AS3//}" |
The things to watch here are 1: Change the path to wherever your class library resides. 2: Mind the /’s You need to escape the slashes between folders, and thats how to do it. And 3: Mind the Double-slash at the end. What you’re telling TextMate here is to replace the path to the class library with nothing.
That should fix the path issue. Now for the grand finale. If you’re not already using QuickSilver your Mac is essentially broken, so fix that! The first step is to make sure QS indexes your class library. Go into the preference pane and click Catalog. Add your Class Path under the “Custom” sidebar option.

Now to locate your classes all you have to do is invoke QS, find your file by typing a few letters and then drag it into your ActionScript file. Brilliant?
If that’s not cool, then I don’t know what is. I’d like to find some way to drag a folder and have it import it as package.*; but until I do I’m gonna pretend that I don’t want that because it’s bad OOP.
There are 2 comments in this article: