Syntax10.Scn.FntAStampElemsAlloc26 Feb 96iSyntax10b.Scn.FntxY@v MODULE DirElems; (** HM  (mah auto-update)*) IMPORT Viewers, Texts, TextFrames, Oberon, PopupElems, Directories, Display; TYPE Elem* = POINTER TO ElemDesc; ElemDesc* = RECORD (PopupElems.ElemDesc) END; NotifyMsg = RECORD(Display.FrameMsg) END; Frame = POINTER TO RECORD(Display.FrameDesc) elem: Elem END; VAR oldDirNotify: Directories.Notifier; curDirName: ARRAY 32 OF CHAR; PROCEDURE ReadName (t: Texts.Text; pos: LONGINT; VAR name: ARRAY OF CHAR); VAR r: Texts.Reader; ch, stopch: CHAR; i: INTEGER; beg, end, time: LONGINT; BEGIN Texts.OpenReader(r, t, pos); Texts.Read(r, ch); i := 0; IF ch = '"' THEN Texts.Read(r, ch); WHILE ~r.eot & (ch # '"') DO name[i] := ch; INC(i); Texts.Read(r, ch) END ELSE WHILE ~r.eot & (ch > " ") DO name[i] := ch; INC(i); Texts.Read(r, ch) END END; name[i] := 0X; IF name = "^" THEN Oberon.GetSelection(t, beg, end, time); IF time >= 0 THEN ReadName(t, beg, name) END END END ReadName; PROCEDURE SetDirName; VAR i, j: INTEGER; name: ARRAY 256 OF CHAR; d, d0: Directories.Directory; BEGIN d := Directories.Current(); d0 := Directories.Startup(); i := 0; WHILE (d0.path[i] # 0X) & (CAP(d0.path[i]) = CAP(d.path[i])) DO INC(i) END; IF (d0.path[i] = 0X) & ((d.path[i] = 0X) OR (d.path[i] = Directories.delimiter)) THEN IF d.path[i] = Directories.delimiter THEN name[0] := "$"; j := 0; INC (i); REPEAT INC(j); name[j] := d.path[i]; INC(i) UNTIL name[j] = 0X ELSE name := "$" END ELSE COPY(d.path, name) END; i := 0; WHILE name[i] # 0X DO INC(i) END; IF i < 32 THEN COPY(name, curDirName) ELSE curDirName[31] := 0X; j := 31; REPEAT DEC(i); DEC(j); curDirName[j] := name[i] UNTIL j = 1; curDirName[0] := "*" END END SetDirName; PROCEDURE Exec (e: Elem; pos: LONGINT); VAR msg: NotifyMsg; name: ARRAY 256 OF CHAR; BEGIN ReadName(e.menu, pos, name); Directories.Change(name) END Exec; PROCEDURE DirNotify (op: INTEGER; path, name: ARRAY OF CHAR); VAR msg: NotifyMsg; BEGIN IF op = Directories.change THEN SetDirName; Viewers.Broadcast (msg) END; oldDirNotify (op, path, name) END DirNotify; PROCEDURE HandleFrame(f: Display.Frame; VAR msg: Display.FrameMsg); VAR m: TextFrames.UpdateMsg; BEGIN IF msg IS NotifyMsg THEN WITH f: Frame DO TextFrames.NotifyDisplay (Texts.ElemBase(f.elem), TextFrames.replace, Texts.ElemPos(f.elem), Texts.ElemPos(f.elem)+1) END END END HandleFrame; PROCEDURE Handle* (e: Texts.Elem; VAR m: Texts.ElemMsg); VAR e1: Elem; f: Frame; BEGIN WITH e: Elem DO COPY (curDirName, e.name); WITH m: Texts.CopyMsg DO IF m.e = NIL THEN NEW(e1); m.e := e1 END ; PopupElems.Handle(e, m) | m: Texts.IdentifyMsg DO m.mod := "DirElems"; m.proc := "Alloc" | m: PopupElems.ExecMsg DO Exec(e, m.pos) | m: TextFrames.DisplayMsg DO IF ~m.prepare THEN NEW (f); f.X := m.X0; f.Y := m.Y0; f.W := 1; f.H := 1; (* trick (c) mah/cs *) f.handle := HandleFrame; f.elem := e; m.elemFrame := f END; PopupElems.Handle (e, m) ELSE PopupElems.Handle(e, m) END END END Handle; PROCEDURE Alloc*; VAR e: Elem; BEGIN NEW(e); e.handle := Handle; Texts.new := e END Alloc; PROCEDURE Insert*; VAR e: Elem; insert: TextFrames.InsertElemMsg; BEGIN NEW(e); e.handle := Handle; e.small := FALSE; e.menu := TextFrames.Text(""); PopupElems.MeasureMenu(e); insert.e := e; Viewers.Broadcast(insert) END Insert; BEGIN SetDirName; oldDirNotify := Directories.notify; Directories.notify := DirNotify END DirElems.