-- File: NutViewerPrivateImpl.mesa
-- Contents: Access to nutList
-- Created by: Rick & Willie-Sue on July 8, 1982
-- Last edited by:
-- Rick Cattell on July 5, 1983 5:00 pm
-- Willie-Sue on January 21, 1983 8:56 am
-- Jim Donahue, March 22, 1983 12:17 pm
DIRECTORY
Atom USING [GetPName],
DB,
Nut,
NutViewer,
Rope,
ViewerClasses USING[Viewer],
ViewerOps,
VirtualDesktops USING[EnumerateViewers];
NutViewerPrivateImpl: CEDAR MONITOR
IMPORTS DB, Rope, ViewerOps, VirtualDesktops, Atom
EXPORTS NutViewer =
BEGIN OPEN Nut;
Viewer: TYPE = ViewerClasses.Viewer;
tiptoe: PUBLIC BOOLEAN ← FALSE; -- TRUE when want as few db accesses as possible
-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FindViewer: PUBLIC ENTRY PROC
[ type: Nut.NutType, domain: DB.Domain, eName: Rope.ROPE, seg: DB.Segment]
RETURNS[Viewer] =
BEGIN
entity: ROPE = Rope.Cat[ Atom.GetPName[seg], "!", DB.NameOf[domain], "!", eName ];
FOR nL: LIST OF Viewer ← GetNutList[], nL.rest UNTIL nL=NIL DO
typeProp: REF ANY = ViewerOps.FetchProp[ nL.first, $NutType ];
nutType: Nut.NutType = IF typeProp = NIL THEN displayer
ELSE NARROW[typeProp, REF Nut.NutType]^;
IF nutType # type THEN LOOP;
IF NOT Rope.Equal[entity, NARROW[ ViewerOps.FetchProp[nL.first, $Entity]]] THEN LOOP;
IF nL.first.destroyed THEN LOOP;
RETURN[nL.first];
ENDLOOP;
RETURN[NIL];
END;
FindSpawned: PUBLIC ENTRY PROC[v: Viewer] RETURNS[Viewer] =
BEGIN
IF v = NIL THEN RETURN[NIL];
{ spawn: Viewer = NARROW[ ViewerOps.FetchProp[ v, $LastSpawned ], Viewer ];
IF spawn = NIL OR spawn.destroyed THEN RETURN[ NIL ];
IF ViewerOps.FetchProp[spawn, $Frozen] = NIL THEN RETURN[ spawn ];
RETURN[ NIL ] }
END;
SetSpawned: PUBLIC ENTRY PROC[parent, spawned: Viewer] =
BEGIN
IF parent = NIL THEN RETURN;
ViewerOps.AddProp[ parent, $LastSpawned, spawned ];
IF spawned # NIL THEN ViewerOps.AddProp[ spawned, $WhoSpawnedMe, parent ];
END;
GetNutList: INTERNAL PROC RETURNS[nL: LIST OF Viewer] =
BEGIN
enum: ViewerOps.EnumProc =
{ name: ROPE = NARROW[ViewerOps.FetchProp[v, $Entity]];
IF name # NIL THEN nL← CONS[v, nL];
RETURN[TRUE] };
VirtualDesktops.EnumerateViewers[enum];
END;
END.