Routing Formats

Routing Formats--The Frame and Text DataTypes

There is a routing format already created for the frame dataType: protoFrameFormat. You can use this proto with slight modification; just add a symbol slot and register it as a viewDef for your dataDef symbol.

We will see how to do this by implementing a standard transport in our application. Let's add Beam support to the Bookstore application. A QuickTime movie of this example is available.

1. Modify the allViewDefs of the Bookstore application to add the protoFrameFormat viewDef.

f := {};
f.(kBookDataDefSym).(kBookEditorViewDefSym) :=
   GetLayout("BookEditorViewDef.t");
f.(kBookDataDefSym).myFrameFormat :=
   {
      _proto: protoFrameFormat,
      symbol: 'myFrameFormat,
   };
f;
If you build and download, you'll find that Beam is now enabled for Books. In fact, so is Mail (see FIGURE 12.9). This happens because protoFrameFormat specifies not only that it can provide a frame dataType, but also that it can provide text.

FIGURE 12.9 : Action picker after protoFrameFormat is registered.



Note:In order to create a routing format that just does frames and not text, override the dataTypes slot of protoFrameFormat:
{
_proto: protoFrameFormat,
dataTypes: ['frame],
}


The text of a routing format is provided by its TextScript method. The default version of this just sends the TextScript message to the associated dataDef. All you need to do is make sure that your dataDef has a TextScript method.

2. Let's add a TextScript method to the bookstore dataDef (a QuickTime movie of this example is available):

func(item, reserved)
begin
   local t := "";
   local e := item.body;

   // set the string t to a value based on slots
   // from item.body, a book
   t := "Author: " & e.author & $\n;
    t := t & "Title: " & e.title & $\n;
   if e.acquireDate then
       t := t & 
         "Acquired on " &
         LongDateStr(e.acquireDate,
         kFormatDefault) & $\n;
   if e.numberInStock then
      t := t &
      "Number in stock: " & 
      NumberStr(e.numberInStock) & $\n;
   return t;
end
FIGURE 12.10 shows the result.

FIGURE 12.10 : Mail slip in Bookstore application.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996