<> <> <> <<>> <> <<>> 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 <> <<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>> <<};>> <> 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]; }; <<>> <> 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]; }; <> 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]; }; <> ActivityProc: Commander.CommandProc = { <<[cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL]>> 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"; }; <> <> <<>> 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.