-- EditToolTopImpl.mesa; Edited by Paxton on December 30, 1982 10:26 am
-- Edited by McGregor on September 21, 1982 3:20 pm
Last Edited by: Maxwell, January 14, 1983 8:39 am
DIRECTORY -- a lot of extra junk in this list
EditToolPrivate,
EditToolBuilder,
Atom,
Buttons,
Convert,
UserExec,
EditNotify,
Inline,
IO,
UndoEvent,
Labels,
List,
Menus,
MessageWindow,
NodeAddrs,
Rope,
RopeEdit,
RopeReader,
Rules,
RunReader,
Runtime,
TextEdit,
TextFind,
TextLooks,
TextLooksSupport,
TextNode,
TEditDocument,
TEditInput,
TEditInputOps,
TEditOps,
TreeFind,
TypeScript,
UserTerminal,
ViewerOps,
ViewerClasses,
ViewerEvents,
ViewerSpecs;
EditToolTopImpl: CEDAR PROGRAM
IMPORTS EditToolPrivate, EditToolBuilder, UserExec, Menus, MessageWindow,
Runtime, TEditInput, TextNode, ViewerEvents, ViewerOps
EXPORTS EditToolPrivate =
{ OPEN ViewerSpecs, 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], 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: UserExec.CommandProc = { OPEN IO;
name: Rope.ROPE ← "EditTool";
viewer: ViewerClasses.Viewer ← ViewerOps.FindViewer[name];
mainEditTool: BOOLEAN ← viewer = NIL;
info: Info ← TextNode.pZone.NEW[InfoRec];
info.layout ← TextNode.pZone.NEW[LayoutRec];
IF ~mainEditTool THEN { -- one already exists
IF viewer.iconic THEN ViewerOps.OpenIcon[viewer];
MessageWindow.Append["EditTool already exists",TRUE];
RETURN };
IF firstTime THEN firstTime ← FALSE ELSE ReRegister[];
{ OPEN info;
interrupt ← NEW[BOOLEANFALSE];
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;
};
TRUSTED {IF Runtime.IsBound[UserExec.RegisterCommand] THEN
UserExec.RegisterCommand["EditTool", InitToolCommand, "Create a Tioga Edit Tool"]};
[] ← InitToolCommand[NIL, NIL];
[] ← ViewerEvents.RegisterEventProc[MyDestroy, destroy];
}.
..