CDRopeViewerImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Similar to an module of: Bob Mayo
Created by: Christian Jacobi, November 20, 1984 11:31:53 am PST
Last Edited by: Christian Jacobi, September 19, 1985 8:38:37 pm PDT
DIRECTORY
CDRopeViewer,
Menus,
ViewerOps,
ViewerClasses,
ViewerTools,
Rope;
CDRopeViewerImpl:
CEDAR
MONITOR
IMPORTS ViewerOps, ViewerTools, Menus
EXPORTS CDRopeViewer =
BEGIN
SaveProc:
TYPE = CDRopeViewer.SaveProc;
--PROC[contents, formatting: Rope.ROPE, clientData: REF, discard: BOOL]
MyData:
TYPE =
RECORD [
tiogaContents: ViewerTools.TiogaContents ← NIL,
init: BOOL ← FALSE,
finished: BOOL ← FALSE, --monitored
save: SaveProc ← NIL,
clientData: REF ← NIL,
skipSaveOnDiscard: BOOL ← TRUE,
saved: CONDITION
];
ResetButton: Menus.ClickProc = {
ENABLE UNWIND => NULL;
data: REF MyData ~ NARROW[clientData];
viewer: ViewerClasses.Viewer ~ NARROW[parent];
IF ShouldSkip[data, FALSE] THEN RETURN; -- ignore additional clicks
ViewerTools.SetTiogaContents[viewer, data.tiogaContents];
ViewerOps.PaintViewer[viewer, $menu];
};
ClearButton: Menus.ClickProc = {
ENABLE UNWIND => NULL;
data: REF MyData ~ NARROW[clientData];
viewer: ViewerClasses.Viewer ~ NARROW[parent];
IF ShouldSkip[data, FALSE] THEN RETURN; -- ignore additional clicks
ViewerTools.SetTiogaContents[viewer, NEW[ViewerTools.TiogaContentsRec]];
ViewerOps.PaintViewer[viewer, $menu];
};
Destroy:
PROC [viewer: ViewerClasses.Viewer] = {
--Destroys all the linked viewers
first: ViewerClasses.Viewer ← viewer;
WHILE viewer#
NIL
DO
next: ViewerClasses.Viewer ← viewer.link;
ViewerOps.DestroyViewer[viewer];
IF next=first OR next=NIL THEN EXIT;
viewer ← next;
ENDLOOP
};
SaveButton: Menus.ClickProc = {
data: REF MyData ~ NARROW[clientData];
viewer: ViewerClasses.Viewer ~ NARROW[parent];
IF ShouldSkip[data, TRUE] THEN RETURN; -- ignore additional clicks
data.tiogaContents ← ViewerTools.GetTiogaContents[viewer];
data.save[data.tiogaContents.contents, data.tiogaContents.formatting, data.clientData, FALSE];
NotifyFinished[data];
Destroy[viewer];
};
DetachButton: Menus.ClickProc = {
data: REF MyData ~ NARROW[clientData];
viewer: ViewerClasses.Viewer ~ NARROW[parent];
newViewer: ViewerClasses.Viewer;
tiogaContents: ViewerTools.TiogaContents;
IF ShouldSkip[data, FALSE] THEN RETURN; -- ignore additional clicks
tiogaContents ← ViewerTools.GetTiogaContents[viewer];
newViewer ← ViewerTools.MakeNewTextViewer[[name: "[Detached comment]"]];
ViewerTools.SetTiogaContents[newViewer, tiogaContents];
};
DiscardButton: Menus.ClickProc = {
data: REF MyData ~ NARROW[clientData];
IF ShouldSkip[data, TRUE] THEN RETURN;
IF ~data.skipSaveOnDiscard
THEN {
data.save[data.tiogaContents.contents, data.tiogaContents.formatting, data.clientData, TRUE]
};
NotifyFinished[data];
Destroy[NARROW[parent]];
};
ShouldSkip:
ENTRY
PROC [data:
REF MyData, finish:
BOOL←
FALSE]
RETURNS [skip:
BOOL] = {
ENABLE UNWIND => NULL;
skip ← data.finished OR ~data.init;
IF finish THEN data.finished ← data.init;
};
NotifyFinished:
ENTRY
PROC [data:
REF MyData] = {
ENABLE UNWIND => NULL;
NOTIFY data.saved;
};
WaitUntilDone:
ENTRY
PROC[myData:
REF MyData] = {
ENABLE UNWIND => NULL;
WHILE ~myData.finished
DO
WAIT myData.saved;
ENDLOOP;
};
Edit:
PUBLIC
PROC [contents, caption, formatting: Rope.
ROPE←
NIL, save: SaveProc←
NIL, clientData:
REF←
NIL, fork:
BOOL←
TRUE, saveOnDiscard:
BOOL←
FALSE] = {
RemoveEntry:
PROC [menu: Menus.Menu, key: Rope.
ROPE] = {
entry: Menus.MenuEntry ← Menus.FindEntry[menu, key];
IF entry#NIL THEN Menus.ReplaceMenuEntry[menu, entry];
};
MakeMenu:
PROC [data:
REF MyData, needDiscard:
BOOL, previous: Menus.Menu]
RETURNS [menu: Menus.Menu] = {
menu ← IF previous#NIL THEN Menus.CopyMenu[previous] ELSE Menus.CreateMenu[];
RemoveEntry[menu, "Get"];
RemoveEntry[menu, "GetImpl"];
RemoveEntry[menu, "Store"];
RemoveEntry[menu, "Clear"];
RemoveEntry[menu, "Reset"];
RemoveEntry[menu, "Save"];
Menus.InsertMenuEntry[menu,
Menus.CreateEntry[name: "Reset", proc: ResetButton, clientData: data, guarded: TRUE]];
Menus.InsertMenuEntry[menu,
Menus.CreateEntry[name: "Clear", proc: ClearButton, clientData: data, guarded: TRUE]];
IF needDiscard
THEN
Menus.InsertMenuEntry[menu,
Menus.CreateEntry[name: "Discard", proc: DiscardButton, clientData: data, guarded: TRUE]];
Menus.InsertMenuEntry[menu,
Menus.CreateEntry[name: "Detach", proc: DetachButton, clientData: data]];
Menus.InsertMenuEntry[menu,
Menus.CreateEntry[name: "Save", proc: SaveButton, clientData: data]];
};
viewer: ViewerClasses.Viewer;
myData: REF MyData ← NEW[MyData];
myData.save ← save;
myData.clientData ← clientData;
myData.tiogaContents ←
NEW[ViewerTools.TiogaContentsRec ←
[contents: contents, formatting: formatting]
];
viewer ← ViewerTools.MakeNewTextViewer[[
iconic: FALSE,
name: caption,
inhibitDestroy: saveOnDiscard
]];
ViewerOps.SetMenu[viewer, MakeMenu[myData, saveOnDiscard, viewer.menu]];
ViewerTools.SetTiogaContents[viewer, myData.tiogaContents];
ViewerTools.SetSelection[viewer, NEW[ViewerTools.SelPosRec]];
ViewerOps.PaintViewer[viewer, $menu];
myData.init ← TRUE;
IF ~fork THEN WaitUntilDone[myData];
};
END.