Implementing Stationery

Registering with NewtApp

NewtApp will do the registration and unregistration for you. All you do is set the allDataDefs and allViewDefs slot in the base template. The allDataDefs slot contains a frame of dataDefs. Here's an example which holds one dataDef:

{
   |DataDef:Calliope|: GetLayout("dataDef.t"),
}
The allViewDefs slot holds a frame of frames organized by dataDef symbol. Here's an example:

{
   |DataDef:Calliope|: {
      default: GetLayout("viewDef1.t");
      another: GetLayout("viewDef2.t");
   },
}
NewtApp makes registration and unregistration very simple. It is a bit of a problem, however, that although we have constants defined for our dataDef and viewDef symbols, we're not using them in our allDataDefs and allViewDefs slots. Instead, they're duplicated--a maintenance nightmare if we ever change the symbols, and certainly a situation we should try to avoid.

It turns out there is a way to take advantage of our constants. We'll take advantage of the fact that a slot value in the slot editor can be not just a single NewtonScript statement, but a sequence of statements--the value of the sequence is the value of the last statement. Let's look at allDataDefs rewritten:

f := {}; // create an empty frame
         // add a slot to f
f.(kDataDefSym) := GetLayout("dataDef.t");
         // value of sequence is f
f;
And here's how we'd implement allViewDefs in order to take advantage of our constants:

f := {}; // create an empty frame
f.(kDataDefSym).(kViewDef1Sym) :=
   GetLayout("viewDef1.t");
f.(kDataDefSym).(kViewDef2Sym) :=
   GetLayout("viewDef2.t");
        // value of sequence is f
f;

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

Last modified: 1 DEC 1996