<<-- EditToolOpsImpl.mesa; Edited by Paxton on June 2, 1983 9:20 am>> <<-- Edited by McGregor on September 20, 1982 2:42 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: BOOL _ TRUE; 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; 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 viewer.newVersion THEN viewer _ TiogaMenuOps.CloseAndNewViewer[viewer] ELSE TiogaMenuOps.Empty[viewer]; TiogaMenuOps.Load[viewer, filename]; IF NOT viewer.name.Equal["No Name"] THEN { -- got the file IF do THEN { TiogaOps.SelectDocument[viewer]; TEditInput.Interpret[viewer, params]; IF viewer.newVersion THEN 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]; <> 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: BOOL _ FALSE; 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.name.Equal["No Name"] 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 "]; }; ---------------------------- }...