<> <> <<>> DIRECTORY Buttons USING [Button, ButtonProc, Create], Convert USING [RopeFromInt], MessageWindow USING [Append, Blink], Rope USING [ActionType, Length, Map, ROPE], TEditOps USING [GetSelContents], TiogaOps USING [Delete, InsertRope]; BinaryConvert: CEDAR PROGRAM IMPORTS Buttons, Convert, Rope, MessageWindow, TEditOps, TiogaOps = BEGIN ROPE: TYPE = Rope.ROPE; binaryConvertButton: Buttons.Button _ Buttons.Create[ info: [name: "Binary: 10/8/16"], proc: BinaryConvertButton]; BinaryConvertButton: Buttons.ButtonProc = <<[parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: Menus.MouseButton _ red, shift: BOOL _ FALSE, control: BOOL _ FALSE]>> { selRope : ROPE _ TEditOps.GetSelContents[]; selLength : INT _ Rope.Length[selRope]; selValue : INT _ 0; valueRope : ROPE; mapProc : Rope.ActionType = { <<[c: CHAR] RETURNS [quit: BOOL _ FALSE]>> selValue _ selValue * 256 + ORD[c]; }; IF selLength = 0 OR selLength > 4 THEN { MessageWindow.Append["Make a selection of 1-4 characters.", TRUE]; MessageWindow.Blink[]; RETURN; }; [] _ Rope.Map[base: selRope, action: mapProc]; valueRope _ Convert.RopeFromInt[from: selValue, base: (SELECT mouseButton FROM red => 10, yellow => 8, ENDCASE => 16)]; IF shift THEN { TiogaOps.Delete[]; TiogaOps.InsertRope[valueRope]; } ELSE MessageWindow.Append[valueRope, TRUE]; }; END.