Writing add-ons for ecto
ecto has several built-in add-ons that manipulate text in the active editing area, such as for example, Amazon Helper, Flickr Helper, and Scripts. You can write your own add-on. To explain how to, I figure it's best to use a sample add-on. After all, what's the better way to learn how to write an add-on for ecto3 than to see a working example? I uploaded the source code of the iTunes add-on as a 53.8 KB zip file. The iTunes add-on grabs info of the currently playing song in iTunes and returns it as a formatted string to ecto, which then inserts it into the active editing area.
The zip archive contains an XCode project with everything necessary to have an add-on working. You can work right on top of this file, but you'll have to rename source code files and class names to prevent conflicts (see this blog entry for directions).
The meat of the code is one call the add-on gets from ecto:
- (id)addonRequested:(id)delegate selection:(NSString*)selectedText subaction:(NSString*)subaction
ecto calls the addon with selected text or full text from active text area (depending on a setting you define in the add-on) and a delegate. Once done, you'd call the delegate using the selector 'addonFinished' and a string (return nil to cancel the action). All text should be plain text (in HTML or any of the supported formats). If you require feedback from the user, return an object that instantiates a nib and responds to @selector(view) to return a view for display. If you return an object, the delegate will keep it around for as long the delegate is alive, and send any following addonRequested calls directly to the object. There is no need to manage objects you return. The delegate will release when done. Just make sure not to autorelease it.
The iTunes add-on doesn't use a nib when called by the user (Amazon Helper and Flickr Helper do). It just returns text, so it's the easiest type of add-on. It also offers a preferences view so the user can define settings specific to the add-on (via ecto -> Settings -> Tools & Add-ons).
If you're familiar with Objective-C and Cocoa, the project should be decent study material. If you have questions, pose them in the Developer Forum or contact me directly. I'd be more than happy to provide more info, advice or an example add-on that uses a nib.
Reactions on this post