TiogaExtraOpsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
written by Bill Paxton. June 1982
Last Edited by: Paxton, January 10, 1983 4:23 pm
Last Edited by: Plass, March 29, 1985 5:48:25 pm PST
Doug Wyatt, April 14, 1985 8:02:18 pm PST
DIRECTORY
EditSpan USING [CompareNodeOrder, NodeOrder],
NodeProps USING [CopyInfoProc, GetProp, MapProps, NullCopy, NullRead, NullWrite, PutProp, Register, RemProp],
PutGet USING [FromFile, ToFile],
Rope USING [ROPE],
TEditDocument USING [SpinAndLock, TEditDocumentData, Unlock],
TEditInput USING [CommandProc, FreeTree, Register, UnRegister],
TextNode USING [Body, FirstChild, FirstSibling, LastChild, LastLocWithin, LastSibling, LastWithin, Location, NarrowToTextNode, Next, Parent, Previous, Ref, RefTextNode, Root, StepBackward, StepForward],
TiogaExtraOps USING [CopyInfoProc, MapPropsAction, ReadSpecsProc, WriteSpecsProc],
TiogaOps USING [CommandProc, SetSelection],
TiogaOpsDefs USING [Location, NodeBody, Order, Ref, Viewer, WhichSelection];
TiogaExtraOpsImpl: CEDAR PROGRAM
IMPORTS EditSpan, NodeProps, PutGet, TEditDocument, TEditInput, TextNode, TiogaOps
EXPORTS TiogaOps, TiogaOpsDefs, TiogaExtraOps
= BEGIN OPEN TiogaOps, TiogaExtraOps, TiogaOpsDefs;
ROPE: TYPE ~ Rope.ROPE;
Ref: TYPE = REF NodeBody; -- points to a Tioga node
NodeBody: PUBLIC TYPE = TextNode.Body;
Miscellaneous operations on nodes
GetRope: PUBLIC PROC [node: Ref] RETURNS [ROPE] = {
txt: TextNode.RefTextNode = TextNode.NarrowToTextNode[node];
RETURN [IF txt=NIL THEN NIL ELSE txt.rope] };
Parent: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TextNode.Parent[node]] };
Root: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TextNode.Root[node]] };
Next: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TextNode.Next[node]] };
Previous: PUBLIC PROC [node: Ref, parent: Ref ← NIL] RETURNS [nx: Ref] = {
RETURN [TextNode.Previous[node]] };
StepForward: PUBLIC PROC [node: Ref] RETURNS [nx: Ref] = {
RETURN [TextNode.StepForward[node]] };
StepBackward: PUBLIC PROC [node: Ref, parent: Ref ← NIL] RETURNS [back: Ref] = {
RETURN [TextNode.StepBackward[node, parent]] };
FirstSibling: PUBLIC PROC [node: Ref] RETURNS [Ref] = {
RETURN [TextNode.FirstSibling[node]] };
LastSibling: PUBLIC PROC [node: Ref] RETURNS [Ref] = {
RETURN [TextNode.LastSibling[node]] };
LastWithin: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TextNode.LastWithin[node]] };
LastLocWithin: PUBLIC PROC [node: Ref] RETURNS [Location] = {
loc: TextNode.Location ~ TextNode.LastLocWithin[node];
RETURN [[loc.node, loc.where]];
};
FirstChild: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TextNode.FirstChild[node]] };
LastChild: PUBLIC PROC [node: Ref] RETURNS [Ref] = { RETURN [TextNode.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: TEditDocument.TEditDocumentData = NARROW[viewer.data];
IF tdd = NIL THEN RETURN [NIL];
[] ← TEditDocument.SpinAndLock[tdd, "ViewerDoc"]; -- make sure nothing else going on
root ← tdd.text;
TEditDocument.Unlock[tdd] };
Node Property Lists
PutProp: PUBLIC PROC [n: Ref, name: ATOM, value: REF] = {
NodeProps.PutProp[n, name, value] };
GetProp: PUBLIC PROC [n: Ref, name: ATOM] RETURNS [REF] = {
RETURN [NodeProps.GetProp[n, name]] };
RemProp: PUBLIC PROC [n: Ref, name: ATOM] = {
NodeProps.RemProp[n, name] };
MapProps: PUBLIC PROC [
n: Ref, action: MapPropsAction, formatFlag, commentFlag: BOOLTRUE]
RETURNS [BOOL] = {
RETURN [NodeProps.MapProps[n, action, formatFlag, commentFlag]] };
read, write, copy props
RegisterPropProc: PUBLIC PROC [name: ATOM,
reader: ReadSpecsProc, writer: WriteSpecsProc, copier: CopyInfoProc] = {
NodeProps.Register[name, reader, writer, copier];
};
NullRead: PUBLIC ReadSpecsProc = { [] ← NodeProps.NullRead[name, specs] };
NullWrite: PUBLIC WriteSpecsProc = { [] ← NodeProps.NullWrite[name, value] };
NullCopy: PUBLIC CopyInfoProc = { [] ← NodeProps.NullCopy[name, value] };
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 PROC [loc1, loc2: Location] RETURNS [order: Order] = {
order ← NodeOrder[EditSpan.CompareNodeOrder[loc1.node, loc2.node]];
IF order=same THEN order ← SELECT loc1.where FROM
< loc2.where => before,
= loc2.where => same,
ENDCASE => after };
CompareNodeOrder: PUBLIC PROC [node1, node2: Ref] RETURNS [order: Order] = {
RETURN [NodeOrder[EditSpan.CompareNodeOrder[node1, node2]]] };
File I/O
GetFile: PUBLIC PROC [name: ROPE] RETURNS [root: Ref] = {
RETURN [PutGet.FromFile[name]] };
PutFile: PUBLIC PROC [name: ROPE, root: Ref] = { [] ← PutGet.ToFile[name, root] };
FreeTree: PUBLIC PROC [root: Ref] = { TEditInput.FreeTree[root] };
Make point selection
SelectPoint: PUBLIC PROC [
viewer: Viewer, caret: Location, which: WhichSelection ← primary] = {
TiogaOps.SetSelection[viewer: viewer, start: caret, end: caret, level: point, which: which]
};
Command registration
RegisterCommand: PUBLIC PROC [name: ATOM, proc: CommandProc, before: BOOLTRUE] = {
TEditInput.Register[name, proc, before] };
UnRegisterCommand: PUBLIC PROC [name: ATOM, proc: CommandProc] = {
TEditInput.UnRegister[name, proc] };
END.