<> <> <> <> <> <<(removed use of long names to access *.tip)>> <> <> <<>> DIRECTORY Buttons USING [ButtonProc, Create], Convert USING [RopeFromInt], FS USING [Create, Error, GetName, nullOpenFile, Open, OpenFile], InputFocus USING [GetInputFocus, SetInputFocus], Menus, -- USING lots MessageWindow USING [Append, Clear], NodeProps USING [GetProp, MapProps, PutProp], Process USING [Detach, GetCurrent], PutGet USING [FromFileC, ToFileC, FromRope, ToRope, WriteRopePlain], EditSpanSupport USING [Apply], Rope USING [Cat, Concat, Equal, Flatten, FromRefText, Length, ROPE, SkipTo, Substr], 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, TEditDocumentPrivateExtras USING [], 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], TiogaMenuOps, -- exports tiogaMenu TIPUser USING [InstantiateNewTIPTable, InvalidTable, TIPTable], ViewerBLT USING [ChangeNumberOfLines], ViewerOps USING [EnumerateChildren, PaintHint, PaintViewer, RegisterViewerClass, SetMenu], ViewerClasses USING [BltRule, DestroyProc, GetProc, InitProc, SaveProc, SetProc, Viewer, ViewerClass, ViewerClassRec], ViewerClassesExtras USING [SaveAborted], ViewerTools USING [EnableUserEdits, --InhibitUserEdits,-- SelPos, SelPosRec, TiogaContents, TiogaContentsRec], VirtualDesktops USING [EnumerateViewers]; TEditDocumentsImpl: CEDAR MONITOR IMPORTS Buttons, Convert, EditSpanSupport, FS, InputFocus, Menus, MessageWindow, NodeProps, Process, PutGet, Rope, TEditDocument, TEditDocumentPrivate, TextEdit, TextNode, TEditImpl, TEditInput, TEditInputOps, TEditLocks, TEditProfile, TEditRefresh, TEditTouchup, TEditScrolling, TEditSelection, TIPUser, ViewerBLT, ViewerClassesExtras, ViewerOps, ViewerTools, VirtualDesktops EXPORTS TEditImpl, TEditDocument, TEditDocumentPrivate, TEditDocumentPrivateExtras, TiogaMenuOps SHARES Menus, ViewerClasses = BEGIN OPEN Menus, TEditDocument, TEditDocumentPrivate, ViewerClasses; fatalTiogaError: PUBLIC ERROR = CODE ; -- for RETURN WITH ERROR monitor clearing punts InitTEditDocument: PUBLIC InitProc = { data: REF ANY _ self.data; self.data _ NIL; InitViewerDoc[self, data] }; InitViewerDoc: PUBLIC PROC [self: Viewer, data: REF ANY] = BEGIN InitViewerDocInternal[self: self, file: FS.nullOpenFile, data: data]; END; <> InitViewerDocInternal: PUBLIC PROC [self: Viewer, file: FS.OpenFile, data: REF ANY] = BEGIN tdd: TEditDocumentData _ NARROW[self.data]; InitTddText: PROC = { IF tdd.text # NIL THEN TEditInput.FreeTree[tdd.text]; tdd.text _ NIL; IF file=FS.nullOpenFile THEN { IF self.file#NIL THEN file _ FS.Open[self.file ! FS.Error => CONTINUE]; }; IF file#FS.nullOpenFile THEN { self.file _ FS.GetName[file].fullFName; tdd.text _ TextNode.NarrowToTextNode[PutGet.FromFileC[file ! FS.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.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]; <> ViewerTools.EnableUserEdits[self]; Unlock[tdd]; END; 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]]; IF self.column#static AND self.parent=NIL THEN ViewerOps.SetMenu[self, tiogaMenu, FALSE]; self.data _ tdd; END; number: INT _ 0; SaveTEditDocument: PUBLIC SaveProc = { tdd: TEditDocumentData _ NARROW[self.data]; root: TextNode.Ref; name: ROPE _ self.file; errorMessage: ROPE _ NIL; IF name.Length = 0 THEN { IF ~force THEN { ERROR ViewerClassesExtras.SaveAborted["no file name!"]; }; name _ Rope.Flatten[Rope.Cat[ "File-", Convert.RopeFromInt[number _ number + 1], ".SaveAllEdits"]]; }; IF tdd.readOnly THEN { ERROR ViewerClassesExtras.SaveAborted["read only document!"]; }; 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 [] _ TEditLocks.Lock[root, "SaveTEditDocument", read]; } ELSE root _ tdd.text; <> { ENABLE FS.Error => { errorMessage _ error.explanation; CONTINUE }; file: FS.OpenFile ~ FS.Create[name: RemoveVersionNumber[name], keep: 2]; newFile: ROPE ~ FS.GetName[file].fullFName; newName: ROPE ~ RemoveVersionNumber[newFile]; [] _ PutGet.ToFileC[file, root]; FOR v: Viewer _ self, v.link DO v.name _ newName; v.file _ newFile; IF v.link = NIL OR v.link = self THEN EXIT; ENDLOOP; }; <<>> <> IF ~force THEN TEditLocks.Unlock[root]; IF errorMessage#NIL THEN ERROR ViewerClassesExtras.SaveAborted[errorMessage]; }; RemoveVersionNumber: PROC[name: ROPE] RETURNS[ROPE] = { RETURN[name.Flatten[start: 0, len: name.SkipTo[0, "!"]]]; }; FileIsMoreRecent: PUBLIC PROC [root: TextNode.Ref, file: Rope.ROPE] RETURNS [BOOL] = TRUSTED { <> RETURN [FALSE]; }; nullNode: TextNode.RefTextNode = TextEdit.FromRope[NIL]; SetTEditDocument: SetProc = BEGIN KillSelections: PROC [self: ViewerClasses.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.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 ~(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: 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.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.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: 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.file, NARROW[self.data]]] }}; <> CleanupAfterDestroy: PROC [self: Viewer, file: Rope.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] }; ChangeMenu: PROC [viewer: Viewer, subMenu: MenuEntry] = { menu: Menus.Menu _ viewer.menu; found: BOOLEAN _ FALSE; numLines: Menus.MenuLine = Menus.GetNumberOfLines[menu]; newLines: Menus.MenuLine _ numLines; FOR i: Menus.MenuLine IN [1..numLines) DO -- see if already showing the submenu IF Rope.Equal[Menus.GetLine[menu,i].name, subMenu.name] THEN { -- yes, so remove it FOR j: Menus.MenuLine IN (i..numLines) DO Menus.SetLine[menu, j-1, Menus.GetLine[menu, j]]; ENDLOOP; <> newLines _ newLines-1; found _ TRUE; EXIT }; ENDLOOP; IF ~found THEN { -- add it. do insertion sort to get it in the right place GoesBefore: PROC [m1, m2: MenuEntry] RETURNS [BOOL] = { Priority: PROC [m: MenuEntry] RETURNS [INTEGER] = { <> <> RETURN [SELECT TRUE FROM Rope.Equal[m.name, "Find"] => 1, Rope.Equal[m.name, "FirstLevelOnly"] => 0, ENDCASE => -1 -- unknown menu goes at bottom -- ] }; RETURN [Priority[m1] > Priority[m2]] }; newLast: Menus.MenuLine = MIN[numLines, LAST[Menus.MenuLine]]; newLines _ newLines+1; <> FOR i: Menus.MenuLine IN [1..numLines) DO IF GoesBefore[subMenu, Menus.GetLine[menu, i]] THEN { -- put it here FOR j: Menus.MenuLine DECREASING IN (i..newLast] DO Menus.SetLine[menu, j, Menus.GetLine[menu, j-1]]; ENDLOOP; Menus.SetLine[menu, i, subMenu]; found _ TRUE; EXIT }; ENDLOOP; IF ~found THEN Menus.SetLine[menu, newLast, subMenu]; }; <> <> ViewerBLT.ChangeNumberOfLines[viewer, newLines]; }; LevelMenu: PUBLIC Menus.MenuProc = { ChangeMenu[NARROW[parent], levelMenu] }; FindMenu: PUBLIC Menus.MenuProc = { ChangeMenu[NARROW[parent], findMenu] }; unlocked: CONDITION; SpinAndLock: PUBLIC ENTRY PROC [tdd: TEditDocumentData, who: Rope.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] = { SELECT v.class.flavor FROM $Text => { tdd: TEditDocumentData _ NARROW[v.data]; IF tdd.readOnly=readonly THEN v.tipTable _ newTIP }; $Container => ViewerOps.EnumerateChildren[v, changeTip]; ENDCASE }; VirtualDesktops.EnumerateViewers[changeTip] }; ReloadTable: PUBLIC PROC [oldTIP: TIPUser.TIPTable, profileKey, default: Rope.ROPE] RETURNS [newTIP: TIPUser.TIPTable] = { ok: BOOL _ TRUE; AddTable: PROC [r: Rope.ROPE] = { bad: BOOLEAN _ FALSE; t: TIPUser.TIPTable; msg: Rope.ROPE; IF ~ok THEN RETURN; IF Rope.Equal[r,"default",FALSE] THEN { TEditProfile.DoList["", AddTable, default]; RETURN }; t _ TIPUser.InstantiateNewTIPTable[r ! FS.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 ~ok AND oldTIP=NIL THEN { -- try the default by itself ok _ TRUE; TEditProfile.DoList["", AddTable, default] }; }; tiogaClass: ViewerClass _ NEW[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 <<-- tipTable set below>> ]]; tiogaMenu: PUBLIC Menus.Menu _ Menus.CreateMenu[]; findMenu, levelMenu, lineMenu: PUBLIC MenuEntry; --preSave: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreSave]; preReset: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreReset]; --preClear: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreClear]; preStore: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreStore]; --preLoadPrevious: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreLoadPrevious]; --preGet: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreGet]; --preGetImpl: REF Menus.ClickProc = NEW[Menus.ClickProc _ PreGetImpl]; <<-- first row>> Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "Clear", proc: Clear --, guarded: TRUE, documentation: preClear--]]; Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "Reset", proc: Reset, guarded: TRUE, documentation: preReset]]; Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "Get", proc: Get --, guarded: TRUE, documentation: preGet--]]; Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "GetImpl", proc: GetImpl --,guarded: TRUE, documentation: preGetImpl--]]; Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "PrevFile", proc: PreviousFile --,guarded: TRUE, documentation: preLoadPrevious--]]; Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "Store", proc: Store, guarded: TRUE, documentation: preStore]]; Menus.AppendMenuEntry[menu: tiogaMenu, entry: Menus.CreateEntry[name: "Save", proc: Save --, guarded: TRUE, documentation: preSave--]]; Menus.AppendMenuEntry[tiogaMenu, Menus.CreateEntry["Time", Time]]; Menus.AppendMenuEntry[tiogaMenu, Menus.CreateEntry["Split", Split]]; Menus.AppendMenuEntry[tiogaMenu, Menus.CreateEntry["Places", FindMenu]]; Menus.AppendMenuEntry[tiogaMenu, Menus.CreateEntry["Levels", LevelMenu]]; <<-- build the places menu>> Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["Reselect", Reselect], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["PrevPlace", JumpToPrevious], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["Normalize", Normalize], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["Position", Position], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["Def", FindDef], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["Word", FindWord], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["Find", Find], 1]; findMenu _ Menus.GetLine[tiogaMenu, 1]; Menus.SetLine[tiogaMenu, 1, NIL]; <<-- build the levels menu>> Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["AllLevels", AllLevels], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["FewerLevels", FewerLevels], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["MoreLevels", MoreLevels], 1]; Menus.InsertMenuEntry[tiogaMenu, Menus.CreateEntry["FirstLevelOnly", FirstLevelOnly], 1]; levelMenu _ Menus.GetLine[tiogaMenu, 1]; Menus.SetLine[tiogaMenu, 1, NIL]; ---- Menus.ChangeNumberOfLines[tiogaMenu, 1]; -- only show the top level to start ReloadTipTable[]; ReloadReadonlyTipTable[]; ViewerOps.RegisterViewerClass [$Text, tiogaClass]; [] _ Buttons.Create[info: [name: "New"], proc: NewButton, fork: FALSE]; <> [] _ Buttons.Create[info: [name: "Open"], proc: OpenButton]; END. PreSave: PUBLIC Menus.MenuProc = { viewer: ViewerClasses.Viewer = NARROW[parent]; tdd: TEditDocumentData _ NARROW[viewer.data]; root: TextNode.Ref; file: Rope.ROPE = viewer.name; IF file=NIL THEN BEGIN MessageWindow.Append["Can't SAVE -- no file name!", TRUE]; MessageWindow.Blink[]; ViewerOps.SetNewVersion[viewer]; -- turn the bit back on RETURN; END; IF tdd.readOnly THEN BEGIN MessageWindow.Append["Can't SAVE -- read only document!", TRUE]; MessageWindow.Blink[]; RETURN; END; [] _ SpinAndLock[tdd, "PreSave"]; -- may have other operation in progress root _ tdd.text; Unlock[tdd]; 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[] } ELSE MessageWindow.Append[Rope.Concat["Confirm save of ", file], TRUE]; };