ExecHacks.mesa; Edited by McGregor on August 17, 1983 5:09 pm
DIRECTORY
InputFocus USING [SetInputFocus],
Menus USING [CreateEntry, AppendMenuEntry, MenuProc],
Rope USING [Concat, Equal, Fetch, ROPE, Size, Substr],
TiogaOps USING [GetSelection, GetRope],
UserTerminal USING [BlinkDisplay],
ViewerClasses USING [Viewer],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerOps USING [EnumProc, EnumerateViewers, PaintViewer],
ViewerTools USING [GetSelectedViewer, GetSelectionContents, SetSelection];
ExecHacks: CEDAR PROGRAM
IMPORTS InputFocus, Menus, Rope, TiogaOps, UserTerminal, ViewerEvents, ViewerOps, ViewerTools = BEGIN
Compile: Menus.MenuProc = BEGIN
exec: ViewerClasses.Viewer ~ NARROW[parent];
sel: Rope.ROPE ← ViewerTools.GetSelectionContents[];
IF sel = NIL THEN TRUSTED {UserTerminal.BlinkDisplay[]; RETURN};
IF Rope.Size[sel] <= 1 THEN BEGIN
selViewer: ViewerClasses.Viewer ← ViewerTools.GetSelectedViewer[];
IF selViewer=exec THEN TRUSTED {UserTerminal.BlinkDisplay[]; RETURN};
sel ← selViewer.name;
END;
sel ← Rope.Concat["Compile ", sel];
sel ← Rope.Concat[sel, "
"];
ViewerTools.SetSelection[exec, NIL];
exec.class.notify[exec, LIST[sel]];
END;
Redo: Menus.MenuProc = BEGIN
ScanAndStuff: PROC = BEGIN
exec: ViewerClasses.Viewer ~ NARROW[parent];
rope: Rope.ROPE;
start, end: INT;
ViewerTools.SetSelection[exec, NIL];
rope ← TiogaOps.GetRope[TiogaOps.GetSelection[].end.node];
IF (start ← Rope.Size[rope]) < 6 THEN ERROR;
start ← start - 4; --one to point to the last char, 2 to skip current %, 1 for prev CR
WHILE Rope.Fetch[rope, start]#'% DO start ← start-1; ENDLOOP;
end ← start ← start+2;
WHILE Rope.Fetch[rope, end]#15C DO end ← end+1; ENDLOOP;
rope ← Rope.Substr[rope, start, end-start+1];
exec.class.notify[exec, LIST[rope]];
END;
ScanAndStuff[! ANY => TRUSTED {UserTerminal.BlinkDisplay[]; CONTINUE}];
END;
Reset: Menus.MenuProc = BEGIN
exec: ViewerClasses.Viewer ~ NARROW[parent];
InputFocus.SetInputFocus[NIL];
exec.class.set[exec, NIL, FALSE];
ViewerTools.SetSelection[exec, NIL];
exec.class.notify[exec, LIST["-- reset --
"]];
END;
DoMenu: ViewerEvents.EventProc = BEGIN
IF Rope.Equal[viewer.name, "Commander"] THEN BEGIN
Menus.AppendMenuEntry[viewer.menu, Menus.CreateEntry[name:"Compile", proc:Compile, fork:FALSE]];
Menus.AppendMenuEntry[viewer.menu, Menus.CreateEntry[name:"Redo", proc:Redo, fork:FALSE]];
Menus.AppendMenuEntry[viewer.menu, Menus.CreateEntry[name:"Reset", proc:Reset, fork:FALSE, guarded: TRUE]];
ViewerOps.PaintViewer[viewer, menu];
END;
END;
AttachMenuItemsToExecs: PROC = BEGIN
PerViewer: ViewerOps.EnumProc = BEGIN
[] ← DoMenu[v, create, FALSE];
END;
ViewerOps.EnumerateViewers[PerViewer];
END;
[] ← ViewerEvents.RegisterEventProc[DoMenu, create, $Typescript, FALSE];
AttachMenuItemsToExecs[];
END.