MODULE; IMPORT Starter, StarterList; IMPORT PaneFrame; IMPORT Pathname; IMPORT VBT; IMPORT Text; IMPORT Fmt; IMPORT Rd; IMPORT Debug; CONST DebugLevel = 90; TYPE Kind = {FromKey, FromPath, FromStarter}; VAR UntNo: INTEGER := 0; UntMu := NEW(MUTEX); PROCEDURE StarterScan Untitled (): TEXT = BEGIN LOCK UntMu DO INC(UntNo); RETURN "Untitled-" & Fmt.Int(UntNo); END; END Untitled; REVEAL T = BRANDED REF RECORD kind: Kind; key: CHAR := '\000'; path: TEXT := NIL; starter: Starter.T := NIL; title: TEXT := NIL; rd: Rd.T := NIL; END; PROCEDUREFromKey (key: CHAR; title: TEXT := NIL): T = BEGIN RETURN NEW(T, kind := Kind.FromKey, key := key, title := title);END FromKey; PROCEDUREFromPath (path: TEXT; title: TEXT := NIL): T = BEGIN RETURN NEW(T, kind := Kind.FromPath, path:=path, title:=title);END FromPath; PROCEDUREFromStarter (s: Starter.T; title: TEXT := NIL): T = BEGIN RETURN NEW(T, kind:=Kind.FromStarter,starter:=s,title:=title);END FromStarter; PROCEDUREDefault (): T = BEGIN RETURN FromStarter(NIL); END Default; PROCEDUREFromRd (rd: Rd.T; s: Starter.T; path, title: TEXT := NIL): T = BEGIN RETURN NEW(T, kind := Kind.FromStarter,starter:=s, path := path, title := title, rd := rd); END FromRd; PROCEDUREGetPath (from: T): TEXT = BEGIN RETURN from.path END GetPath; PROCEDURENewFromStarter (override: Starter.T; p, t: TEXT; paneMan: VBT.T; rd: Rd.T := NIL; s: StarterList.T := NIL): PaneFrame.T = VAR starter := override; title := t; path := p; BEGIN IF override = NIL THEN starter := s.head; END; IF title = NIL THEN title := Untitled(); END; IF path = NIL THEN path := "./"; END; Debug.S("Start frame: Path = " & path, DebugLevel); RETURN starter.new().init(path, title, starter.name, paneMan, starter, rd); END NewFromStarter; PROCEDURENewFromPath (s: StarterList.T; path: TEXT; t: TEXT; paneMan: VBT.T): PaneFrame.T = VAR title := t; cur := s; ext := Pathname.LastExt(path); BEGIN IF title = NIL THEN title := Pathname.Last(path); END; WHILE cur # NIL DO IF cur.tail = NIL OR Text.Equal(cur.head.ext, ext) THEN RETURN NewFromStarter(cur.head, path, title, paneMan); END; cur := cur.tail; END; RETURN NIL; END NewFromPath; PROCEDURENewFromKey (s: StarterList.T; key: CHAR; title: TEXT; paneMan: VBT.T): PaneFrame.T = VAR cur := s; BEGIN WHILE cur # NIL DO IF cur.head.key = key THEN RETURN NewFromStarter(cur.head, NIL, title, paneMan); END; cur := cur.tail; END; RETURN NIL; END NewFromKey; PROCEDURENewPaneFrame (s: StarterList.T; paneMan: VBT.T; from: T): PaneFrame.T = BEGIN CASE from.kind OF | Kind.FromKey => RETURN NewFromKey(s, from.key, from.title, paneMan); | Kind.FromPath => RETURN NewFromPath(s, from.path, from.title, paneMan); | Kind.FromStarter => RETURN NewFromStarter(from.starter, from.path, from.title, paneMan, from.rd, s); END; END NewPaneFrame; PROCEDUREEqual (a, b: T): BOOLEAN = BEGIN RETURN a=b; END Equal; BEGIN END StarterScan.