PeanutWindowImpl.mesa; Written by Scott McGregor, February 1983
Last edited by McGregor on February 28, 1983 2:03 pm
DIRECTORY
Icons USING [IconFlavor, NewIconFromFile],
Menus USING [AppendMenuEntry, CreateEntry, CreateMenu, Menu, MenuProc],
PeanutWindow,
Rope USING [Cat, ROPE],
TypeScript USING [Create, PutChar, PutRope, TS],
ViewerOps USING [DestroyViewer, PaintViewer];
PeanutWindowImpl: CEDAR MONITOR
IMPORTS Icons, Menus, Rope, TypeScript, ViewerOps
EXPORTS PeanutWindow =
BEGIN
OutputRope: PUBLIC ENTRY PROC [text: Rope.ROPE] = BEGIN
ENABLE ANY => UNWIND;
IF ~Destroyed[] THEN TypeScript.PutRope[peanutScript, text];
END;
OutputChar: PUBLIC ENTRY PROC [char: CHAR] = BEGIN
ENABLE ANY => UNWIND;
IF ~Destroyed[] THEN TypeScript.PutChar[peanutScript, char];
END;
SetNewMail: PUBLIC ENTRY PROC [newMail: BOOL] = BEGIN
ENABLE ANY => UNWIND;
newMailExists ← newMail;
IF Destroyed[] THEN RETURN;
peanutScript.icon ← IF newMailExists THEN newMailIcon ELSE noMailIcon;
peanutScript.name ← Caption[newMailExists];
ViewerOps.PaintViewer[peanutScript, caption];
END;
AddCommand: PUBLIC ENTRY PROC [name: Rope.ROPE, proc: Menus.MenuProc, data: REF ANYNIL, fork: BOOLTRUE, guarded: BOOLFALSE] = BEGIN
ENABLE ANY => UNWIND;
Menus.AppendMenuEntry[menu, Menus.CreateEntry[name, proc, data, NIL, fork, guarded]];
IF peanutScript#NIL THEN ViewerOps.PaintViewer[peanutScript, all];
END;
Create: PUBLIC ENTRY PROC = BEGIN
ENABLE ANY => UNWIND;
peanutScript ← TypeScript.Create[[name: Caption[newMailExists], icon: IF newMailExists THEN newMailIcon ELSE noMailIcon, column: right, openHeight: 100]];
peanutScript.menu ← menu;
END;
Destroy: PUBLIC ENTRY PROC = BEGIN
ENABLE ANY => UNWIND;
IF ~Destroyed[] THEN ViewerOps.DestroyViewer[peanutScript];
peanutScript ← NIL;
END;
Destroyed: PROC RETURNS [BOOL] = INLINE BEGIN
IF peanutScript=NIL THEN RETURN [TRUE]
ELSE IF peanutScript.destroyed THEN {peanutScript←NIL; RETURN [TRUE]};
RETURN [FALSE];
END;
Caption: PROC [newMail: BOOL] RETURNS [name: Rope.ROPE] = BEGIN
name ← "Peanut";
IF newMail THEN BEGIN
name ← Rope.Cat[name, " -- You have new mail"];
END
ELSE BEGIN
name ← Rope.Cat[name, " -- No new mail"];
END;
END;
peanutScript: TypeScript.TSNIL;
menu: Menus.Menu ← Menus.CreateMenu[];
noMailIcon: Icons.IconFlavor ← Icons.NewIconFromFile["/Indigo/CedarViewers/Peanut/Peanut.icons", 0];
newMailIcon: Icons.IconFlavor ← Icons.NewIconFromFile["/Indigo/CedarViewers/Peanut/Peanut.icons", 4];
newMailExists: BOOLFALSE;
END.