ActiveSampler.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Doug Terry, July 9, 1987 9:58:59 am PDT
A sampling of transformations for active Tioga nodes.
DIRECTORY
BasicTime USING [Now],
Commander USING [CommandProc, Register],
CommandTool USING [DoCommandRope, NextArgument],
Convert USING [Error, IntFromRope, RopeFromInt, RopeFromTime],
MessageWindow USING [Append],
NodeProps USING [GetProp, PutProp],
Rope USING [Equal, ROPE, Size],
TextLooks USING [CreateRun],
TextNodeRegistry USING [ActivityOn, ActivityProc, ProcSetRec, Ref, Register, SizeProc, TransformProc];
ActiveSampler: CEDAR PROGRAM
IMPORTS BasicTime, Commander, CommandTool, Convert, MessageWindow, NodeProps, Rope, TextLooks, TextNodeRegistry
~ BEGIN
Active=Activity
ActivityTransform: TextNodeRegistry.TransformProc = {
[node: TextNode.Ref, parent: TextNode.Ref, wantFirst: BOOLEAN, clientData: REF ANY] RETURNS [new: TextNode.Ref]
body
};
ActivitySize: TextNodeRegistry.SizeProc = {
[node: TextNode.Ref, clientData: REF ANY] RETURNS [size: INT]
body
};
ActivityActive: TextNodeRegistry.ActivityProc = {
[on: BOOLEAN, clientData: REF ANY]
body
};
Active=Command
CommandTransform: TextNodeRegistry.TransformProc = {
[node: TextNode.Ref, parent: TextNode.Ref, wantFirst: BOOLEAN, clientData: REF ANY] RETURNS [new: TextNode.Ref]
node.rope ← CommandTool.DoCommandRope[commandLine: node.rope, parent: NIL].out;
node.runs ← TextLooks.CreateRun[Rope.Size[node.rope]];
NodeProps.PutProp[node, $Active, NIL]; -- make node inactive
RETURN[node];
};
Active=Max
MaxTransform: TextNodeRegistry.TransformProc = {
[node: TextNode.Ref, parent: TextNode.Ref, wantFirst: BOOLEAN, clientData: REF ANY] RETURNS [new: TextNode.Ref]
max: INT ← 0;
FOR n: TextNodeRegistry.Ref ← node.child, n.next WHILE n#node DO
i: INT;
i ← Convert.IntFromRope[n.rope ! Convert.Error => {i ← -1; CONTINUE}];
max ← MAX[i, max];
ENDLOOP;
node.rope ← Convert.RopeFromInt[max];
node.runs ← TextLooks.CreateRun[Rope.Size[node.rope]];
RETURN[node];
};
Active=CurrentTime
CurrentTimeTransform: TextNodeRegistry.TransformProc = {
[node: TextNode.Ref, parent: TextNode.Ref, wantFirst: BOOLEAN, clientData: REF ANY] RETURNS [new: TextNode.Ref]
node.rope ← Convert.RopeFromTime[BasicTime.Now[]];
node.runs ← TextLooks.CreateRun[Rope.Size[node.rope]];
RETURN[node];
};
Toggling activity
ActivityProc: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: ROPENIL]
arg: Rope.ROPE = CommandTool.NextArgument[cmd];
SELECT TRUE FROM
Rope.Equal[s1: arg, s2: "on", case: FALSE] => {
[] ← TextNodeRegistry.ActivityOn[NIL, TRUE];
msg ← "Tioga activity turned on";
};
Rope.Equal[s1: arg, s2: "off", case: FALSE] => {
[] ← TextNodeRegistry.ActivityOn[NIL, FALSE];
msg ← "Tioga activity turned off";
};
ENDCASE => msg ← "usage: ActiveTioga on/off";
};
Registrations
TextNodeRegistry.Register[activity: $Activity, procs: NEW[TextNodeRegistry.ProcSetRec ← [activityOn: TRUE, transformProc: ActivityTransform, sizeProc: ActivitySize, activityProc: ActivityActive]]];
TextNodeRegistry.Register[activity: $CurrentTime, procs: NEW[TextNodeRegistry.ProcSetRec ← [activityOn: TRUE, transformProc: CurrentTimeTransform]]];
TextNodeRegistry.Register[activity: $Max, procs: NEW[TextNodeRegistry.ProcSetRec ← [activityOn: TRUE, transformProc: MaxTransform]]];
TextNodeRegistry.Register[activity: $Command, procs: NEW[TextNodeRegistry.ProcSetRec ← [activityOn: TRUE, transformProc: CommandTransform]]];
Commander.Register[key: "ActiveTioga", proc: ActivityProc, doc: "turn ActiveTioga on/off"];
END.