<<-- TEditDocumentsImpl.mesa; Written by S. McGregor>> <<-- Edited by McGregor on March 28, 1983 9:21 am>> <<-- Edited by Paxton on June 2, 1983 10:39 am>> <<-- Edited by Maxwell, January 6, 1983 11:03 am>> -- Edited by Russ Atkinson, April 15, 1983 2:31 pm <> DIRECTORY Atom USING [Gensym, GetPName], Buttons, CedarSnapshot USING [After, Register], CIFS USING [Close, GetFC, Open, OpenFile, read, Error], Convert USING [ValueToRope], Directory USING [Error, GetProperty, LookupUnlimited, RemoveFile, Rename], File USING [Capability, Delete, nullCapability], FileIO USING [OpenFailed], InputFocus USING [GetInputFocus, SetInputFocus], MessageWindow USING [Append, Blink, Clear], NodeProps USING [GetProp, MapProps, PutProp], Process USING [Detach, GetCurrent], PropertyTypes USING [tCreateDate], PutGet USING [FromFile, ToFile, FromRope, ToRope, WriteRopePlain], EditSpanSupport USING [Apply], Rope USING [Cat, Concat, Equal, Find, Flatten, FromRefText, Length, ROPE, Substr, Text], RTFiles USING [IsFileInUse], System USING [GreenwichMeanTime, SecondsSinceEpoch], TextEdit USING [DocFromNode, FromRope, Ref], TextLooks USING [noLooks], TextNode USING [FirstChild, LastLocWithin, LocNumber, Location, LocOffset, LocRelative, LocWithin, Offset, NarrowToTextNode, NodeProps, pZone, Ref, RefTextNode, Root, TypeName], TEditCompile USING [minAvgLineLeading], TEditDocument USING [ForgetViewer, LineTableRec, RecordViewerForRoot, Selection, TEditDocumentData, TEditDocumentDataRec], TEditDocumentPrivate, TEditImpl USING [PaintTEditDocument, TEditNotifyProc], TEditInput USING [FreeTree], TEditInputOps USING [CallWithLocks], TEditLocks USING [Lock, LockDocAndTdd, Unlock, UnlockDocAndTdd], TEditProfile USING [DoList], TEditRefresh USING [ScrollToEndOfSel], TEditScrolling USING [ScrollTEditDocument], TEditSelection USING [Alloc, Free, InputModify, MakeSelection, pSel, sSel, fSel], TEditTouchup USING [fullUpdate], TIPUser USING [InstantiateNewTIPTable, InvalidTable, TIPTable], ViewerClasses USING [DestroyProc, GetProc, InitProc, SaveProc, SetProc, Viewer, ViewerClass, ViewerClassRec], ViewerOps, ViewerTools USING [EnableUserEdits, InhibitUserEdits, SelPos, SelPosRec, TiogaContents, TiogaContentsRec]; TEditDocumentsImpl: CEDAR MONITOR IMPORTS Atom, Buttons, CIFS, CedarSnapshot, Convert, Directory, EditSpanSupport, File, FileIO, InputFocus, MessageWindow, NodeProps, Process, PutGet, Rope, RTFiles, System, TEditDocument, TEditDocumentPrivate, TextEdit, TextNode, TEditImpl, TEditInput, TEditInputOps, TEditLocks, TEditProfile, TEditRefresh, TEditTouchup, TEditScrolling, TEditSelection, TIPUser, ViewerOps, ViewerTools EXPORTS TEditImpl, <> TEditDocument, <> TEditDocumentPrivate <> = BEGIN OPEN TEditDocument, TEditDocumentPrivate; Viewer: TYPE = ViewerClasses.Viewer; ROPE: TYPE = Rope.ROPE; fatalTiogaError: PUBLIC ERROR = CODE ; -- for RETURN WITH ERROR monitor clearing punts InitTEditDocument: PUBLIC ViewerClasses.InitProc = { data: REF ANY _ self.data; self.data _ NIL; InitViewerDoc[self, data] }; InitViewerDoc: PUBLIC PROC [self: Viewer, data: REF ANY] = BEGIN tdd: TEditDocumentData _ NARROW[self.data]; InitTddText: PROC = { IF tdd.text # NIL THEN TEditInput.FreeTree[tdd.text]; tdd.text _ NIL; IF self.name.Length#0 THEN tdd.text _ TextNode.NarrowToTextNode[PutGet.FromFile[self.name ! CIFS.Error => {self.newFile _ TRUE; CONTINUE}]]; IF tdd.text=NIL THEN tdd.text _ TextNode.NarrowToTextNode[TextEdit.DocFromNode[TextEdit.FromRope[""]]] }; InitLineTable: PROC = { IF NodeProps.GetProp[tdd.text, $OpenFirstLevelOnly]#NIL THEN tdd.clipLevel _ 1; tdd.lineTable.lastLine _ 0; tdd.lineTable[0].pos _ [TextNode.NarrowToTextNode[TextNode.FirstChild[tdd.text]], 0] }; IF self.link#NIL THEN BEGIN <<-- make sure another link didn't already init>> <<-- and if so, copy that data>> otherInit: Viewer _ NIL; IF tdd=NIL THEN self.data _ tdd _ NARROW[data]; -- someday I should really find out how to fix this in a less horrible manner [] _ SpinAndLock[tdd, "InitViewerDoc"]; FOR v: Viewer _ self.link, v.link UNTIL v=self DO IF ~v.newVersion THEN {otherInit _ v; EXIT}; ENDLOOP; IF otherInit=NIL THEN InitTddText[] ELSE BEGIN -- somebody else already did the init otherTdd: TEditDocumentData _ NARROW[otherInit.data]; tdd.text _ otherTdd.text; END; InitLineTable[]; END ELSE IF data=NIL THEN BEGIN IF tdd=NIL THEN tdd _ AllocateDataForNewViewer[self]; [] _ SpinAndLock[tdd, "InitViewerDoc"]; InitTddText[]; InitLineTable[]; END ELSE WITH data SELECT FROM d: TEditDocumentData => BEGIN self.data _ tdd _ d; [] _ SpinAndLock[tdd, "InitViewerDoc"]; InitTddText[]; InitLineTable[]; END; root: TextNode.RefTextNode => BEGIN IF tdd=NIL THEN tdd _ AllocateDataForNewViewer[self]; [] _ SpinAndLock[tdd, "InitViewerDoc"]; tdd.text _ root; InitLineTable[]; END; r: ROPE => BEGIN IF tdd=NIL THEN tdd _ AllocateDataForNewViewer[self]; [] _ SpinAndLock[tdd, "InitViewerDoc"]; tdd.text _ TextNode.NarrowToTextNode[ TextEdit.DocFromNode[TextEdit.FromRope[r]]]; InitLineTable[]; END; t: REF TEXT => BEGIN IF tdd=NIL THEN tdd _ AllocateDataForNewViewer[self]; [] _ SpinAndLock[tdd, "InitViewerDoc"]; tdd.text _ TextNode.NarrowToTextNode[ TextEdit.DocFromNode[TextEdit.FromRope[Rope.FromRefText[t]]]]; InitLineTable[]; END; ENDCASE => BEGIN -- bad data IF tdd=NIL THEN tdd _ AllocateDataForNewViewer[self]; [] _ SpinAndLock[tdd, "InitViewerDoc"]; tdd.text _ TextNode.NarrowToTextNode[PutGet.FromRope["*ERROR*"]]; InitLineTable[]; END; RecordViewerForRoot[self,tdd.text]; IF HasBrackets[self.name] THEN ViewerTools.InhibitUserEdits[self] ELSE ViewerTools.EnableUserEdits[self]; Unlock[tdd]; END; HasBrackets: PROC [file: ROPE] RETURNS [BOOL] = { Has: PROC [delim: ROPE] RETURNS [BOOL] = { RETURN [Rope.Find[file, delim] # -1] }; RETURN [Has["/"] OR Has["["] OR Has["<"]] }; AllocateDataForNewViewer: PROC [self: Viewer] RETURNS [tdd: TEditDocumentData] = BEGIN tdd _ TextNode.pZone.NEW[TEditDocumentDataRec]; <<-- for now, just hack in a conservative size line table>> tdd.lineTable _ TextNode.pZone.NEW[LineTableRec[MAX[2, (self.ch/TEditCompile.minAvgLineLeading)+1]] _ [lastLine: 0, lastY: 0, lines: NULL]]; <> self.data _ tdd; END; SaveTEditDocument: PUBLIC ViewerClasses.SaveProc = BEGIN tdd: TEditDocumentData _ NARROW[self.data]; dollarCap: File.Capability _ File.nullCapability; root: TextNode.Ref; file: Rope.Text _ Rope.Flatten[self.name]; -- makes LOOPHOLE to LONG STRING OK dollarFile: Rope.Text _ Rope.Flatten[Rope.Concat[file, "$"]]; IF file.Length = 0 OR file.Equal["No Name"] THEN BEGIN IF ~force THEN BEGIN MessageWindow.Append["Can't SAVE -- no file name!", TRUE]; MessageWindow.Blink[]; RETURN [ok: FALSE]; END; file _ Rope.Flatten[Rope.Concat[Atom.GetPName[Atom.Gensym['F]], ".SaveAllEdits"]]; dollarFile _ Rope.Flatten[Rope.Concat[file, "$"]]; END; IF tdd.readOnly THEN BEGIN MessageWindow.Append["Can't SAVE -- read only document!", TRUE]; MessageWindow.Blink[]; RETURN [ok: FALSE]; END; IF ~force THEN { -- lock so no edits while saving MessageWindow.Clear[]; [] _ SpinAndLock[tdd, "SaveTEditDocument"]; -- may have other operation in progress root _ tdd.text; Unlock[tdd]; -- don't need to keep this locked during rest of Save IF FileIsMoreRecent[root, file] THEN { -- the create date of the file on the disk MessageWindow.Append[Rope.Concat[file," on disk is newer than this one."], TRUE]; MessageWindow.Blink[] }; [] _ TEditLocks.Lock[root, "SaveTEditDocument", read] } ELSE root _ tdd.text; TRUSTED { FOR dollarIndex: NAT IN [0..1000) DO dollarCap _ Directory.LookupUnlimited[ fileName: LOOPHOLE[dollarFile] ! Directory.Error => CONTINUE]; IF dollarCap#File.nullCapability THEN { <> IF RTFiles.IsFileInUse[dollarCap] THEN { dollarCap _ File.nullCapability; dollarFile _ Rope.Flatten[Rope.Cat[file, "$", Convert.ValueToRope[[signed[dollarIndex]]], "$"]]; IF dollarIndex = 999 THEN ERROR; LOOP; }; Directory.RemoveFile[LOOPHOLE[dollarFile], dollarCap]; }; EXIT; ENDLOOP; Directory.Rename[LOOPHOLE[file], LOOPHOLE[dollarFile] ! Directory.Error => CONTINUE]; }; [] _ PutGet.ToFile[file, root ! FileIO.OpenFailed => { IF why=illegalFileName THEN { MessageWindow.Append[file, TRUE]; MessageWindow.Append[" is an illegal file name. Operation aborted."]; MessageWindow.Blink[]; CONTINUE }}]; IF dollarCap#File.nullCapability THEN TRUSTED {Process.Detach[FORK ReclaimDollarFile[dollarCap]]}; IF ~force THEN TEditLocks.Unlock[root]; RETURN [ok: TRUE] END; FileIsMoreRecent: PROC [root: TextNode.Ref, file: ROPE] RETURNS [BOOL] = TRUSTED { <> prop: REF System.GreenwichMeanTime; fh: CIFS.OpenFile; createDate: System.GreenwichMeanTime; fileCap: File.Capability; IF (prop _ NARROW[NodeProps.GetProp[root, $FileCreateDate]]) = NIL THEN RETURN [FALSE]; fh _ CIFS.Open[file, CIFS.read ! CIFS.Error => {CONTINUE}]; IF fh = NIL THEN RETURN [FALSE]; fileCap _ CIFS.GetFC[fh]; CIFS.Close[fh]; Directory.GetProperty[file: fileCap, property: PropertyTypes.tCreateDate, propertyValue: DESCRIPTOR[@createDate, SIZE[System.GreenwichMeanTime]]]; RETURN [System.SecondsSinceEpoch[prop^] < System.SecondsSinceEpoch[createDate]] }; ReclaimDollarFile: PROC [file: File.Capability] = TRUSTED { File.Delete[file ! ABORTED => CONTINUE]; }; nullNode: TextNode.RefTextNode = TextEdit.FromRope[NIL]; SetTEditDocument: ViewerClasses.SetProc = BEGIN KillSelections: PROC [self: Viewer] = { OPEN TEditSelection; <> IF pSel # NIL AND pSel.viewer = self THEN MakeSelection[selection: primary]; IF sSel # NIL AND sSel.viewer = self THEN MakeSelection[selection: secondary]; IF fSel # NIL AND fSel.viewer = self THEN MakeSelection[selection: feedback] }; tdd: TEditDocumentData _ NARROW[self.data]; IF self.destroyed OR tdd = NIL THEN RETURN; IF op#$SelPos AND InputFocus.GetInputFocus[].owner=self THEN InputFocus.SetInputFocus[]; IF op=NIL OR op=$TiogaContents OR op=$TiogaDocument OR op=$KeepRootStyleProps THEN BEGIN rope: ROPE; IF self.link#NIL THEN ERROR; -- not yet implemented [] _ SpinAndLock[tdd, "SetTEditDocument"]; KillSelections[self]; IF op=NIL OR op=$KeepRootStyleProps THEN { root: TextNode.RefTextNode = tdd.text; node: TextNode.RefTextNode = TextNode.NarrowToTextNode[root]; typename: TextNode.TypeName = root.typename; child: TextNode.RefTextNode = IF node=NIL THEN NIL ELSE TextNode.NarrowToTextNode[node.child]; rope _ IF data=NIL THEN "" ELSE NARROW[data]; IF child#NIL AND child.last AND child.child=NIL THEN { -- reuse rather than reallocate RemoveProps: PROC [name: ATOM, value: REF] RETURNS [BOOLEAN] = { IF name#$DocumentLock AND name#$Viewer AND NOT (op=$KeepRootStyleProps AND (name=$Prefix OR name=$Postfix)) THEN NodeProps.PutProp[root, name, NIL]; RETURN [FALSE] }; rootProps: TextNode.NodeProps; <> child^ _ nullNode^; rootProps _ root.props; root^ _ nullNode^; root.props _ rootProps; root.child _ child; child.next _ root; root.last _ child.last _ TRUE; child.rope _ rope; IF op = $KeepRootStyleProps THEN root.typename _ typename; [] _ NodeProps.MapProps[root, RemoveProps, FALSE, FALSE] } ELSE { prefix, postfix: REF; IF op=$KeepRootStyleProps THEN { prefix _ NodeProps.GetProp[root, $Prefix]; postfix _ NodeProps.GetProp[root, $Postfix] }; TEditInput.FreeTree[root]; tdd.text _ TextNode.NarrowToTextNode[ TextEdit.DocFromNode[TextEdit.FromRope[rope]]]; IF op=$KeepRootStyleProps THEN { IF prefix#NIL THEN NodeProps.PutProp[tdd.text, $Prefix, prefix]; IF postfix#NIL THEN NodeProps.PutProp[tdd.text, $Postfix, postfix]; tdd.text.typename _ typename }; } } ELSE IF op=$TiogaContents THEN { info: ViewerTools.TiogaContents _ NARROW[data]; rope _ Rope.Concat[info.contents, info.formatting]; TEditInput.FreeTree[tdd.text]; tdd.text _ TextNode.NarrowToTextNode[PutGet.FromRope[rope]] } ELSE IF op=$TiogaDocument THEN { root: TextNode.RefTextNode _ NARROW[data]; TEditInput.FreeTree[tdd.text]; tdd.text _ root } ELSE ERROR; tdd.lineTable.lastLine _ 0; tdd.lineTable[0].pos _ [TextNode.NarrowToTextNode[TextNode.FirstChild[tdd.text]], 0]; RecordViewerForRoot[self,tdd.text]; self.newVersion _ FALSE; -- clear edited bit IF finalise THEN ViewerOps.PaintViewer[self, all, TRUE, TEditTouchup.fullUpdate]; Unlock[tdd]; END ELSE IF op = $SelPos THEN BEGIN OPEN TEditSelection; IF ~self.iconic THEN BEGIN -- no iconic selections please tSel: TEditDocument.Selection _ TEditSelection.Alloc[]; sel: ViewerTools.SelPos _ NARROW[data]; start, length: INT; [] _ TEditLocks.LockDocAndTdd[tdd, "SetTEditDocument", read]; IF sel=NIL THEN BEGIN IF tdd.tsInfo#NIL THEN { -- for typescripts, NIL => caret at end start _ TextNode.LocNumber[ -- includes 1 for root, so must subtract 1 at: TextNode.LastLocWithin[tdd.text], skipCommentNodes: TRUE]; length _ 0 } ELSE { -- for other text viewers, NIL => entire contents start _ 0; length _ TextNode.LocNumber[ -- includes 1 for root, so must subtract 1 at: TextNode.LastLocWithin[tdd.text], skipCommentNodes: TRUE]-1}; END ELSE { tiogaFile: BOOL _ (NodeProps.GetProp[tdd.text, $FromTiogaFile] = $Yes); start _ sel.start; IF ~tiogaFile THEN start _ start+1; -- hack to compensate for leading CR length _ sel.length }; tSel.start.pos _ TextNode.LocWithin[n: tdd.text, count: start, skipCommentNodes: TRUE]; tSel.end.pos _ TextNode.LocRelative[ location: tSel.start.pos, count: MAX[length-1, 0], skipCommentNodes: TRUE]; TEditLocks.UnlockDocAndTdd[tdd]; tSel.granularity _ IF length=0 THEN point ELSE char; tSel.viewer _ self; tSel.data _ tdd; tSel.insertion _ IF length=0 THEN before ELSE after; tSel.pendingDelete _ TRUE; tSel.looks _ TextLooks.noLooks; TEditSelection.MakeSelection[new: tSel]; TEditSelection.Free[tSel]; TEditRefresh.ScrollToEndOfSel[self, FALSE]; END; END ELSE IF op = $ReadOnly THEN BEGIN self.tipTable _ readonlyTIP; tdd.readOnly _ TRUE; END ELSE IF op = $ReadWrite THEN BEGIN self.tipTable _ tiogaTIP; tdd.readOnly _ FALSE; END ELSE ERROR; END; GetTEditDocument: ViewerClasses.GetProc = BEGIN tdd: TEditDocumentData = NARROW[self.data]; IF op=NIL THEN { node: TextNode.RefTextNode = TextNode.NarrowToTextNode[tdd.text.child]; IF node#NIL AND node.last AND node.child=NIL THEN -- simple case of only one node RETURN [node.rope]; RETURN [PutGet.WriteRopePlain[tdd.text]] }; IF op = $TiogaContents THEN { contents, formatting: ROPE; dataLen, count: INT; [dataLen, count, contents] _ PutGet.ToRope[tdd.text]; formatting _ Rope.Substr[base: contents, start: dataLen, len: count-dataLen]; contents _ Rope.Substr[base: contents, start: 0, len: dataLen]; RETURN [TextNode.pZone.NEW[ViewerTools.TiogaContentsRec _ [contents, formatting]]] }; IF op = $SelChars THEN BEGIN OPEN TEditSelection; rope: ROPE; -- hack to fix compiler problem DoSelChars: PROC [root: TextEdit.Ref, tSel: Selection] = { SelConcat: PROC [node: TextNode.RefTextNode, start, len: TextNode.Offset] RETURNS [stop: BOOLEAN] = { rope _ IF rope = NIL THEN Rope.Substr[node.rope, start, len] ELSE Rope.Cat[rope, "\n", Rope.Substr[node.rope, start, len]]; RETURN [FALSE] }; IF tSel.viewer # NIL AND tSel.granularity # point THEN EditSpanSupport.Apply[[tSel.start.pos, tSel.end.pos], SelConcat]; IF rope=NIL THEN rope _ "" }; TEditInputOps.CallWithLocks[DoSelChars, read]; RETURN[rope]; END ELSE IF op = $SelPos THEN BEGIN OPEN TEditSelection; sel: ViewerTools.SelPos _ TextNode.pZone.NEW[ViewerTools.SelPosRec]; DoSelPos: PROC [root: TextEdit.Ref, tSel: Selection] = { sel.start _ TextNode.LocNumber[at: tSel.start.pos, skipCommentNodes: TRUE]; sel.length _ TextNode.LocOffset[ loc1: tSel.start.pos, loc2: tSel.end.pos, skipCommentNodes: TRUE] }; TEditInputOps.CallWithLocks[DoSelPos, read]; RETURN[sel]; END ELSE ERROR; END; DestroyTEditDocument: ViewerClasses.DestroyProc = { ForgetViewer[self]; -- this also fixes up the Root => Viewer mapping if necessary IF self.link # NIL THEN RETURN; -- linked, so not finished with document yet TRUSTED {Process.Detach[FORK CleanupAfterDestroy[self, self.name, NARROW[self.data]]] }}; <> CleanupAfterDestroy: PROC [self: Viewer, file: ROPE, tdd: TEditDocument.TEditDocumentData] = { root: TextNode.Ref; IF tdd = NIL THEN RETURN; -- anybody remember why this is here (SM)? [] _ SpinAndLock[tdd, "DestroyTEditDocument"]; root _ tdd.text; IF self.newVersion AND ~self.saveInProgress AND file # NIL THEN RecordUnsavedDocument[file, root] ELSE TEditInput.FreeTree[root]; Unlock[tdd] }; unlocked: CONDITION; SpinAndLock: PUBLIC ENTRY PROC [tdd: TEditDocumentData, who: ROPE, interrupt, defer: BOOL _ FALSE] RETURNS [ok: BOOL] = TRUSTED BEGIN ENABLE UNWIND => NULL; myProcess: PROCESS = LOOPHOLE[Process.GetCurrent[]]; IF myProcess#tdd.lockProcess THEN BEGIN IF interrupt THEN { IF defer AND tdd.interrupt > 0 THEN RETURN [FALSE]; tdd.interrupt _ tdd.interrupt+1 }; WHILE tdd.lock>0 DO WAIT unlocked; ENDLOOP; tdd.lockProcess _ myProcess; tdd.who _ who; -- save the first guy who got the lock IF interrupt THEN tdd.interrupt _ tdd.interrupt-1; END; tdd.lock _ tdd.lock+1; RETURN [TRUE]; END; Unlock: PUBLIC ENTRY PROC [tdd: TEditDocumentData] = TRUSTED { ENABLE UNWIND => NULL; IF tdd.lockProcess # Process.GetCurrent[] THEN ERROR; IF (tdd.lock _ tdd.lock-1) = 0 THEN BROADCAST unlocked }; ReloadTipTable: PUBLIC PROC = BEGIN newTIP: TIPUser.TIPTable _ ReloadTable[tiogaTIP, "TiogaTIP", "Tioga.tip"]; IF newTIP#NIL THEN ChangeTipTables[tiogaClass.tipTable _ tiogaTIP _ newTIP, FALSE]; END; ReloadReadonlyTipTable: PUBLIC PROC = BEGIN newTIP: TIPUser.TIPTable _ ReloadTable[readonlyTIP, "ReadonlyTiogaTIP", "ReadonlyTioga.tip"]; IF newTIP # NIL THEN ChangeTipTables[readonlyTIP _ newTIP, TRUE]; END; readonlyTIP: TIPUser.TIPTable; tiogaTIP: PUBLIC TIPUser.TIPTable; ChangeTipTables: PROC [newTIP: TIPUser.TIPTable, readonly: BOOL] = { changeTip: PROC [v: Viewer] RETURNS [BOOL _ TRUE] = { IF v.class.flavor = $Text THEN { tdd: TEditDocumentData _ NARROW[v.data]; IF tdd # NIL AND tdd.readOnly = readonly THEN v.tipTable _ newTIP } ELSE IF ViewerOps.IsClass[v, $Container] THEN { ViewerOps.EnumerateChildren[v, changeTip]; }; }; ViewerOps.EnumerateViewers[changeTip] }; ReloadTable: PUBLIC PROC [oldTIP: TIPUser.TIPTable, profileKey, default: ROPE] RETURNS [newTIP: TIPUser.TIPTable] = { ok: BOOL _ TRUE; AddTable: PROC [r: ROPE] = { bad: BOOLEAN _ FALSE; t: TIPUser.TIPTable; msg: ROPE; IF ~ok THEN RETURN; IF Rope.Equal[r,"default",FALSE] THEN { TEditProfile.DoList["", AddTable, default]; RETURN }; t _ TIPUser.InstantiateNewTIPTable[r ! CIFS.Error => { bad _ TRUE; msg _ Rope.Concat["Cannot read TIP table file: ", r]; CONTINUE}; TIPUser.InvalidTable => { bad _ TRUE; msg _ Rope.Concat["Error(s) saved on TIP.Errors for: ", r]; CONTINUE}]; IF bad THEN { ok _ FALSE; MessageWindow.Append[msg, TRUE]; RETURN }; IF newTIP=NIL THEN { newTIP _ t; RETURN }; FOR x: TIPUser.TIPTable _ newTIP, x.link UNTIL x=NIL DO FOR y: TIPUser.TIPTable _ t, y.link UNTIL y=NIL DO IF x # y THEN LOOP; ok _ FALSE; MessageWindow.Append[Rope.Concat["Loop in TIP table layers caused by ", r], TRUE]; RETURN; ENDLOOP; ENDLOOP; FOR x: TIPUser.TIPTable _ newTIP, x.link UNTIL x.link=NIL DO REPEAT FINISHED => BEGIN newTIP.mouseTicks _ MIN[t.mouseTicks, newTIP.mouseTicks]; x.opaque _ FALSE; x.link _ t; END; ENDLOOP; }; TEditProfile.DoList[profileKey, AddTable, default]; IF NOT ok AND oldTIP=NIL THEN { -- try the default by itself ok _ TRUE; TEditProfile.DoList["", AddTable, default] }; }; CheckFilesAfterRollback: PROC [when: CedarSnapshot.After] = { <> Check: ViewerOps.EnumProc --PROC [v: Viewer] RETURNS [BOOL _ TRUE]-- = { tdd: TEditDocument.TEditDocumentData; IF v.class.flavor # $Text THEN RETURN [TRUE]; -- only interested in text viewers tdd _ NARROW[v.data]; IF tdd = NIL THEN RETURN [TRUE]; IF v.name.Equal["No Name"] THEN RETURN [TRUE]; IF NOT FileIsMoreRecent[tdd.text, v.name] THEN RETURN [TRUE]; MessageWindow.Append[Rope.Concat["Loading newer version of ", v.name], TRUE]; ViewerOps.RestoreViewer[v]; -- reload the file RETURN [TRUE] --continue enumeration }; IF when=checkpoint THEN RETURN; -- only do this after return from Rollback ViewerOps.EnumerateViewers[Check]; -- Check each top level viewer }; tiogaClass: ViewerClasses.ViewerClass _ NEW[ViewerClasses.ViewerClassRec _ [ paint: TEditImpl.PaintTEditDocument, bltContents: top, -- use blt to copy screen contents to top of viewer when change dimensions notify: TEditImpl.TEditNotifyProc, modify: TEditSelection.InputModify, init: InitTEditDocument, set: SetTEditDocument, get: GetTEditDocument, save: SaveTEditDocument, destroy: DestroyTEditDocument, scroll: TEditScrolling.ScrollTEditDocument, menus: LIST[$tiogaBasicMenu, $tiogaPlacesMenu, $tiogaLevelsMenu] <<-- tipTable set below>> ]]; ReloadTipTable[]; ReloadReadonlyTipTable[]; ViewerOps.RegisterViewerClass [$Text, tiogaClass]; TRUSTED {CedarSnapshot.Register[r: CheckFilesAfterRollback]}; <<[] _ Buttons.Create[info: [name: "New"], proc: NewButton, fork: FALSE];>> <> <<>> <<[] _ Buttons.Create[info: [name: "Open"], proc: OpenButton];>> END.