TextMate + QuickSilver = Drag & Drop ActionScript imports.

I 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.
Dd Drag Drop 1

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.

Ssp Absolute Path

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 (?-?-?)

Drag

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.

Qscatalog

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.

Possibly related posts:

  1. Better (AS3) imports in TextMate Summary: In which Martin has concocted a hack to make...
  2. Quicksilver actions the easy way Just encountered bliss deep down in the Quicksilver Google Groups...
  3. TextMate theme-switcher script Summary: In which Martin ponders solutions on how to quickly...
  4. Capture key sequences in ActionScript 3. AKA The Konami Comeback. Lately the internet has had a wave of sites using...
  5. ActionScript 3 URL validator class Fairly robust AS3 utility class for evaluating, parsing and tagging...

2 Comments

  1. Rich
    Posted June 19, 2008 at 21:52 | Link

    OK, that’s cool! I had to fix some preference file shenanigans with Quicksilver a while back and haven’t used it much lately. That will change now.

  2. Martin
    Posted July 2, 2008 at 08:47 | Link

    Don’t even get me started on QS. There’s so many cool things you can use this app for.

    Actually; I guess you got me started. Expect a post on QS goodies shortly.

Post a Comment

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

*
*