PeanutTopImpl.mesa; Written by Bill Paxton, February 1983
Last edited by Paxton on April 4, 1983 9:10 am
DIRECTORY
CedarSnapshot USING [CheckpointProc, Register, RollbackProc],
UserExec USING [CommandProc, RegisterCommand],
Process USING [Detach],
Menus USING [ClickProc, MenuProc],
PeanutSendMail,
Spell,
Rope,
PeanutRetrieve,
PeanutWindow,
TiogaMenuOps,
ViewerClasses,
ViewerOps,
VirtualDesktops;
PeanutTopImpl: CEDAR PROGRAM
IMPORTS PeanutWindow, PeanutRetrieve, PeanutSendMail, CedarSnapshot, Process, Spell, Rope, UserExec, TiogaMenuOps, VirtualDesktops, ViewerOps =
BEGIN
NewForm: Menus.MenuProc = {
PeanutSendMail.NewMsgForm[mouseButton, shift, control] };
AnswerMessage: Menus.MenuProc = {
PeanutSendMail.AnswerMsg[mouseButton, shift, control] };
ForwardMessage: Menus.MenuProc = {
PeanutSendMail.ForwardMsg[mouseButton, shift, control] };
SendMessage: Menus.MenuProc = {
PeanutSendMail.SendMsg[mouseButton, shift, control] };
NewMail: Menus.MenuProc = {
PeanutRetrieve.GetNewMsgs[] };
Abort: Menus.MenuProc = {
PeanutWindow.abortFlag ← TRUE };
SaveAll: Menus.MenuProc = {
files: LIST OF Rope.ROPE ← mailFiles;
WHILE files # NIL DO
viewer: ViewerClasses.Viewer ← VirtualDesktops.FindViewer[files.first].viewer;
IF viewer # NIL AND viewer.newVersion THEN {
PeanutWindow.OutputRope["\nSaving "];
PeanutWindow.OutputRope[files.first];
TiogaMenuOps.Save[viewer] };
files ← files.rest;
ENDLOOP;
};
MailFileButton: Menus.ClickProc = {
IF mouseButton=yellow THEN -- open the message file
ViewerOps.OpenIcon[PeanutRetrieve.GetMailViewer[NARROW[clientData]]]
ELSE PeanutRetrieve.CopyMessages[to: NARROW[clientData], delete: mouseButton=blue] };
restartAfterRollback: BOOLFALSE;
PeanutCheckpointProc: CedarSnapshot.CheckpointProc = {
CloseDown[]; restartAfterRollback ← TRUE };
PeanutRollbackProc: CedarSnapshot.RollbackProc = {
IF restartAfterRollback THEN TRUSTED {Process.Detach[FORK StartPeanut[]]}};
BuildPeanut: UserExec.CommandProc = {StartPeanut[]};
CloseDown: PROC = {
PeanutRetrieve.CloseConnection[] };
mailFiles: LIST OF Rope.ROPE;
modes: REF Spell.ModesRecord ← NEW[Spell.ModesRecord];
StartPeanut: PROC = {
files: LIST OF Rope.ROPE;
NullInform: Spell.InformProc = {};
AddName: PROC [fileName: Rope.ROPE] = {
name: Rope.ROPE ← Rope.Substr[fileName, 0, Rope.Find[fileName, "."]];
PeanutWindow.AddButton[name: name, proc: MailFileButton, data: fileName] };
modes.inform ← modes.confirm ← modes.disabled ← never;
modes.timeout ← -1;
modes.defaultConfirm ← FALSE;
IF PeanutSendMail.AuthenticateUser[] THEN
[] ← PeanutRetrieve.NewUser[PeanutSendMail.userRName];
IF PeanutWindow.Create[] THEN { -- created a new one
files ← mailFiles ←
Spell.GetMatchingFileList[unknown: "*.Mail", modes: modes, inform: NullInform];
WHILE files # NIL DO AddName[files.first]; files ← files.rest; ENDLOOP }
ELSE { -- restarting, probably after Rollback; check for new Mail files
IsOld: PROC [name: Rope.ROPE] RETURNS [yes: BOOL] = {
fileList: LIST OF Rope.ROPE ← mailFiles;
WHILE fileList # NIL DO
IF Rope.Equal[name, fileList.first] THEN RETURN [TRUE];
fileList ← fileList.rest;
ENDLOOP;
RETURN [FALSE] };
files ← Spell.GetMatchingFileList[unknown: "*.Mail", modes: modes, inform: NullInform];
WHILE files # NIL DO
IF ~IsOld[files.first] THEN {
PeanutWindow.Destroy[];
[] ← PeanutWindow.Create[];
files ← mailFiles ←
Spell.GetMatchingFileList[unknown: "*.Mail", modes: modes, inform: NullInform];
WHILE files # NIL DO AddName[files.first]; files ← files.rest; ENDLOOP;
EXIT };
files ← files.rest;
ENDLOOP };
};
PeanutWindow.AddCommand[name: "NewMail", proc: NewMail];
PeanutWindow.AddCommand[name: "NewForm", proc: NewForm];
PeanutWindow.AddCommand[name: "Answer", proc: AnswerMessage];
PeanutWindow.AddCommand[name: "Forward", proc: ForwardMessage];
PeanutWindow.AddCommand[name: "Send", proc: SendMessage];
PeanutWindow.AddCommand[name: "Abort", proc: Abort];
PeanutWindow.AddCommand[name: "SaveAll", proc: SaveAll];
UserExec.RegisterCommand["Peanut", BuildPeanut, "For retrieving and sending mail"];
TRUSTED {CedarSnapshot.Register[c: PeanutCheckpointProc, r: PeanutRollbackProc]};
StartPeanut[];
END.