-- TEditRefreshImpl.mesa Edited by Paxton on December 28, 1982 2:06 pm
Last Edited by: Maxwell, January 6, 1983 11:35 am
Last Edited by: Wyatt, December 9, 1983 3:17 pm
DIRECTORY
TEditRefresh,
MonitoredQueue USING [Create, MQ, Remove],
Process USING [Detach, SetPriority, priorityNormal],
TEditDocument USING [GetViewerForRoot, SelectionId, TEditDocumentData],
TEditLocks USING [LockDocAndTdd, UnlockDocAndTdd],
TextNode USING [pZone, Ref],
TEditTouchup USING [refresh, RefreshOver],
ViewerClasses USING [Viewer],
ViewerOps USING [PaintViewer];
TEditRefreshImpl: CEDAR MONITOR
IMPORTS MonitoredQueue, Process, TextNode, TEditDocument, TEditLocks, TEditTouchup, ViewerOps
EXPORTS TEditRefresh = BEGIN
dirtyDocs: PUBLIC MonitoredQueue.MQ ← MonitoredQueue.Create[TextNode.pZone];
processCount, scrollProcessCount: INTEGER ← 0;
maxProcesses: INTEGER = 10; -- max number of concurrent refresh processes
done: CONDITION;
DecCount: ENTRY PROC = {
processCount ← processCount-1; NOTIFY done };
Refresh: PROC = { 
TRUSTED {Process.SetPriority[Process.priorityNormal]};
DO
doc: TextNode.Ref;
viewer: ViewerClasses.Viewer;
RefreshIt: ENTRY PROC [viewer: ViewerClasses.Viewer] = {
WHILE processCount >= maxProcesses DO WAIT done; ENDLOOP;
processCount ← processCount+1;
TRUSTED {Process.Detach[FORK RefreshViewer[viewer ! ABORTED => CONTINUE]]} };
doc ← NARROW[MonitoredQueue.Remove[dirtyDocs]];
viewer ← TEditDocument.GetViewerForRoot[doc];
IF viewer=NIL THEN LOOP;
RefreshIt[viewer];
IF viewer.link # NIL THEN
FOR v: ViewerClasses.Viewer ← viewer.link, v.link UNTIL v=viewer DO
RefreshIt[v]; ENDLOOP;
ENDLOOP };
RefreshViewer: PROC [viewer: ViewerClasses.Viewer] = {
tdd: TEditDocument.TEditDocumentData = NARROW[viewer.data];
IF tdd = NIL THEN RETURN;
[] ← TEditLocks.LockDocAndTdd[tdd, "RefreshViewer", read];
tdd.invisible ← TRUE; -- will be reset by our paint proc if it is called
ViewerOps.PaintViewer[viewer, client, FALSE, TEditTouchup.refresh];
IF tdd.invisible THEN TEditTouchup.RefreshOver[];
in case we're waiting in LockAfterRefresh
DecCount[];
TEditLocks.UnlockDocAndTdd[tdd] };
ScrollToEndOfDoc: PUBLIC PROC [viewer: ViewerClasses.Viewer, glitch: BOOL] = {
tdd: TEditDocument.TEditDocumentData = NARROW[viewer.data];
IF tdd=NIL THEN RETURN;
tdd.scroll ← endofdoc; tdd.scrollGlitch ← glitch };
ScrollToEndOfSel: PUBLIC PROC [viewer: ViewerClasses.Viewer, glitch: BOOL,
id: TEditDocument.SelectionId ← primary] = {
tdd: TEditDocument.TEditDocumentData = NARROW[viewer.data];
IF tdd=NIL THEN RETURN;
tdd.scroll ← endofsel; tdd.scrollGlitch ← glitch; tdd.scrollSelectionId ← id };
TRUSTED {Process.Detach[FORK Refresh[]]};
END.