-- ViewerNut.mesa
-- Registers three classes of viewers so they can be 'stored' in the data base.
-- The variables given are reset whenever the data base is opened.

-- Last modified by:
  -- John Maxwell on:  July 16, 1982 1:02 pm.
  -- Willie-Sue Haugeland on: July 28, 1982 11:01 am

DIRECTORY
  DBView USING [
    AttLoHiList, Attribute, Domain, Entity, PropertyLoHiList, Relation, Relship, Version],
  Icons USING [IconFlavor],
  Rope USING [ROPE],
  ViewerClasses USING [Viewer];
  
ViewerNut: DEFINITIONS =
  BEGIN
  OPEN DBView;
  
  ROPE: TYPE = Rope.ROPE;
  Viewer: TYPE = ViewerClasses.Viewer;
  iconAttribute: Attribute; -- so the Palm displayer can access it.
  
  -- ***************** Data Schema for Viewers *******************
  -- NOTE: There is no notion of versions in this implementation!
  -- If a viewer already exists with the entity's name, ViewerNut will flash it.
  -- If the entity is a TextViewer, ViewerNut open a Viewer on the file.
  -- If the entity is a ToolViewer, ViewerNut will load its implementor.
  -- **********************************************************
  
  FindViewer: PROCEDURE[e: Entity] RETURNS[v: Viewer];
  ConvertViewer: PROCEDURE[v: Viewer] RETURNS[e: Entity];
  -- guesses at an appropriate entity for the given viewer.
  
  RegisterTool: PROCEDURE[name, impl, instructions: ROPE ← NIL];
  -- name = name of viewer (as given at the top of the viewer).
  -- implementor = name of bcd.
  -- instructions = human readable instructions of how to 
  -- get the tool (where the DF file is, what to load, etc).
  
  -- ***************** icon management *******************
  
  SetDomainIcon: PROCEDURE[d: Domain, iconFile: ROPE, fileIndex: INTEGER];
  SetEntityIcon: PROCEDURE[e: Entity, iconFile: ROPE, fileIndex: INTEGER];
  NewIcon: PROCEDURE[file: ROPE, index: INTEGER] RETURNS[Icons.IconFlavor];
  GetIcon: PROCEDURE[e: Entity] RETURNS[Icons.IconFlavor];
  
  -- ***************** useful utility routines *******************
  
  GetEntity: PROCEDURE[d: Domain, name: ROPE ← NIL, init: PropertyLoHiList←NIL, version: Version ← NewOrOld]
    RETURNS[e: Entity];
  -- creates a new unique entity if name = NIL
  -- if there isn't an entity named 'name', creates a new one
  
  DeclareRelship: PROCEDURE[r: Relation, init: AttLoHiList ← NIL, version: Version ← NewOrOld] 
    RETURNS[Relship];
   -- If version = NewOnly, creates a new relship (NonKey)
   -- If version = OldOnly, returns the first relship that qualifies (Key)
   -- If version = NewOrOld, will use the first relship if it exists; else it creates a new one (Key)
       
  ExtractName: PROCEDURE[name: ROPE] RETURNS[ROPE];
  -- extracts the name of an entity from the defaultLabel of a CreateProc
  
  StartTrap: PROCEDURE; -- called to initialize variables
  
  END..