File: RopeViewerImpl.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 13, 1984 4:52:00 pm PDT
DIRECTORY
RopeViewer, TiogaOps, Menus, ViewerOps, ViewerClasses,
RopeViewerImpl:
CEDAR
MONITOR
IMPORTS TiogaOps, ViewerOps, ViewerTools, Menus, Rope EXPORTS RopeViewer = BEGIN
ourData:
TYPE =
RECORD [
origContents, newContents: Rope.ROPE ← NIL,
origTioga: ViewerTools.TiogaContents ← NIL,
beenSaved: BOOL ← FALSE,
saved: CONDITION
];
SetMenu:
PROC [viewer: ViewerClasses.Viewer, data:
REF ourData] ~
BEGIN
menu: Menus.Menu;
menu ← Menus.CreateMenu[];
Menus.AppendMenuEntry[menu, Menus.CreateEntry[name: "Reset", proc: ResetProc, clientData: data, fork: FALSE, guarded: TRUE]];
Menus.AppendMenuEntry[menu, Menus.CreateEntry[name: "Save", proc: SaveProc, clientData: data, fork: FALSE]];
ViewerOps.SetMenu[viewer, menu];
END;
ResetProc: Menus.ClickProc ~
BEGIN
data: REF ourData ~ NARROW[clientData];
viewer: ViewerClasses.Viewer ~ NARROW[parent];
IF data.origTioga =
NIL
THEN {
TiogaOps.SelectDocument[viewer];
TiogaOps.Delete[];
TiogaOps.ClearLooks[];
FOR i:
INT
IN [0..Rope.Length[data.origContents])
DO
ch: CHAR ← Rope.Fetch[data.origContents, i];
IF ch = '\n
THEN
TiogaOps.Break[]
ELSE
TiogaOps.InsertChar[ch];
ENDLOOP;
TiogaOps.Jump[viewer, [TiogaOps.ViewerDoc[viewer], 0]];
data.origTioga ← ViewerTools.GetTiogaContents[viewer];
};
ViewerTools.SetTiogaContents[viewer, data.origTioga];
ViewerOps.PaintViewer[viewer, $menu]; -- to sidestep a Tioga or ViewerTools bug
END;
SaveProc:
ENTRY Menus.ClickProc ~
BEGIN
data: REF ourData ~ NARROW[clientData];
viewer: ViewerClasses.Viewer ~ NARROW[parent];
IF data.beenSaved THEN RETURN; -- ignore additional clicks
data.newContents ← ViewerTools.GetContents[viewer];
data.beenSaved ← TRUE;
NOTIFY data.saved;
END;
-- create a viewer onto a rope, let the guy edit it, and return the new rope
Edit:
PUBLIC
ENTRY PROC [contents, caption: Rope.
ROPE]
RETURNS [Rope.
ROPE] =
BEGIN
data: REF ourData ← NEW[ourData];
viewerInfo: ViewerClasses.ViewerRec;
viewer: ViewerClasses.Viewer;
data.origContents ← contents;
viewerInfo.iconic ← FALSE;
viewerInfo.name ← caption;
viewerInfo.inhibitDestroy ← TRUE;
viewer ← ViewerTools.MakeNewTextViewer[viewerInfo];
SetMenu[viewer, data];
ResetProc[viewer, data];
WAIT data.saved;
ViewerOps.DestroyViewer[viewer];
RETURN[data.newContents];
END;
END.