-- EditToolOpsImpl.mesa; Edited by Paxton on December 30, 1982 10:23 am
-- Edited by McGregor on September 20, 1982 2:42 pm
Last Edited by: Maxwell, January 19, 1983 2:54 pm
DIRECTORY
EditToolPrivate,
EditToolBuilder,
Buttons,
Convert,
EditNotify,
FileIO,
IO,
Labels,
List,
Menus,
MessageWindow,
NameSymbolTable,
NodeAddrs,
NodeProps,
NodeStyle,
Rope,
RopeEdit,
RopeReader,
RunReader,
TextEdit,
TextFind,
TextLooks,
TextLooksSupport,
TextNode,
TEditDisplay,
TEditDocument,
TEditHistory,
TEditInput,
TEditOps,
TEditProfile,
TEditRefresh,
TEditSelection,
TEditTouchup,
TiogaMenuOps,
TiogaOpsDefs,
TiogaOps,
TreeFind,
TypeScript,
UndoEvent,
UserTerminal,
ViewerOps,
ViewerClasses,
ViewerMenus,
WindowManager;
EditToolOpsImpl: CEDAR PROGRAM
IMPORTS EditToolPrivate, EditToolBuilder, FileIO, IO, List, MessageWindow, Rope, TEditInput, TEditOps, TextEdit, TEditHistory, TEditSelection, TiogaMenuOps, TiogaOps, TEditProfile, TypeScript, UndoEvent, ViewerOps
EXPORTS EditToolPrivate
SHARES Rope =
{ OPEN ViewerClasses, EditToolBuilder, EditToolPrivate;
----------------------------
Offset: TYPE = TextNode.Offset;
----------------------------
opsAtom: LIST OF REF = Register[$Operations,OpsArgOp];
clearOpsAtom: LIST OF REF = Register[$ClearOperations,ClearOpsArgOp];
OpsButton: Buttons.ButtonProc = {
DoButton[opsAtom,clearOpsAtom, mouseButton=red] };
OpsArgOp: TEditInput.CommandProc = { OpsArg[mainToolInfo] };
OpsArg: PROC [info: Info] = { DataFieldButton[info.opsArg,FALSE] };
ClearOpsArgOp: TEditInput.CommandProc = { ClearOpsArg[mainToolInfo] };
ClearOpsArg: PROC [info: Info] = { DataFieldButton[info.opsArg,TRUE] };
BuildOperationField: PUBLIC PROC [info: Info] = { OPEN info;
[,opsArg] ← BuildDataFieldPair[layout, "Operations:", OpsButton, info, 2] };
GetOps: PUBLIC PROC [info: Info] RETURNS [list: LIST OF REF ANY] = { OPEN IO, info;
rope: Rope.ROPE ← TextEdit.GetRope[GetDataNode[opsArg]];
h: Handle ← CreateInputStreamFromRope[rope];
item: REF ANY;
WHILE (item ← GetRefAny[h ! EndOfStream => { item ← NIL; CONTINUE}]) # NIL DO
list ← List.Nconc1[list, item];
ENDLOOP;
--h.Close[];
};
----------------------------
BuildFileListEntries: PUBLIC PROC [info: Info] = { OPEN info;
[] ← BuildButton[layout, "DoForEachFile", DoFilesListButton, info, TRUE];
[] ← BuildButton[layout, "SearchEachFile", SearchFilesListButton, info, TRUE];
HGap[layout];
[,filesArg] ← BuildDataFieldPair[layout, "Files:", FilesListButton, info, 1];
};
----------------------------
filesListAtom: LIST OF REF = Register[$FilesList,FilesListOp];
clearFilesListAtom: LIST OF REF = Register[$ClearFilesList,ClearFilesListOp];
FilesListButton: Buttons.ButtonProc = {
DoButton[filesListAtom,clearFilesListAtom, mouseButton=red] };
FilesListOp: TEditInput.CommandProc = { FilesList[mainToolInfo] };
FilesList: PROC [info: Info] = { DataFieldButton[info.filesArg,FALSE] };
ClearFilesListOp: TEditInput.CommandProc = { ClearFilesList[mainToolInfo] };
ClearFilesList: PROC [info: Info] = { DataFieldButton[info.filesArg,TRUE] };
----------------------------
searchFilesListAtom: LIST OF REF = Register[$SearchEachFile,SearchFilesListOp];
SearchFilesListButton: Buttons.ButtonProc = { DoButton[searchFilesListAtom] };
SearchFilesListOp: TEditInput.CommandProc = { SearchFilesListCom[mainToolInfo] };
SearchFilesListCom: PROC [info: Info] = { DoFilesList[info, FALSE] };
----------------------------
doFilesListAtom: LIST OF REF = Register[$DoForEachFile,DoFilesListOp];
DoFilesListButton: Buttons.ButtonProc = { DoButton[doFilesListAtom] };
DoFilesListOp: TEditInput.CommandProc = { DoFilesListCom[mainToolInfo] };
DoFilesListCom: PROC [info: Info] = { DoFilesList[info, TRUE] };
DoFilesList: PROC [info: Info, do: BOOL] = {
GetFilesList: PROC [fileName: Rope.ROPE] RETURNS [filesList: Rope.ROPE] = {
readChar: SAFE PROC RETURNS [CHAR] = { RETURN [IO.GetChar[s]] };
len: INT;
s: IO.STREAM;
found: BOOLTRUE;
s ← FileIO.Open[fileName, read ! FileIO.OpenFailed => {
IF why=fileNotFound THEN { found ← FALSE; CONTINUE }}];
IF ~found THEN -- try it with ".cm" as extension
s ← FileIO.Open[Rope.Concat[fileName, ".cm"], read ! FileIO.OpenFailed => {
IF why=fileNotFound THEN GOTO Quit}];
len IO.GetLength[s];
filesList ← Rope.FromProc[len, readChar];
IO.Close[s];
EXITS Quit => {
MessageWindow.Append[Rope.Concat[fileName, " not found"], TRUE];
MessageWindow.Blink[];
filesList ← NIL };
};
DoEachInList: PROC [list: Rope.ROPE] RETURNS [remainder: Rope.ROPE] = {
offset: INT ← 0;
new: BOOLFALSE;
DO-- process each file
filename: Rope.ROPE;
IF info.interrupt^ THEN RETURN [Rope.Substr[list, offset]];
[filename, offset] ← TEditProfile.GetToken[list, offset];
IF Rope.Size[filename]=0 THEN RETURN [NIL];
IF Rope.Fetch[filename,0]='@ THEN { -- process list
sub: Rope.ROPE = DoEachInList[GetFilesList[Rope.Substr[filename,1]]];
IF sub=NIL THEN LOOP; -- finished the sublist
RETURN [Rope.Cat[sub, " ", Rope.Substr[list, offset]]] };
IF new OR viewer.newVersion THEN
viewer ← TiogaMenuOps.CloseAndNewViewer[viewer]
ELSE TiogaMenuOps.Empty[viewer];
TiogaMenuOps.Load[viewer, filename];
IF viewer.file#NIL THEN { -- got the file
IF do THEN {
TiogaOps.SelectDocument[viewer];
TEditInput.Interpret[viewer, params];
new ← viewer.newVersion; -- if make an edit, leave icon rather than reuse viewer
ViewerOps.SaveViewer[viewer];
UndoEvent.Reset[event] } -- so we don't fill up VM with trash
ELSE { -- search
node: TiogaOpsDefs.Ref = TiogaOps.FirstChild[TiogaOps.ViewerDoc[viewer]];
TiogaOps.SetSelection[viewer, [node,0], [node,0], point];
make point selection at start of document
IF TrySearch[forwards, info] THEN
found ← info.interrupt^ ← TRUE; -- so will stop after this one
}};
ENDLOOP
};
params: LIST OF REF ANY;
pSel: TEditDocument.Selection;
viewer: Viewer;
found: BOOLFALSE;
event: UndoEvent.Ref = TEditInput.CurrentEvent[];
rope: Rope.ROPE ← TextEdit.GetRope[GetDataNode[info.filesArg]];
info.interrupt^ ← FALSE;
IF do AND (params ← GetOps[info])=NIL THEN {
OPEN MessageWindow; Append["Enter operations.", TRUE]; Blink[]; RETURN };
IF rope=NIL THEN {
OPEN MessageWindow; Append["Enter list of files.", TRUE]; Blink[]; RETURN };
TEditInput.CloseEvent[];
TEditSelection.LockSel[primary, "DoFilesList"];
pSel ← TEditOps.GetSelData[];
viewer ← IF pSel.viewer#NIL AND pSel.viewer.parent=NIL
AND ~TypeScript.IsATypeScript[pSel.viewer]
THEN IF pSel.viewer.file=NIL THEN pSel.viewer
ELSE TiogaMenuOps.CloseAndNewViewer[pSel.viewer]
ELSE TiogaMenuOps.New[];
TEditOps.SetTextContents[info.filesArg, DoEachInList[rope]];
TEditSelection.UnlockSel[primary];
IF do OR (~found AND ~viewer.newVersion) THEN ViewerOps.DestroyViewer[viewer];
};
----------------------------
BuildGetAndSetOpsEntries: PUBLIC PROC [info: Info] = { OPEN info;
[] ← BuildButton[layout, "GetLast", DoGetLastOpsButton, info];
[] ← BuildButton[layout, "Do", DoOpsButton, info];
[] ← BuildButton[layout, "Begin", DoBeginButton, info];
[] ← BuildButton[layout, "End", DoEndButton, info];
[] ← BuildButton[layout, "SetCom", DoSetOpsButton, info];
[] ← BuildButton[layout, "GetCom", DoGetOpsButton, info];
HGap[layout];
BuildComNumField[info]; -- "Command number [0..9]:" field
};
doGetLastOpsAtom: LIST OF REF = Register[$DoGetLastOps,DoGetLastOpsOp];
DoGetLastOpsButton: Buttons.ButtonProc = {
DoButton[doGetLastOpsAtom] };
DoGetLastOpsOp: TEditInput.CommandProc = {
DoGetLastOpsCom[mainToolInfo]; RETURN [FALSE] };
DoGetLastOpsCom: PROC [info: Info] = {
ShowOps[TEditInput.GetRepeatSequence[],info] };
ShowOps: PROC [list: LIST OF REF ANY, info: Info] = {
TEditOps.SetTextContents[info.opsArg, ConvertList[list]] };
doOpsAtom: LIST OF REF = Register[$DoOps,DoOpsOp];
DoOpsButton: Buttons.ButtonProc = {
DoButton[doOpsAtom] };
DoOpsOp: TEditInput.CommandProc = { DoOpsCom[mainToolInfo] };
DoOpsCom: PUBLIC PROC [info: Info] = {
pSel: TEditDocument.Selection ← TEditOps.GetSelData[];
params: LIST OF REF ANY;
IF ~CheckPSel[pSel] THEN {
OPEN MessageWindow; Append["Make a selection.", TRUE]; Blink[]; RETURN };
IF (params ← GetOps[info])=NIL THEN {
OPEN MessageWindow; Append["Enter operations.", TRUE]; Blink[]; RETURN };
TEditSelection.LockSel[primary, "DoOpsCom"];
TEditInput.Interpret[pSel.viewer, params];
TEditSelection.UnlockSel[primary] };
SetCom: PROC [num: [0..9], info: Info] = {
list: LIST OF REF ANY ← GetOps[info];
TEditInput.SetCommand[num,list];
};
doSetOpsAtom: LIST OF REF = Register[$DoSetOps,DoSetOpsOp];
DoSetOpsButton: Buttons.ButtonProc = {
DoButton[doSetOpsAtom] };
DoSetOpsOp: TEditInput.CommandProc = { DoSetOpsCom[mainToolInfo] };
DoSetOpsCom: PROC [info: Info] = {
num: INT ← GetInt[info.comArg ! BadNumber => GOTO BadNum];
IF num NOT IN [0..9] THEN GOTO BadNum;
SetCom[num,info];
EXITS BadNum => { OPEN MessageWindow;
Append["Enter number from 0 to 9 in Command Number field", TRUE];
Blink[] } };
doGetOpsAtom: LIST OF REF = Register[$DoGetOps,DoGetOpsOp];
DoGetOpsButton: Buttons.ButtonProc = {
DoButton[doGetOpsAtom] };
DoGetOpsOp: TEditInput.CommandProc = { DoGetOpsCom[mainToolInfo] };
DoGetOpsCom: PROC [info: Info] = {
num: INT ← GetInt[info.comArg ! BadNumber => GOTO BadNum];
IF num NOT IN [0..9] THEN GOTO BadNum;
ShowOps[TEditInput.GetCommand[num],info];
EXITS BadNum => { OPEN MessageWindow;
Append["Enter number from 0 to 9 in Command Number field", TRUE];
Blink[] } };
doBeginAtom: LIST OF REF = Register[$DoBegin,DoBeginOp];
DoBeginButton: Buttons.ButtonProc = {
DoButton[doBeginAtom] };
DoBeginOp: TEditInput.CommandProc = { DoBeginCom[mainToolInfo] };
beginEvent: INT ← 0;
DoBeginCom: PROC [info: Info] = {
[] ← TEditInput.GetRepeatSequence[]; -- to make sure the event is terminated
beginEvent ← TEditHistory.CurrentEventNumber[];
TEditInput.CloseEvent[] };
doEndAtom: LIST OF REF = Register[$DoEnd,DoEndOp];
DoEndButton: Buttons.ButtonProc = {
DoButton[doEndAtom] };
DoEndOp: TEditInput.CommandProc = { DoEndCom[mainToolInfo] };
DoEndCom: PROC [info: Info] = {
list: LIST OF REF ANY;
endEvent: INT;
[] ← TEditInput.GetRepeatSequence[]; -- to make sure the event is terminated
endEvent ← TEditHistory.CurrentEventNumber[];
IF endEvent-beginEvent > TEditHistory.SliceSize[] THEN { OPEN MessageWindow;
Append["Not all events still recorded. Some missing at start.", TRUE];
Blink[] };
FOR i: INT ← beginEvent+1, i+1 UNTIL i > endEvent DO
list ← List.Append[list, TEditHistory.GetRepeatList[i]];
ENDLOOP;
ShowOps[list,info] };
----------------------------
comNumAtom: LIST OF REF = Register[$CommandNumber,DoComNumOp];
clearComNumAtom: LIST OF REF = Register[$ClearCommandNumber,ClearComNumOp];
ComNumButton: Buttons.ButtonProc = {
DoButton[comNumAtom,clearComNumAtom, mouseButton=red] };
DoComNumOp: TEditInput.CommandProc = { DoComNum[mainToolInfo] };
DoComNum: PROC [info: Info] = { DataFieldButton[info.comArg,FALSE] };
ClearComNumOp: TEditInput.CommandProc = { ClearComNum[mainToolInfo] };
ClearComNum: PROC [info: Info] = { DataFieldButton[info.comArg,TRUE] };
BuildComNumField: PUBLIC PROC [info: Info] = { OPEN info;
[,comArg] ← BuildDataFieldPair[layout, "Command [0..9]:", ComNumButton, info, 1];
TEditOps.SetTextContents[comArg, "1 "]; };
----------------------------
}...