-- file: Replace.Mesa
-- edited by Brotz, October 12, 1981 3:24 PM
-- edited by Taft, May 26, 1983 6:11 PM

DIRECTORY
exD: FROM "ExceptionDefs",
inD: FROM "InteractorDefs",
intCommon,
opD: FROM "OperationsDefs",
tsD: FROM "TOCSelectionDefs",
vmD: FROM "VirtualMgrDefs";

Replace: PROGRAM
IMPORTS exD, inD, intC: intCommon, opD, tsD, vmD =

BEGIN

tnp: inD.TOCTextNbrPtr = intC.tocTextNbr;
toc: vmD.TOCHandle = intC.tocTextNbr.toc;
tocIndex: vmD.TOCIndex;
key: CARDINAL;

IF ~tnp.haveToc OR ~intC.cmTextNbr.haveMessage THEN
exD.DisplayExceptionString["No toc or message"L]
ELSE BEGIN
key ← vmD.WaitForLock[toc];
IF tsD.TOCSelectionEmpty[toc, key] THEN
BEGIN
exD.DisplayExceptionString["No message selected"L];
vmD.UnlockTOC[toc, key];
END
ELSE BEGIN
worked: BOOLEAN;
tocIndex ← tsD.LastSelectedEntry[toc, key];
-- inD.IndicateCommandBusy[intC.mailFileCommandHouse];
tsD.DeconsiderAll[tnp, key];
tsD.ResetTOCSelection[toc, key];
worked ← opD.ReplaceMailOperation
[delete: TRUE, toc: toc, msg: intC.cmTextNbr.message, index: tocIndex, key: key];
IF worked THEN
BEGIN
tsD.SetTOCSelection[toc, key, tocIndex];
inD.Consider[tocIndex, tocIndex, tnp, key];
intC.composedMessageEdited ← FALSE;
END
ELSE exD.DisplayExceptionString["Not enough room to perform replace."L];
inD.UpdateTOCThumbLine[tnp, key];
vmD.UnlockTOC[toc, key];
-- inD.IndicateCommandFinished[intC.mailFileCommandHouse];
END;
END;

END. -- of Replace --