EditHistoryImpl.mesa
Copyright Ó 1985, 1986, 1991, 1992 by Xerox Corporation. All rights reserved.
Plass, April 20, 1983 9:54 am
Russ Atkinson (RRA) June 18, 1985 5:09:57 pm PDT
Doug Wyatt, March 14, 1992 6:11 pm PST
DIRECTORY
Buttons USING [ButtonProc],
Commander USING [CommandProc, Register],
Containers USING [ChildXBound, ChildYBound, Create],
EditToolBuilder USING [BadNumber, BuildButton, BuildDataFieldPair, ConvertList, DataFieldButton, GetInt, HRule, Layout, LayoutRec, SetInt],
IO USING [char, CR, int, Put1, rope, RopeFromROS, ROS, STREAM, TAB],
MessageWindow USING [Append, Blink],
Rope USING [ROPE],
TEditHistory USING [CurrentEventNumber, GetRepeatList, Known, NewSliceSize, SliceSize, Undo],
TEditInput USING [CloseEvent],
TEditOps USING [SetTextContents],
ViewerClasses USING [Viewer],
ViewerOps USING [CreateViewer, FindViewer, OpenIcon];
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: STREAM ¬ IO.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];
Put1[h,int[num]];
Put1[h,char[TAB]]; Put1[h,char[TAB]];
Put1[h,rope[ConvertList[list]]];
Put1[h,char[CR]]; Put1[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."];
}.....