summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-11-12 17:20:15 +1100
committerJed Barber <jjbarber@y7mail.com>2016-11-12 17:20:15 +1100
commit8908535c7dc9fc7adf3c56b96aecc49b319c5a9e (patch)
treec7dc949471370aa28924cfb8ca227d933e9e8702
parent7aa86670f5d76284ae193ed1e1ed936b20a5c5fb (diff)
Added basic word count feature
-rw-r--r--src/adapad.adb24
-rw-r--r--src/fltk_binding/c_fl_text_display.cpp10
-rw-r--r--src/fltk_binding/c_fl_text_display.h2
-rw-r--r--src/fltk_binding/fltk-widgets-groups-text_displays.adb26
-rw-r--r--src/fltk_binding/fltk-widgets-groups-text_displays.ads8
-rw-r--r--src/windows-editor.adb18
-rw-r--r--src/windows-editor.ads8
-rw-r--r--to_do.txt4
8 files changed, 97 insertions, 3 deletions
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);
diff --git a/src/fltk_binding/c_fl_text_display.cpp b/src/fltk_binding/c_fl_text_display.cpp
index 94eb002..5104869 100644
--- a/src/fltk_binding/c_fl_text_display.cpp
+++ b/src/fltk_binding/c_fl_text_display.cpp
@@ -73,3 +73,13 @@ void fl_text_display_show_insert_pos(TEXTDISPLAY td) {
reinterpret_cast<Fl_Text_Display*>(td)->show_insert_position();
}
+
+void fl_text_display_next_word(TEXTDISPLAY td) {
+ reinterpret_cast<Fl_Text_Display*>(td)->next_word();
+}
+
+
+void fl_text_display_previous_word(TEXTDISPLAY td) {
+ reinterpret_cast<Fl_Text_Display*>(td)->previous_word();
+}
+
diff --git a/src/fltk_binding/c_fl_text_display.h b/src/fltk_binding/c_fl_text_display.h
index 5a91774..f42ada9 100644
--- a/src/fltk_binding/c_fl_text_display.h
+++ b/src/fltk_binding/c_fl_text_display.h
@@ -23,6 +23,8 @@ extern "C" void fl_text_display_set_text_size(TEXTDISPLAY td, int s);
extern "C" int fl_text_display_get_insert_pos(TEXTDISPLAY td);
extern "C" void fl_text_display_set_insert_pos(TEXTDISPLAY td, int p);
extern "C" void fl_text_display_show_insert_pos(TEXTDISPLAY td);
+extern "C" void fl_text_display_next_word(TEXTDISPLAY td);
+extern "C" void fl_text_display_previous_word(TEXTDISPLAY td);
#endif
diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays.adb b/src/fltk_binding/fltk-widgets-groups-text_displays.adb
index e2d62d8..f8418d6 100644
--- a/src/fltk_binding/fltk-widgets-groups-text_displays.adb
+++ b/src/fltk_binding/fltk-widgets-groups-text_displays.adb
@@ -72,6 +72,14 @@ package body FLTK.Widgets.Groups.Text_Displays is
(TD : in System.Address);
pragma Import (C, fl_text_display_show_insert_pos, "fl_text_display_show_insert_pos");
+ procedure fl_text_display_next_word
+ (TD : in System.Address);
+ pragma Import (C, fl_text_display_next_word, "fl_text_display_next_word");
+
+ procedure fl_text_display_previous_word
+ (TD : in System.Address);
+ pragma Import (C, fl_text_display_previous_word, "fl_text_display_previous_word");
+
@@ -219,5 +227,23 @@ package body FLTK.Widgets.Groups.Text_Displays is
end Show_Insert_Position;
+
+
+ procedure Next_Word
+ (This : in out Text_Display) is
+ begin
+ fl_text_display_next_word (This.Void_Ptr);
+ end Next_Word;
+
+
+
+
+ procedure Previous_Word
+ (This : in out Text_Display) is
+ begin
+ fl_text_display_previous_word (This.Void_Ptr);
+ end Previous_Word;
+
+
end FLTK.Widgets.Groups.Text_Displays;
diff --git a/src/fltk_binding/fltk-widgets-groups-text_displays.ads b/src/fltk_binding/fltk-widgets-groups-text_displays.ads
index 6c2a9fe..3eea299 100644
--- a/src/fltk_binding/fltk-widgets-groups-text_displays.ads
+++ b/src/fltk_binding/fltk-widgets-groups-text_displays.ads
@@ -70,6 +70,14 @@ package FLTK.Widgets.Groups.Text_Displays is
(This : in out Text_Display);
+ procedure Next_Word
+ (This : in out Text_Display);
+
+
+ procedure Previous_Word
+ (This : in out Text_Display);
+
+
private
diff --git a/src/windows-editor.adb b/src/windows-editor.adb
index e961d4a..bbaa069 100644
--- a/src/windows-editor.adb
+++ b/src/windows-editor.adb
@@ -167,5 +167,23 @@ package body Windows.Editor is
end Show_Insert_Position;
+
+
+ procedure Next_Word
+ (This : in out Editor_Window) is
+ begin
+ This.Editor.Next_Word;
+ end Next_Word;
+
+
+
+
+ procedure Previous_Word
+ (This : in out Editor_Window) is
+ begin
+ This.Editor.Previous_Word;
+ end Previous_Word;
+
+
end Windows.Editor;
diff --git a/src/windows-editor.ads b/src/windows-editor.ads
index a1afdad..46e0fe6 100644
--- a/src/windows-editor.ads
+++ b/src/windows-editor.ads
@@ -77,6 +77,14 @@ package Windows.Editor is
(This : in out Editor_Window);
+ procedure Next_Word
+ (This : in out Editor_Window);
+
+
+ procedure Previous_Word
+ (This : in out Editor_Window);
+
+
private
diff --git a/to_do.txt b/to_do.txt
index af2080c..402f395 100644
--- a/to_do.txt
+++ b/to_do.txt
@@ -3,8 +3,8 @@
To Do:
- change build to be dynamically linked
-- improve find, replace, undo/redo
-- add word count feature
+- improve find, replace, undo/redo, word count
+- add jump to, line numbers, word wrap
- suppress unnecessary left/right scrollbar
- make logo colours lighter to stand out more
- separate fltk binding into its own repo