diff options
-rw-r--r-- | src/adapad.adb | 35 | ||||
-rw-r--r-- | src/fltk_binding/c_fl_text_buffer.cpp | 5 | ||||
-rw-r--r-- | src/fltk_binding/c_fl_text_buffer.h | 1 | ||||
-rw-r--r-- | src/fltk_binding/fltk-text_buffers.adb | 20 | ||||
-rw-r--r-- | src/fltk_binding/fltk-text_buffers.ads | 6 |
5 files changed, 60 insertions, 7 deletions
diff --git a/src/adapad.adb b/src/adapad.adb index bea6b91..8f1196b 100644 --- a/src/adapad.adb +++ b/src/adapad.adb @@ -283,8 +283,7 @@ function Adapad return Integer is Item : in String; Match_Case : in Boolean) is - Current_Position : Natural; - Found_At : Natural; + Current_Position, Found_At : Natural; begin Find.Hide; @@ -308,13 +307,33 @@ function Adapad return Integer is (This : in Do_Replace_Callback; Item, Replace_With : in String; Match_Case, Replace_All : in Boolean) is + + Current_Position, Found_At : Natural; + Times_Replaced : Natural := 0; + begin - Ada.Text_IO.Put_Line ("Replacing " & Item & " with " & Replace_With); - if Match_Case then - Ada.Text_IO.Put_Line ("Matching case"); - end if; + Replace.Hide; + if Replace_All then - Ada.Text_IO.Put_Line ("Replacing all"); + Editor.Set_Insert_Position (0); + end if; + + loop + Current_Position := Editor.Get_Insert_Position; + exit when not Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case); + Buffer.Set_Selection (Found_At, Found_At + Item'Length); + Buffer.Remove_Selected_Text; + Buffer.Insert_Text (Found_At, Replace_With); + Editor.Set_Insert_Position (Found_At + Replace_With'Length); + Editor.Show_Insert_Position; + Times_Replaced := Times_Replaced + 1; + exit when not Replace_All and Times_Replaced > 0; + end loop; + + if Times_Replaced > 0 then + Message_Box ("Replaced " & Integer'Image (Times_Replaced) & " occurrences."); + else + Alert ("No occurrences of '" & Item & "' found!"); end if; end Call; @@ -458,6 +477,8 @@ begin Replace.Set_Replace_Callback (Do_Replace_CB'Access); Buffer.Add_Modify_Callback (Mod_CB'Access); Editor.Set_Callback (Quit_CB'Access); + + Editor.Set_Buffer (Buffer); Editor.Show; return FLTK.Run; diff --git a/src/fltk_binding/c_fl_text_buffer.cpp b/src/fltk_binding/c_fl_text_buffer.cpp index b0df365..8b0cde1 100644 --- a/src/fltk_binding/c_fl_text_buffer.cpp +++ b/src/fltk_binding/c_fl_text_buffer.cpp @@ -35,6 +35,11 @@ void fl_text_buffer_call_predelete_callbacks(TEXTBUFFER tb) { } +void fl_text_buffer_insert(TEXTBUFFER tb, int p, const char * item) { + reinterpret_cast<Fl_Text_Buffer*>(tb)->insert(p, item); +} + + int fl_text_buffer_length(TEXTBUFFER tb) { return reinterpret_cast<Fl_Text_Buffer*>(tb)->length(); } diff --git a/src/fltk_binding/c_fl_text_buffer.h b/src/fltk_binding/c_fl_text_buffer.h index cd64112..5a1ab08 100644 --- a/src/fltk_binding/c_fl_text_buffer.h +++ b/src/fltk_binding/c_fl_text_buffer.h @@ -15,6 +15,7 @@ extern "C" void fl_text_buffer_add_modify_callback(TEXTBUFFER tb, void * cb, voi extern "C" void fl_text_buffer_add_predelete_callback(TEXTBUFFER tb, void * cb, void * ud); extern "C" void fl_text_buffer_call_modify_callbacks(TEXTBUFFER tb); extern "C" void fl_text_buffer_call_predelete_callbacks(TEXTBUFFER tb); +extern "C" void fl_text_buffer_insert(TEXTBUFFER tb, int p, const char * item); extern "C" int fl_text_buffer_length(TEXTBUFFER tb); extern "C" int fl_text_buffer_loadfile(TEXTBUFFER tb, char * n); extern "C" void fl_text_buffer_remove_selection(TEXTBUFFER tb); diff --git a/src/fltk_binding/fltk-text_buffers.adb b/src/fltk_binding/fltk-text_buffers.adb index 6df96cb..b3b8344 100644 --- a/src/fltk_binding/fltk-text_buffers.adb +++ b/src/fltk_binding/fltk-text_buffers.adb @@ -46,6 +46,12 @@ package body FLTK.Text_Buffers is pragma Import (C, fl_text_buffer_call_predelete_callbacks, "fl_text_buffer_call_predelete_callbacks"); + procedure fl_text_buffer_insert + (TB : in System.Address; + P : in Interfaces.C.int; + I : in Interfaces.C.char_array); + pragma Import (C, fl_text_buffer_insert, "fl_text_buffer_insert"); + function fl_text_buffer_length (TB : in System.Address) return Interfaces.C.int; @@ -237,6 +243,20 @@ package body FLTK.Text_Buffers is + procedure Insert_Text + (This : in out Text_Buffer; + Pos : in Natural; + Item : in String) is + begin + fl_text_buffer_insert + (This.Void_Ptr, + Interfaces.C.int (Pos), + Interfaces.C.To_C (Item)); + end Insert_Text; + + + + function Length (This : in Text_Buffer) return Natural is diff --git a/src/fltk_binding/fltk-text_buffers.ads b/src/fltk_binding/fltk-text_buffers.ads index 0bb881e..a560076 100644 --- a/src/fltk_binding/fltk-text_buffers.ads +++ b/src/fltk_binding/fltk-text_buffers.ads @@ -56,6 +56,12 @@ package FLTK.Text_Buffers is (This : in out Text_Buffer); + procedure Insert_Text + (This : in out Text_Buffer; + Pos : in Natural; + Item : in String); + + function Length (This : in Text_Buffer) return Natural; |