-- EditHistoryImpl.mesa; Edited by Paxton on June 14, 1982 10:42 am
-- Edited by McGregor on September 21, 1982 3:28 pm
Last Edited by: Maxwell, January 6, 1983 12:18 pm
DIRECTORY
Buttons,
Containers,
UserExec,
EditToolBuilder,
IO,
MessageWindow,
Rope,
Runtime,
TEditHistory,
TEditInput,
TEditOps,
TypeScript,
ViewerClasses,
ViewerOps;
EditHistoryImpl: CEDAR PROGRAM
IMPORTS
Containers,
UserExec,
IO,
EditToolBuilder,
MessageWindow,
Runtime,
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: UserExec.CommandProc = {
-- build 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];
MessageWindow.Append["EditHistory Tool already exists",TRUE];
RETURN };
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];
}};
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: Handle ← CreateOutputStreamToRope[];
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, GetOutputStreamRope[h]] };
DoUndo: Buttons.ButtonProc = {
num: INT ← GetInt[info.eventNumArg ! BadNumber => GOTO Bad];
TEditHistory.Undo[num];
EXITS Bad => {
OPEN MessageWindow;
Append["Fill in the \"since event number\" field",TRUE];
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 => {
OPEN MessageWindow;
Append["Enter a number in the \"history size\" field",TRUE];
Blink[] } };
TRUSTED {
IF Runtime.IsBound[UserExec.RegisterCommand]
THEN
UserExec.RegisterCommand["EditHistory", BuildIt, "Create an Edit History tool."]};
}.....