DIRECTORY Buttons, Commander, Convert, IO, MessageWindow, Rope, ViewerClasses, ViewerOps, ViewerTools, WordCount; WordCountButtonImpl: CEDAR PROGRAM IMPORTS Buttons, Commander, Convert, IO, MessageWindow, Rope, ViewerOps, ViewerTools, WordCount EXPORTS WordCount = { ROPE: TYPE = Rope.ROPE; CountSelection: PUBLIC PROC [tokenMode: BOOL ¬ FALSE] RETURNS [lines, words, characters: INT ¬ 0] ~ { [lines, words, characters] ¬ WordCount.CountRope[ViewerTools.GetSelectionContents[], tokenMode]; }; WCButton: Buttons.ButtonProc ~ { selection: BOOL ¬ mouseButton IN [red..yellow]; tokenMode: BOOL ¬ shift; msg: ROPE ¬ NIL; lines, words, characters: INT ¬ 0; [lines, words, characters] ¬ IF selection THEN CountSelection[tokenMode] ELSE WordCount.CountRope[NARROW[ViewerOps.GetViewer[ViewerTools.GetSelectedViewer[]]], tokenMode]; msg ¬ IO.PutFR1["%g: ", [rope[IF selection THEN "Selection" ELSE "Viewer"]]]; msg ¬ Rope.Cat[msg, "lines: ", Convert.RopeFromInt[from: lines, showRadix: FALSE]]; msg ¬ Rope.Cat[msg, ", words: ", Convert.RopeFromInt[from: words, showRadix: FALSE]]; msg ¬ Rope.Cat[msg, ", chars: ", Convert.RopeFromInt[from: characters, showRadix: FALSE]]; msg ¬ Rope.Concat[msg, IO.PutFR1[" (%g mode)", [rope[IF tokenMode THEN "token" ELSE "white-space"]]]]; MessageWindow.Append[message: msg, clearFirst: TRUE]; }; CreateWCButton: Commander.CommandProc ~ { [] ¬ Buttons.Create[ info: [name: "WC", parent: NIL], proc: WCButton, documentation: "Counts the lines, words, and chars in the current selection (or viewer)."]; }; Commander.Register[key: "WordCountButton", proc: CreateWCButton, doc: "Creates a WC (Word Count) button in the top button space."]; }. j WordCountButtonImpl.mesa Copyright Σ 1988, 1992 by Xerox Corporation. All rights reserved. Wes Irish, January 12, 1989 4:26:53 pm PST Jules Bloomenthal July 7, 1992 12:30 pm PDT Willie-s, November 13, 1991 10:47 am PST TYPEs... PROCs... PROC [parent: Viewer, clientData: REF ANY _ NIL, mouseButton: MouseButton _ red, shift, control: BOOL _ FALSE]; Κ•NewlineDelimiter –"cedarcode" style™šœ™Icodešœ Οeœ6™BKšœ*™*K™+K™(K™—šΟk ˜ KšœžœH˜g—K˜K™šΟnœžœž˜"Kšžœžœ8˜_Kšžœ˜K˜K˜K™K™Kšžœžœžœ˜K˜K™K˜šŸœžœžœ žœžœžœžœ ˜eK˜`K˜K˜—šŸΠanœ˜ Kš žœžœžœžœ3žœžœ™pKšœ žœžœ˜/Kšœ žœ ˜Kšœžœžœ˜Kšœžœ˜"šœžœ žœ˜IKšžœžœC˜b—Kš œžœžœ žœ žœ ˜MKšœKžœ˜SKšœMžœ˜UKšœRžœ˜ZKš œžœžœ žœ žœ˜gKšœ/žœ˜5K˜—K˜šŸœ˜)˜Kšœžœ˜ K˜Kšœ[˜[—K˜—K˜Kšœƒ˜ƒK˜—Kšœ˜K˜K˜K˜—…—Ž