<> <> <> <> <<>> DIRECTORY Atom, BasicTime, Buttons, Commander, CommandTool, Convert, IO, MessageWindow, Process, Rope, UserProfile, ViewerOps; NewClockImpl: CEDAR PROGRAM IMPORTS Atom, BasicTime, Buttons, CommandTool, Convert, IO, MessageWindow, Process, Rope, UserProfile, ViewerOps ~ BEGIN ROPE: TYPE ~ Rope.ROPE; CurrentTime: PROC RETURNS [time: ROPE] ~ { unpacked: BasicTime.Unpacked ~ BasicTime.Unpack[time: BasicTime.Now[]]; hour: CARDINAL _ unpacked.hour; IF NOT military AND hour > 12 THEN hour _ hour-12; IF hour = 0 THEN hour _ 12; time _ IO.PutFR["%2g:%02g", IO.card[hour], IO.card[unpacked.minute]]; IF seconds THEN time _ IO.PutFR["%g:%02g", IO.rope[time], IO.card[unpacked.second]]; }; start: ROPE ~ "12:00"; seconds: BOOL _ FALSE; military: BOOL _ FALSE; style: ATOM _ $WhiteOnBlack; StyleInit: UserProfile.ProfileChangedProc = { style _ Atom.MakeAtom[UserProfile.Token["NewClock.ButtonStyle", "WhiteOnBlack"]]; seconds _ UserProfile.Boolean["NewClock.Seconds", FALSE]; military _ UserProfile.Boolean["NewClock.Military", FALSE]; }; UpdateButtonNow: Buttons.ButtonProc = { SELECT mouseButton FROM red => Buttons.ReLabel[button: NARROW[parent], newName: CurrentTime[]]; yellow => { clock: BOOL _ FALSE; Proc: TYPE ~ ViewerOps.EnumProc; p1: Proc ~ {IF Rope.Equal[v.name, "Clock"] THEN clock _ TRUE}; p2: Proc ~ {IF Rope.Equal[v.name, "Clock"] THEN ViewerOps.OpenIcon[v]}; ViewerOps.EnumerateViewers[p1]; IF NOT clock THEN [] _ CommandTool.DoCommand ["///Commands/Clock", NEW[Commander.CommandObject _ [IO.RIS[NIL], IO.ROS[], IO.ROS[], NIL]]]; ViewerOps.EnumerateViewers[p2]; }; blue => MessageWindow.Append[ Convert.RopeFromTime[from: BasicTime.Now[], includeDayOfWeek: TRUE], TRUE]; ENDCASE; }; UpdateButton: PROC [button: Buttons.Button] ~ { Buttons.SetDisplayStyle[button: button, style: style]; DO Buttons.ReLabel[button: button, newName: CurrentTime[]]; Process.Pause[ticks: Process.SecondsToTicks[IF seconds THEN 1 ELSE 30]]; ENDLOOP; }; UserProfile.CallWhenProfileChanges[StyleInit]; TRUSTED { Process.Detach[FORK UpdateButton[ Buttons.Create[ info: [name: IF seconds THEN "12:00:00" ELSE "12:00"], proc: UpdateButtonNow, paint: FALSE] ]]; }; END.