EditHistoryImpl.mesa
Paxton on June 14, 1982 10:42 am
McGregor on September 21, 1982 3:28 pm
Maxwell, January 6, 1983 12:18 pm
Plass, April 20, 1983 9:54 am
Russ Atkinson, September 29, 1983 11:03 am
Paul Rovner, September 30, 1983 10:37 am
DIRECTORY
Buttons,
Commander,
Containers,
EditToolBuilder,
IO,
MessageWindow,
Rope,
TEditHistory,
TEditInput,
TEditOps,
ViewerClasses,
ViewerOps;
EditHistoryImpl: CEDAR PROGRAM
IMPORTS
Commander, Containers, IO, EditToolBuilder, MessageWindow, TEditHistory, TEditInput, TEditOps, ViewerOps
= { OPEN EditToolBuilder;
Info: TYPE = REF InfoRec;
InfoRec: TYPE = RECORD [
layout: Layout,
eventNumArg: ViewerClasses.Viewer,
sliceSizeArg: ViewerClasses.Viewer,
textField: ViewerClasses.Viewer ];
info: Info; -- for the current edit history tool
BuildIt: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
... builds an edit history tool.
layout: Layout;
name: Rope.ROPE = "EditHistory Tool";
viewer: ViewerClasses.Viewer ← ViewerOps.FindViewer[name];
IF viewer # NIL THEN { -- already have an edit history tool around
IF viewer.iconic THEN ViewerOps.OpenIcon[viewer];
RETURN [NIL, "Opened existing EditHistory Tool."]};
info ← NEW[InfoRec];
info.layout ← layout ← NEW[LayoutRec];
{OPEN layout;
entryLeft ← initLeft ← 5;
heightSoFar ← initHeight ← entryVSpace;
container ← Containers.Create[[name: name, iconic: TRUE, column: right, scrollable: FALSE]];
[] ← BuildButton[layout, "Show", DoShow];
[] ← BuildButton[layout, "Undo", DoUndo];
[,info.eventNumArg] ←
BuildDataFieldPair[layout, "since event number:", EventNumberButton, NIL, 1];
layout.heightSoFar ← layout.heightSoFar + layout.entryVSpace/2;
[] ← BuildButton[layout, "Get", DoGetSize];
[] ← BuildButton[layout, "Set", DoSetSize];
[,info.sliceSizeArg] ←
BuildDataFieldPair[layout, "history size:", SliceSizeButton, NIL, 1];
HRule[layout];
info.textField ← ViewerOps.CreateViewer[flavor: $Text, info: [parent: layout.container,
wx: entryLeft, wy: heightSoFar, wh: 700, ww: 200, border: FALSE, scrollable: TRUE],
paint: FALSE];
-- make the textField grow as the container grows
Containers.ChildYBound[container, info.textField];
Containers.ChildXBound[container, info.textField];
};
RETURN [NIL, "Created new EditHistory Tool."];
};
EventNumberButton: Buttons.ButtonProc = {
DataFieldButton[info.eventNumArg, mouseButton#red] };
SliceSizeButton: Buttons.ButtonProc = {
DataFieldButton[info.sliceSizeArg, mouseButton#red] };
DoShow: Buttons.ButtonProc = { OPEN IO;
num, stop: INT;
h: STREAMIO.ROS[];
TEditInput.CloseEvent[];
num ← TEditHistory.CurrentEventNumber[];
stop ← EditToolBuilder.GetInt[info.eventNumArg ! BadNumber => { stop ← 0; CONTINUE }];
WHILE TEditHistory.Known[num ← num-1] AND num >= stop DO
list: LIST OF REF ANY ← TEditHistory.GetRepeatList[num];
Put[h,int[num]];
Put[h,char[TAB]]; Put[h,char[TAB]];
Put[h,rope[ConvertList[list]]];
Put[h,char[CR]]; Put[h,char[CR]];
ENDLOOP;
TEditOps.SetTextContents[info.textField, IO.RopeFromROS[h]];
};
DoUndo: Buttons.ButtonProc = {
num: INT ← GetInt[info.eventNumArg ! BadNumber => GOTO Bad];
TEditHistory.Undo[num];
EXITS Bad => {
MessageWindow.Append["Please fill in the \"since event number\" field",TRUE];
MessageWindow.Blink[];
} };
DoGetSize: Buttons.ButtonProc = {
SetInt[info.sliceSizeArg, TEditHistory.SliceSize[]] };
DoSetSize: Buttons.ButtonProc = {
num: INT ← GetInt[info.sliceSizeArg ! BadNumber => GOTO Bad];
TEditHistory.NewSliceSize[num];
EXITS Bad => {
MessageWindow.Append["Please enter a number in the \"history size\" field",TRUE];
MessageWindow.Blink[] } };
Commander.Register["EditHistory", BuildIt, "Create an Edit History tool."];
}.....