TiogaFileOpsImpl.mesa
Copyright Ó 1985, 1991, 1992 by Xerox Corporation. All rights reserved.
written by Bill Paxton, June 1982
last written by Paxton. September 22, 1982 1:19 pm
Last Edited by: Maxwell, January 6, 1983 11:48 am
Rick Beach, March 28, 1985 10:02:14 am PST
Michael Plass, March 27, 1985 5:06:37 pm PST
Doug Wyatt, December 23, 1991 5:37 pm PST
DIRECTORY
Atom USING [MakeAtom],
PFS USING [PathFromRope],
Rope USING [IsEmpty, ROPE],
TextEdit USING [ChangeLooks, ChangeStyle, PutFormat, ReplaceByRope],
TextNode USING [LastChild, NewTextNode, Root],
Tioga USING [Looks, noLooks, Node, NodeRep],
TiogaFileOps,
TiogaIO USING [ToFile];
TiogaFileOpsImpl: CEDAR PROGRAM
IMPORTS Atom, PFS, Rope, TextEdit, TextNode, TiogaIO
EXPORTS TiogaFileOps
= BEGIN OPEN TiogaFileOps;
Ref: TYPE = Tioga.Node; -- points to a Tioga node
NodeBody: PUBLIC TYPE = Tioga.NodeRep;
CreateRoot: PUBLIC PROC RETURNS [root: Ref] = {
root ¬ TextNode.NewTextNode[];
};
InsertNode: PUBLIC PROC [x: Ref, child: BOOL ¬ FALSE] RETURNS [new: Ref] = {
-- if ~child then new is sibling of x
-- else new is first child of x
new ¬ TextNode.NewTextNode[];
IF child
THEN { new.next ¬ x.child; x.child ¬ new; new.parent ¬ x }
ELSE { new.next ¬ x.next; x.next ¬ new; new.parent ¬ x.parent };
};
InsertAsLastChild: PUBLIC PROC [x: Ref, prevLast: Ref ¬ NIL] RETURNS [new: Ref] = {
-- prevLast is optional accelerator
IF NOT(prevLast#NIL AND prevLast.next=NIL AND prevLast.parent=x)
THEN prevLast ¬ TextNode.LastChild[x];
new ¬ IF prevLast=NIL
THEN InsertNode[x, TRUE]
ELSE InsertNode[prevLast, FALSE];
};
SetContents: PUBLIC PROC [x: Ref, txt: Rope.ROPE] = {
[] ¬ TextEdit.ReplaceByRope[root: TextNode.Root[x], dest: x, rope: txt];
};
AddLooks: PUBLIC PROC [x: Ref, start, len: INT, look: CHAR ['a..'z], root: Ref ¬ NIL] = {
looks: Tioga.Looks ¬ Tioga.noLooks;
looks[look] ¬ TRUE;
IF root = NIL THEN root ¬ TextNode.Root[x];
TextEdit.ChangeLooks[root: root, text: x, add: looks, start: start, len: len];
};
SetFormat: PUBLIC PROC [x: Ref, format: Rope.ROPE] = {
name: ATOM ¬ IF format.IsEmpty THEN NIL ELSE Atom.MakeAtom[format];
TextEdit.PutFormat[x, name];
};
SetStyle: PUBLIC PROC [x: Ref, style: Rope.ROPE] = { TextEdit.ChangeStyle[x, style] };
Store: PUBLIC PROC [x: Ref, filename: Rope.ROPE] = {
[] ¬ TiogaIO.ToFile[PFS.PathFromRope[filename], x];
};
END.