From 8908535c7dc9fc7adf3c56b96aecc49b319c5a9e Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 12 Nov 2016 17:20:15 +1100 Subject: Added basic word count feature --- src/adapad.adb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/adapad.adb') diff --git a/src/adapad.adb b/src/adapad.adb index 3a0ce97..5f8e7d8 100644 --- a/src/adapad.adb +++ b/src/adapad.adb @@ -197,6 +197,27 @@ package body Adapad is + procedure Count_CB + (Item : in out FLTK.Widgets.Widget'Class) + is + Restore_Position : Natural := Editor.Get_Insert_Position; + Current_Position, New_Position, Result : Natural := 0; + begin + Editor.Set_Insert_Position (0); + loop + Editor.Next_Word; + New_Position := Editor.Get_Insert_Position; + exit when New_Position = Buffer.Length; + Current_Position := New_Position; + Result := Result + 1; + end loop; + Editor.Set_Insert_Position (Restore_Position); + FLTK.Dialogs.Message_Box ("There are " & Integer'Image (Result) & " words in the document."); + end Count_CB; + + + + procedure About_CB (Item : in out FLTK.Widgets.Widget'Class) is begin @@ -419,7 +440,8 @@ begin Bar.Add (Text => "&Search", Flags => Flag_Submenu); Bar.Add ("Search/&Find...", Find_CB'Access, Mod_Ctrl + 'f'); - Bar.Add ("Search/&Replace...", Replace_CB'Access, Mod_Ctrl + 'h'); + Bar.Add ("Search/&Replace...", Replace_CB'Access, Mod_Ctrl + 'h', Flag_Divider); + Bar.Add ("Search/&Word Count", Count_CB'Access); Bar.Add (Text => "&Help", Flags => Flag_Submenu); Bar.Add ("Help/&About", About_CB'Access); -- cgit