EditToolTopImpl.mesa
Paxton on December 30, 1982 10:26 am
McGregor on September 21, 1982 3:20 pm
Maxwell, January 14, 1983 8:39 am
Plass, April 20, 1983 9:52 am
Russ Atkinson, September 29, 1983 11:02 am
Doug Wyatt, January 13, 1984 3:55 pm
DIRECTORY
Commander USING [CommandProc, Register],
EditToolBuilder USING [HRule, LayoutRec, ToMiddle, ToNext, VGap],
EditToolPrivate USING [BuildExtraButtons, BuildFileListEntries, BuildGetAndSetOpsEntries, BuildInitCapEntry, BuildLooksButtons, BuildMiniPatternDocEntry, BuildOperationEntry, BuildOperationField, BuildPropertyButtons, BuildSearchButtons, BuildSortButtons, BuildSourceEntry, BuildStyleButtons, BuildSubstituteEntry, BuildTargetEntry, BuildTypeButtons, DoCountMenuButton, DoItMenuButton, DoNoMenuButton, DoSearchMenuButton, DoSubstituteMenuButton, DoYesMenuButton, Info, InfoRec],
Menus USING [AppendMenuEntry, CreateEntry, CreateMenu, Menu, MenuProc],
Rope USING [ROPE],
TEditInput USING [CommandProc, Interpret, Register, UnRegister],
TextNode USING [pZone],
UndoEvent USING [Ref],
ViewerClasses USING [Viewer],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerOps USING [CreateViewer, FindViewer, OpenIcon, SetOpenHeight];
EditToolTopImpl: CEDAR PROGRAM
IMPORTS Commander, EditToolBuilder, EditToolPrivate, Menus, TEditInput, TextNode, ViewerEvents, ViewerOps
EXPORTS EditToolPrivate
= { OPEN EditToolBuilder, EditToolPrivate;
Event: TYPE = UndoEvent.Ref;
BuildContainer: PROC [info: Info, name: Rope.ROPE] = { OPEN info;
viewer: ViewerClasses.Viewer;
editToolMenu: Menus.Menu ← Menus.CreateMenu[];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Stop", Stop]];
Menus.AppendMenuEntry[editToolMenu,
Menus.CreateEntry[name: "Search", proc: DoSearchMenuButton, fork: TRUE]];
Menus.AppendMenuEntry[editToolMenu,
Menus.CreateEntry[name: "Substitute", proc: DoSubstituteMenuButton, fork: TRUE]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Yes", DoYesMenuButton]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["No", DoNoMenuButton]];
Menus.AppendMenuEntry[editToolMenu, Menus.CreateEntry["Replace", DoItMenuButton]];
Menus.AppendMenuEntry[editToolMenu,
Menus.CreateEntry[name: "Count", proc: DoCountMenuButton, fork: TRUE]];
layout.container ← viewer ← ViewerOps.CreateViewer[flavor: $Container,
info: [name: name, iconic: TRUE, column: right, menu: editToolMenu, icon: LOOPHOLE[5]], paint: TRUE];
editTool ← viewer; -- save in global variable
};
editTool: PUBLIC ViewerClasses.Viewer;
MyDestroy: ViewerEvents.EventProc = {
IF viewer#editTool THEN RETURN; -- filter
mainToolInfo ← NIL;
editTool ← NIL;
UnRegister[];
};
Stop: Menus.MenuProc = {
mainToolInfo.interrupt^ ← TRUE;
};
----------------------------
ChangeState: PUBLIC PROC [flag: BOOLEAN, trueList, falseList: LIST OF REF] = {
DoButton[IF ~flag THEN trueList ELSE falseList] };
----------------------------
CycleTriple: PUBLIC PROC [state: [0..2], list0, list1, list2: LIST OF REF] = {
nextState: ARRAY [0..2] OF [0..2] = [1,2,0];
nextLIST: ARRAY [0..2] OF LIST OF REF = [list0, list1, list2];
DoButton[nextLIST[nextState[state]]] };
----------------------------
DoButton: PUBLIC PROC [
redList, blueList: LIST OF REFNIL,
redButton: BOOLFALSE,
viewer: ViewerClasses.Viewer ← NIL] = {
IF viewer=NIL THEN viewer ← mainToolInfo.targetArg; -- must be a text viewer
IF ~redButton AND blueList#NIL THEN TEditInput.Interpret[viewer,blueList]
ELSE TEditInput.Interpret[viewer,redList] };
----------------------------
registered: LIST OF RegCom;
RegCom: TYPE = RECORD [atom: ATOM, op: TEditInput.CommandProc];
Register: PUBLIC PROC [atom: ATOM, op: TEditInput.CommandProc] RETURNS [LIST OF REF] = {
TEditInput.Register[atom, op];
registered ← CONS[[atom, op], registered];
RETURN [LIST[atom]] };
ReRegister: PROC = {
FOR r: LIST OF RegCom ← registered, r.rest UNTIL r=NIL DO
TEditInput.Register[r.first.atom, r.first.op];
ENDLOOP };
UnRegister: PROC = {
FOR r: LIST OF RegCom ← registered, r.rest UNTIL r=NIL DO
TEditInput.UnRegister[r.first.atom, r.first.op];
ENDLOOP };
-- Initialization
mainToolInfo: PUBLIC Info;
firstTime: BOOLEANTRUE;
InitToolCommand: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: Rope.ROPE ← NIL]
name: Rope.ROPE ← "EditTool";
viewer: ViewerClasses.Viewer ← ViewerOps.FindViewer[name];
mainEditTool: BOOL ← viewer = NIL;
info: Info ← TextNode.pZone.NEW[InfoRec];
info.layout ← TextNode.pZone.NEW[LayoutRec];
IF ~mainEditTool THEN {
an EditTool already exists, so flush the command
IF viewer.iconic THEN ViewerOps.OpenIcon[viewer];
RETURN [NIL, "Opened existing Edit Tool."]};
IF firstTime THEN firstTime ← FALSE ELSE ReRegister[];
{OPEN info;
interrupt ← NEW[BOOLFALSE];
layout.entryLeft ← layout.initLeft ← 0;
layout.entryVSpace ← 3;
layout.heightSoFar ← layout.initHeight ← 1;
----------------------------
BuildContainer[info,name]; -- build enclosing viewer
----------------------------
BuildTargetEntry[info]; -- the "target:" field
BuildSourceEntry[info]; -- the "replacement:" field
heights[0] ← layout.heightSoFar+layout.entryVSpace;
layout.heightSoFar ← layout.heightSoFar+2;
----------------------------
BuildSearchButtons[info]; -- the various choices for seaching
ToNext[layout];
BuildInitCapEntry[info]; -- Capitalize like first replaced char or not
ToMiddle[layout];
BuildOperationEntry[info]; -- Do Replace / Do Operations Specified Below
ToNext[layout];
BuildSubstituteEntry[info]; -- the within/after/entire choice
ToNext[layout];
BuildMiniPatternDocEntry[info];
heights[1] ← layout.heightSoFar+layout.entryVSpace+1;
HRule[layout];
----------------------------
BuildLooksButtons[info]; -- caret/selection looks, Looks:, Get, Set, etc.
ToNext[layout]; HRule[layout];
----------------------------
BuildTypeButtons[info]; -- type names
ToNext[layout]; HRule[layout];
----------------------------
BuildStyleButtons[info]; -- style names
ToNext[layout];
heights[2] ← layout.heightSoFar+layout.entryVSpace+1;
HRule[layout];
----------------------------
BuildPropertyButtons[info]; -- property values
HRule[layout];
----------------------------
BuildSortButtons[info]; -- Sort increasing/decreasing; sort text/lines/branches; Sort
ToNext[layout]; HRule[layout];
----------------------------
BuildOperationField[info]; -- the "Operations:" field
VGap[layout];
BuildGetAndSetOpsEntries[info]; -- "GetLast" "SetCom" "GetCom" etc.
VGap[layout];
BuildFileListEntries[info]; -- the "Files:" field and the DoForEachFile command
VGap[layout];
heights[3] ← layout.heightSoFar+layout.entryVSpace+1;
HRule[layout];
----------------------------
BuildExtraButtons[info]; -- the low level edit commands
HRule[layout];
----------------------------
--BuildPatternDocEntry[info];-- -- explaining special chars for patterns
----------------------------
currentHeightIndex ← 0;
ViewerOps.SetOpenHeight[layout.container, heights[currentHeightIndex]];
};
mainToolInfo ← info;
RETURN [NIL, "Created new Edit Tool."];
};
Commander.Register["EditTool", InitToolCommand, "Create a Tioga Edit Tool"];
[] ← InitToolCommand[NIL];
[] ← ViewerEvents.RegisterEventProc[MyDestroy, destroy];
}.
..