File: TiogaRopeEditorImpl.mesa   
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created by: Bob Mayo, August 5, 1984 8:21:38 pm PDT
Last Edited by: Mayo, August 6, 1984 4:18:03 pm PDT
DIRECTORY
TerminalIO, TiogaRopeEditor, TiogaOps, ViewerOps, ViewerClasses, Rope;
TiogaRopeEditorImpl: CEDAR PROGRAM    
IMPORTS TerminalIO, TiogaOps, ViewerOps, Rope EXPORTS TiogaRopeEditor = BEGIN
OurAtom: ATOM = $RopeEdit;
TiogaInitProc: ViewerClasses.InitProc;
-- create a viewer onto a rope, let the guy edit it, and return the new rope
Edit: PUBLIC PROC [old, caption, comment: Rope.ROPE ← NIL] RETURNS [Rope.ROPE] = BEGIN
viewerInfo: ViewerClasses.ViewerRec;
viewer: ViewerClasses.Viewer;
viewerInfo.iconic ← FALSE;
viewerInfo.name ← caption;
viewerInfo.inhibitDestroy ← TRUE;
viewer ← ViewerOps.CreateViewer[OurAtom, viewerInfo];
TiogaOps.SelectDocument[viewer];
TiogaOps.PutProp[TiogaOps.GetCaret[].node, $Comment, NEW[BOOLTRUE]];
TiogaOps.InsertRope[comment];
TiogaOps.Break[];
TiogaOps.PutProp[TiogaOps.GetCaret[].node, $Comment, NEW[BOOLFALSE]];
TiogaOps.InsertRope[old];
RETURN[old];
END;
OurInitProc: ViewerClasses.InitProc -- PROC [self: Viewer] -- = BEGIN
TiogaInitProc[self];
TiogaOps.SelectDocument[self];
TiogaOps.PutProp[TiogaOps.GetCaret[].node, $Comment, NEW[BOOLTRUE]];
TiogaOps.InsertRope["Howdy"];
END;
OurSaveProc: ViewerClasses.SaveProc -- PROC [self: Viewer, force: BOOL ← FALSE] -- = BEGIN
newRope: Rope.ROPENIL;
node: TiogaOps.Ref;
TiogaOps.SelectDocument[self];
node ← TiogaOps.SelectionRoot[];
TerminalIO.WriteRope["Contents were:\n"];
DO
IF ~TiogaOps.IsComment[node] THEN {
r: Rope.ROPE ← TiogaOps.GetRope[node];
IF r # NIL THEN
newRope ← Rope.Cat[newRope, r, "\n"];
};
node ← TiogaOps.StepForward[node];
IF node = NIL THEN EXIT;
ENDLOOP;
TerminalIO.WriteRope[newRope];
TerminalIO.WriteRope["-------------\n"];
ViewerOps.DestroyViewer[self];
END;
Init: PROC [] = BEGIN
ourClass: ViewerClasses.ViewerClass ← NEW[ViewerClasses.ViewerClassRec];
ourClass^ ← ViewerOps.FetchViewerClass[$Text]^;
ourClass.save ← OurSaveProc;
TiogaInitProc ← ourClass.init;
ourClass.init ← OurInitProc;
ViewerOps.RegisterViewerClass[OurAtom, ourClass];
END;
Init[];
END.