(Prev Next) Part of UserLand's MIDAS Website. 10/6/97.

Apple Event Interface for External Editing

A protocol that makes it possible to edit text and scripts stored in Frontier's object database using specialized editors such as BBEdit and Script Debugger.

By Dave Winer, UserLand Software, dwiner@well.com

Background

We worked out a protocol for connecting BBEdit to Frontier so that you can use BBEdit to edit the text of any wptext or string object in Frontier's object database. This is an important feature because BBEdit is a much more powerful text editing environment than Frontier is.

Independently, Mark Aldritt of Late Night Software worked out a protocol that's more sophisticated, and as soon as we found out about it, we implemented it in Frontier.

The Late Night connection allows you to edit an AppleScript object in our database using Script Debugger. Again, he has a much richer AppleScript development tool than we do (ours works better with UserTalk, as you might imagine...)

At InternetWorld last week, I talked with Andreas Poliza, the CEO of GoLive Systems, the people who make CyberStudio. We agreed that GoLive would also support this protocol. I agreed to write up a specification.

Discussion

I decided to promote the more sophisticated protocol implemented by Late Night. Both are very easy to implement on the server side, the Late Night protocol is a little more work, but there's no need for a temporary file, and no tables to clean out in the server. It also makes the Apple Event Manager work harder, and may limit the size of objects that can be edited. We'll have to dig a little here...

How it works. The server app sends an Apple Event to the client requesting that it open a new window. The event contains the data to be edited and an id. Open the data in a window, store the id along with the window.

When the user saves the window, send an Apple Event back to the client, requesting that it save the data. Clean the dirty bit on the window. Nothing else changes in your app.

To see a client implementation of this protocol, get the latest version of Frontier, and Cmd-J to suites.odbEditor.editors. When your app supports the protocol we'll create a table like one of these to connect to your editor.

I know that the keys are AppleScript-centric, but they're just identifiers, please look past that. This protocol is general. Since we already have an implementation of this protocol in Late Night's editor, I didn't want to break the connection. I've just documented the protocol implemented by Late Night. We can edit this spec in coordination with Aldritt and anyone else who may have implemented the Late Night spec.

Write an Apple Event handler

Your app must respond to an incoming Apple Event.

The event class is 'edit', the event is 'EDIT'. It takes 7 parameters:

KeyTypeExplanation
'----' The data that's to be edited. If it's a text object, the type is 'TEXT'. If it's an AppleScript, it's a compiled script, binary type, with a subtype of 'scpt'.
'ASwt''TEXT' The new window's title.
'ASid''TEXT' The client's identifier for this object. For Frontier, we send the address of the object being edited. The editor app must save this id and pass it back to the client when the user saves the document. Details in the next section.
'ASnc''bool' Receive close events for this window?
'ASct''bool' Client context? (For AppleScript editors, should the script run in the client's context?)
'ASna''bool' Editor come to front?
'ASro''bool' Read only? (Frontier sets this false.)

When the user saves

When the user saves one of these objects, send an Apple Event back to the app that sent you the 'EDIT' event.

The event class is the creator ID of your app, the event is 'EDsv'.

The direct parameter, key '----', is the data to be saved. It must be of the same type as the '----' parameter of the Apple Event that opened the window.

The second parameter, key 'ASid', is the id passed thru the Apple Event that opened the window.

To see how Frontier handles this event, Cmd-J to system.verbs.traps.asDB.EDsv.

When the user closes the window

When the user closes the window, send an Apple Event back to the app that sent you the 'EDIT' event.

The event class is the creator ID of your app, the event is 'EDcl'.

The direct parameter, key '----', is the id passed thru the Apple Event that opened the window.

To see how Frontier handles this event, Cmd-J to system.verbs.traps.asDB.EDcl.

Pointers

Editing AppleScripts using Script Debugger -- A writeup that explains how Frontier works with Script Debugger, from a user's perspective.

Late Night Software has a page documenting their External Script Editing protocol, the one that this spec is based on.

Comments on the MIDAS mailing list.

Wed, Mar 19, 1997 at 8:17:08 AM by DW


This page was last built with Frontier on a Macintosh on Mon, Oct 6, 1997 at 3:01:27 PM. Thanks for checking it out! Dave