-- File: WalnutNuts.mesa
-- Contents: Interface for Nut Procs for displaying msgs & msgsets.
-- Created by: Willie-Sue Haugeland, March 15, 1983
-- Last edited by:
-- Willie-Sue on: March 16, 1983 4:32 pm
-- Donahue, May 27, 1983 11:46 am
-- Cattell, June 8, 1983 3:54 pm

DIRECTORY
Buttons,
Menus USING [Menu],
Nut,
NutViewer USING[ SetIcon ],
Rope,
Runtime USING [IsBound],
WalnutSendMail,
WalnutDB,
WalnutDisplayerOps,
WalnutWindow,
ViewerOps USING [CreateViewer, SetMenu],
ViewerClasses;

WalnutNuts: CEDAR PROGRAM
IMPORTS
Nut, NutViewer, Rope, Runtime, WalnutDisplayerOps,
WalnutSendMail, WalnutDB, WalnutWindow,
ViewerOps
=

BEGIN OPEN WalnutDB, WalnutWindow, WalnutDisplayerOps;

----------------------------
MsgDisplayerCreate: Nut.CreateProc =
{ name: ROPE;

IF nutType=editor THEN
RETURN[WalnutSendMail.BuildSendViewer[paint: FALSE, iconic: FALSE]];

  name← eName.Substr[0, eName.Find[" $ "] + 3];
  name← name.Cat[eName.Substr[eName.Find["@"]+1, 9]];

  v← ViewerOps.CreateViewer[flavor: $Text,
  info: [name: name, column: column, icon: WalnutWindow.msgIcon,
    scrollable: TRUE, iconic: FALSE]];
ViewerOps.SetMenu[ v, msgMenu ] };

MsgDisplayer: Nut.DisplayProc = { DisplayMsgInViewer[e, newV]};

MsgEdit: Nut.EditProc = { };

MsgSetDisplayerCreate: Nut.CreateProc =
BEGIN
 msgSet: WalnutDB.MsgSet = WalnutDB.NameToEntity[MsgSetDomain, eName, OldOnly];

IF msgSet = NIL THEN RETURN[NIL];
IF (v← DisplayMsgSet[msgSet]) # NIL THEN RETURN[NIL]; -- already displayed

v← BuildMsgSetDisplayer[msgSet, eName];
END;

MsgSetDisplayer: Nut.DisplayProc =
 { DisplayMsgSetInViewer[e, newV]};

RegisterNutProcs: PROC =
BEGIN OPEN WalnutWindow;
TRUSTED {IF ~Runtime.IsBound[Nut.Register] THEN RETURN};
NutViewer.SetIcon[ WalnutDB.MsgDomain, "/Indigo/Cedar/Walnut/Walnut.icons", 2 ];
NutViewer.SetIcon[ WalnutDB.MsgSetDomain, "/Indigo/Cedar/Walnut/Walnut.icons", 1 ];
 Nut.Register[ domain: "Msg", segment: $Walnut,
     display: MsgDisplayer, create: MsgDisplayerCreate];

 Nut.Register[domain: "MsgSet", segment: $Walnut,
     display: MsgSetDisplayer, create: MsgSetDisplayerCreate];
END;

DeregisterNutProcs: PROC =
BEGIN
TRUSTED {IF ~Runtime.IsBound[Nut.Register] THEN RETURN};
 Nut.DeRegister[$Walnut, "Msg"];
 Nut.DeRegister[$Walnut, "MsgSet"];
END;

TRUSTED {
IF Runtime.IsBound[WalnutDisplayerOps.DisplayMsgInViewer] THEN RegisterNutProcs[] };
END.