-- NutViewerImpl.mesa -- Last edit by -- Maxwell on September 30, 1982 10:35 am -- Willie-Sue, January 21, 1983 8:50 am -- Cattell, June 3, 1983 10:37 am -- Last Edited by: Donahue, May 31, 1983 4:41 pm DIRECTORY Atom, CIFS USING [Error], DB, DBNames, Icons USING [IconFlavor, NewIconFromFile], DBIcons, NutOps, NutViewer, Rope USING [Cat, Equal, Length, ROPE, SkipTo], ViewerOps, VirtualDesktops; NutViewerImpl: CEDAR PROGRAM IMPORTS Atom, CIFS, DB, DBNames, Icons, DBIcons, NutOps, Rope, ViewerOps, VirtualDesktops EXPORTS NutViewer = BEGIN OPEN DB, NutViewer; ROPE: TYPE = Rope.ROPE; -- ****************** setting/getting icons for entities **************** -- works for Entities or Domains acorn: Icons.IconFlavor_ NewIcon["Nut.icons", 3]; SetIcon: PUBLIC PROCEDURE[e: Entity, iconFile: ROPE, fileIndex: CARDINAL] = BEGIN name: ROPE = IF DB.Eq[DomainOf[e], DomainDomain] THEN DB.NameOf[e] ELSE DBNames.EntityToName[e, DB.SegmentOf[e]]; IF DBIcons.IsRegistered[name].file = NIL THEN DBIcons.RegisterIcon[ name, iconFile, fileIndex, TRUE ] END; GetIcon: PUBLIC PROC[e: Entity, seg: Segment _ NIL] RETURNS[icon: Icons.IconFlavor] = BEGIN IF e = NIL THEN RETURN[acorn]; { d: Domain = DomainOf[e]; segment: DB.Segment = IF NutOps.IsSystemDomain[d] THEN seg ELSE DB.SegmentOf[e]; dName: ROPE = NameOf[d]; isTool: BOOL = Rope.Equal[dName, ToolViewer]; eName: ROPE = IF isTool THEN NameOf[e] ELSE DBNames.EntityToName[e, segment]; IF Rope.Equal[dName, "TextViewer"] THEN RETURN[document]; icon _ unInit; icon _ DBIcons.GetIcon[eName, IF isTool THEN tool ELSE unInit ! DBIcons.Failed => CONTINUE]; IF icon # unInit THEN RETURN; icon _ DBIcons.GetIcon[dName, acorn] } END; icons: IconList; IconList: TYPE = LIST OF RECORD[file: ROPE, index: INTEGER, icon: Icons.IconFlavor]; NewIcon: PUBLIC PROC[file: ROPE, index: INTEGER] RETURNS[icon: Icons.IconFlavor _ acorn] = BEGIN ENABLE CIFS.Error => TRUSTED {GOTO notFound}; FOR list: IconList _ icons, list.rest WHILE list # NIL DO IF list.first.index # index THEN LOOP; IF ~Rope.Equal[list.first.file, file] THEN LOOP; RETURN[list.first.icon]; ENDLOOP; icon _ Icons.NewIconFromFile[file, index]; icons _ CONS[[file, index, icon], icons]; EXITS notFound => -- if not given full path name, then try [Indigo]Icons>file BEGIN ENABLE CIFS.Error => TRUSTED {CONTINUE}; IF file.SkipTo[pos: 0, skip: "[/"] # file.Length[] THEN RETURN; --given full path, give up icon _ Icons.NewIconFromFile[Rope.Cat["[Indigo]Icons>", file], index]; icons _ CONS[[file, index, icon], icons]; END; END; -- ****************** converting from viewer to entity **************** ToolViewer: PUBLIC Rope.ROPE _ "ToolViewer"; TextViewer: PUBLIC Rope.ROPE _ "TextViewer"; FindViewerForEntity: PUBLIC PROC[ e: DB.Entity, segment: DB.Segment _ NIL] RETURNS[viewer: Viewer] = BEGIN domain: Domain = DomainOf[e]; dName: ROPE = NameOf[domain]; isText: BOOLEAN = Rope.Equal[dName, TextViewer]; isTool: BOOLEAN = Rope.Equal[dName, ToolViewer]; name: ROPE = NameOf[e]; seg: DB.Segment = IF NutOps.IsSystemDomain[domain] THEN segment ELSE SegmentOf[e]; entity: ROPE = Rope.Cat[Atom.GetPName[seg], "!", DB.NameOf[domain], "!", name]; FindEntity: ViewerOps.EnumProc = { IF v.destroyed THEN RETURN[TRUE]; { eHandle: Entity = V2E[ ViewerOps.FetchProp[ v, $EntityHandle ] ]; -- eName: ROPE = NARROW[ ViewerOps.FetchProp[ v, $Entity ] ]; IF eHandle#NIL AND DB.Eq[eHandle, e] THEN { viewer _ v; RETURN[FALSE] }; -- IF Rope.Equal[ name, eName ] THEN { viewer _ v; RETURN[FALSE] }; IF isText AND v.class.flavor = $Text AND v.name = name THEN { viewer _ v; RETURN[FALSE] }; IF isTool AND v.name = name THEN { viewer _ v; RETURN[FALSE] }; RETURN[ TRUE ] } }; viewer _ NIL; VirtualDesktops.EnumerateViewers[FindEntity]; END; ConvertViewerToEntity: PUBLIC PROC[v: Viewer] RETURNS[e: Entity] = BEGIN name: ROPE = NARROW[ViewerOps.FetchProp[ v, $Entity ]]; IF name # NIL THEN e _ DBNames.NameToEntity[name]; IF e # NIL THEN RETURN; -- make a guess at the entity type SELECT v.class.flavor FROM $Text => { textDomain: Domain; textDomain _ DeclareDomain[TextViewer, $Squirrel ! DB.Error => { textDomain _ NIL; CONTINUE } ]; IF textDomain # NIL THEN RETURN[DeclareEntity[textDomain, v.name]] ELSE RETURN[NIL] }; ENDCASE => { toolDomain: Domain; toolDomain _ DeclareDomain[ToolViewer, $Squirrel ! DB.Error => { toolDomain _ NIL; CONTINUE } ]; IF toolDomain # NIL THEN RETURN[DeclareEntity[toolDomain, v.name]] ELSE RETURN[NIL] }; END; END. Êt˜JšOÏc&œ*œ(œ"œ1œÏk œžœžœžœžœQžœžœ?žœžœžœ žœžœFžœžœžœžœžœžœžœKœ"Ïnœ3Ÿœžœž œžœ žœ žœ žœžœžœžœžœžœžœ˜ŒJšœžœ#žœž˜0JšÍœ3žœžœŸœžœžœžœžœžœžœžœžœžœ8žœ žœžœžœžœžœžœ/žœžœžœ žœœžœžœžœ%žœ žœžœžœ3žœ"žœžœžœžœžœ žœŸœžœžœžœ žœžœ'žœžœžœ žœžœžœ#žœžœžœžœžœžœ žœ$žœžœ žœžœ=žœ"žœFœžœžœžœ žœžœ žœ1žœžœœgžœ$žœžœIœ žœžœ žœžœŸœžœžœ žœžœ žœžœžœ.žœžœ.žœ,žœžœ žœžœ žœžœ%žœKžœ žœžœžœW>œ žœ žœžœžœžœžœžœDœ žœžœžœžœžœžœžœžœžœžœžœžœžœžœ6žœŸœžœžœ žœžœ žœžœ)žœžœžœ%žœžœžœžœ#œžœžœžœžœžœžœžœžœžœ.žœžœžœ žœožœžœžœžœžœžœžœ.žœžœžœ žœžœ˜ê—…—ª$