TiogaExtraOpsImpl.Mesa
written by Bill Paxton. June 1982
last written by Paxton. December 30, 1982 11:19 am
Last Edited by: Paxton, January 10, 1983 4:23 pm
Last Edited by: Plass, April 15, 1983 2:04 pm
DIRECTORY
TiogaOpsDefs,
TiogaExtraOps,
TiogaNode,
TiogaNodeOps,
NodeProps,
EditSpan,
PutGet,
Rope,
TiogaDocument,
TiogaInput,
TiogaOps;
TiogaExtraOpsImpl: CEDAR PROGRAM
IMPORTS
NodeProps,
EditSpan,
PutGet,
TiogaInput,
TiogaDocument,
TiogaNodeOps,
TiogaOps
EXPORTS TiogaOps, TiogaOpsDefs, TiogaExtraOps =
BEGIN OPEN TiogaOps, TiogaExtraOps, TiogaOpsDefs;
Ref: TYPE = REF NodeBody; -- points to a Tioga node
NodeBody: PUBLIC TYPE = TiogaNode.Node;
Miscellaneous operations on nodes
GetRope: PUBLIC PROC [node: Ref] RETURNS [ROPE] = {
txt: TiogaNode.RefTextNode = TiogaNodeOps.NarrowToTextNode[node];
RETURN [IF txt=NIL THEN NIL ELSE txt.rope] };
Parent: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TiogaNodeOps.Parent[node]] };
Root: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TiogaNodeOps.Root[node]] };
Next: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TiogaNodeOps.Next[node]] };
Previous: PUBLIC PROC [node: Ref, parent: Ref ← NIL] RETURNS [nx: Ref] = {
RETURN [TiogaNodeOps.Previous[node]] };
StepForward: PUBLIC PROC [node: Ref] RETURNS [nx: Ref] = {
RETURN [TiogaNodeOps.StepForward[node]] };
StepBackward: PUBLIC PROC [node: Ref, parent: Ref ← NIL] RETURNS [back: Ref] = {
RETURN [TiogaNodeOps.StepBackward[node, parent]] };
FirstSibling: PUBLIC PROC [node: Ref] RETURNS [Ref] = {
RETURN [TiogaNodeOps.FirstSibling[node]] };
LastSibling: PUBLIC PROC [node: Ref] RETURNS [Ref] = {
RETURN [TiogaNodeOps.LastSibling[node]] };
LastWithin: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TiogaNodeOps.LastWithin[node]] };
DocLoc: PROC [loc: Location] RETURNS [TiogaNode.Location] = INLINE {
RETURN [[loc.node, loc.where]] };
MyLoc: PROC [loc: TiogaNode.Location] RETURNS [Location] = INLINE {
RETURN [[loc.node, loc.where]] };
LastLocWithin: PUBLIC PROC [node: Ref] RETURNS [Location] = {
RETURN [MyLoc[TiogaNodeOps.LastLocWithin[node]]] };
FirstChild: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TiogaNodeOps.FirstChild[node]] };
LastChild: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TiogaNodeOps.LastChild[node]] };
IsDirty: PUBLIC PROC [node: Ref] RETURNS [BOOL] = { RETURN [node.dirty] };
IsNew: PUBLIC PROC [node: Ref] RETURNS [BOOL] = { RETURN [node.new] };
ClearDirty: PUBLIC PROC [node: Ref] = { node.dirty ← FALSE };
ClearNew: PUBLIC PROC [node: Ref] = { node.new ← FALSE };
ViewerDoc: PUBLIC PROC [viewer: Viewer] RETURNS [root: Ref] = {
tdd: TiogaDocument.TiogaDocumentData = NARROW[viewer.data];
IF tdd = NIL THEN RETURN [NIL];
[] ← TiogaDocument.SpinAndLock[tdd, "ViewerDoc"]; -- make sure nothing else going on
root ← tdd.text;
TiogaDocument.Unlock[tdd] };
Node Property Lists
PutProp: PUBLIC PROCEDURE [n: Ref, name: ATOM, value: REF] = {
NodeProps.PutProp[n, name, value] };
GetProp: PUBLIC PROCEDURE [n: Ref, name: ATOM] RETURNS [REF] = {
RETURN [NodeProps.GetProp[n, name]] };
RemProp: PUBLIC PROCEDURE [n: Ref, name: ATOM] = {
NodeProps.RemProp[n, name] };
MapProps: PUBLIC PROC [
n: Ref, action: MapPropsAction, typeFlag, commentFlag: BOOLEANTRUE]
RETURNS [BOOLEAN] = {
RETURN [NodeProps.MapProps[n, action, typeFlag, commentFlag]] };
read, write, copy props
Register: PUBLIC PROC [name: ATOM,
reader: ReadSpecsProc,
writer: WriteSpecsProc,
copier: CopyInfoProc] = { NodeProps.Register[name, reader, writer, copier] };
NullRead: PUBLIC ReadSpecsProc = { [] ← NodeProps.NullRead[name, specs, n] };
NullWrite: PUBLIC WriteSpecsProc = { [] ← NodeProps.NullWrite[name, value, n] };
NullCopy: PUBLIC CopyInfoProc = { [] ← NodeProps.NullCopy[name, value, from, to] };
Comparing order of nodes or locations in document
NodeOrder: PROC [order: EditSpan.NodeOrder] RETURNS [Order] = {
RETURN [SELECT order FROM before => before, same => same, after => after, disjoint => disjoint, ENDCASE => ERROR] };
CompareLocOrder: PUBLIC PROCEDURE [loc1, loc2: Location] RETURNS [order: Order] = TRUSTED {
order ← NodeOrder[EditSpan.CompareNodeOrder[LOOPHOLE[loc1.node], LOOPHOLE[loc2.node]]];
IF order=same THEN order ← SELECT loc1.where FROM
< loc2.where => before,
= loc2.where => same,
ENDCASE => after };
CompareNodeOrder: PUBLIC PROCEDURE [node1, node2: Ref] RETURNS [order: Order] = {
RETURN [NodeOrder[EditSpan.CompareNodeOrder[node1, node2]]] };
File I/O
GetFile: PUBLIC PROCEDURE [name: ROPE] RETURNS [root: Ref] = {
RETURN [PutGet.FromFile[name]] };
PutFile: PUBLIC PROCEDURE [name: ROPE, root: Ref] = { [] ← PutGet.ToFile[name, root] };
FreeTree: PUBLIC PROCEDURE [root: Ref] = { TiogaInput.FreeTree[root] };
Make point selection
SelectPoint: PUBLIC PROC [
viewer: Viewer, caret: Location, which: WhichSelection ← primary] = TRUSTED {
TiogaOps.SetSelection[viewer: viewer, start: LOOPHOLE[caret], end: LOOPHOLE[caret], level: point, which: which] };
Command registration
RegisterCommand: PUBLIC PROC [name: ATOM, proc: CommandProc, before: BOOLTRUE] = {
TiogaInput.Register[name, proc, before] };
UnRegisterCommand: PUBLIC PROC [name: ATOM, proc: CommandProc] = {
TiogaInput.UnRegister[name, proc] };
END.