TEditSplitImpl.mesa
Edited by Paxton on June 2, 1983 9:00 am
Edited by McGregor on August 27, 1982 2:38 pm
Edited by Wyatt on December 15, 1983 6:50 pm
DIRECTORY
TEditDisplay USING [EstablishLine],
TEditDocument USING [LineTable, Selection, SelectionRec, SpinAndLock, TEditDocumentData, Unlock],
TEditOps USING [CopyLoadHistory, CopyPositionHistory],
TEditSplit USING [],
TextNode USING [Location, pZone],
ViewerClasses USING [Viewer],
ViewerOps USING [AddProp, ComputeColumn, CreateViewer, DestroyViewer, FetchProp,
MoveBelowViewer, OpenIcon, PaintViewer, SetMenu];
TEditSplitImpl: CEDAR PROGRAM
IMPORTS TEditDisplay, TEditDocument, TEditOps, TextNode, ViewerOps
EXPORTS TEditSplit
SHARES ViewerClasses =
BEGIN
Viewer: TYPE = ViewerClasses.Viewer;
Split: PUBLIC PROC [old: Viewer] = BEGIN
tddNew, tddOld: TEditDocument.TEditDocumentData;
new: Viewer;
paintCaption: BOOLFALSE;
selectionHistory: TEditDocument.Selection;
lines: TEditDocument.LineTable;
loc: TextNode.Location;
tddOld ← NARROW[old.data];
IF tddOld = NIL THEN RETURN;
new ← ViewerOps.CreateViewer[flavor: old.class.flavor, info: [name: old.name,
column: old.column, iconic: TRUE], paint: FALSE];
ViewerOps.OpenIcon[icon: new, paint: FALSE];
ViewerOps.MoveBelowViewer[altered: new, static: old, paint: FALSE];
tddNew ← NARROW[new.data];
IF tddNew = NIL THEN RETURN; -- How this could happen is beyond me, but paranoia is cheap. [McGregor]
selectionHistory ← NARROW[ViewerOps.FetchProp[old, $SelectionHistory]];
new.link ← old;
IF old.link=NIL THEN { old.link ← new; paintCaption ← TRUE }
ELSE FOR v: Viewer ← old.link, v.link UNTIL v.link=old DO
REPEAT FINISHED => v.link ← new;
ENDLOOP;
new.newVersion ← old.newVersion;
new.newFile ← old.newFile;
new.file ← old.file;
ViewerOps.ComputeColumn[column: new.column, paint: FALSE]; -- to find new height
[] ← TEditDocument.SpinAndLock[tddOld, "Split"]; -- must ComputeColumn before lock tdd
tddNew.text ← tddOld.text;
tddNew.tsInfo ← tddOld.tsInfo;
tddNew.clipLevel ← tddOld.clipLevel;
tddNew.commentFilter ← tddOld.commentFilter;
ViewerOps.SetMenu[new, old.menu, FALSE];
IF selectionHistory # NIL THEN { -- copy it
newSelectionHistory: TEditDocument.Selection ←
TextNode.pZone.NEW[TEditDocument.SelectionRec];
newSelectionHistory^ ← selectionHistory^;
ViewerOps.AddProp[new, $SelectionHistory, newSelectionHistory] };
TEditOps.CopyPositionHistory[from: old, to: new];
TEditOps.CopyLoadHistory[from: old, to: new];
lines ← tddOld.lineTable;
loc ← lines[lines.lastLine].pos; -- in case loop doesn't find anything
FOR n: INTEGER IN [0..lines.lastLine] DO -- find line that goes past new bottom
IF lines[n].yOffset+lines[n].descent >= old.ch THEN {
loc ← lines[n].pos; EXIT };
ENDLOOP;
TEditDocument.Unlock[tddOld];
TEditDisplay.EstablishLine[tddNew, loc];
ViewerOps.ComputeColumn[column: new.column, paint: TRUE]; -- now do the painting
FOR v: Viewer ← new.link, v.link UNTIL v=new DO
IF v.iconic THEN { -- get rid of it -- ViewerOps.DestroyViewer[v]; EXIT };
IF paintCaption THEN ViewerOps.PaintViewer[v, caption]; -- turn on [Split]
ENDLOOP;
END;
END.