summaryrefslogtreecommitdiff
path: root/src/adapad.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-10-04 21:34:08 +1100
committerJed Barber <jjbarber@y7mail.com>2016-10-04 21:34:08 +1100
commit3b643fb37910c216d921e742ae30471606093ed9 (patch)
treeeecb814e11d0223ca51939f7a1dea85e2882d1ae /src/adapad.adb
parent1f9e7a15d9414b1a96691111069523a70e107f16 (diff)
Basic replace functionality added
Diffstat (limited to 'src/adapad.adb')
-rw-r--r--src/adapad.adb35
1 files changed, 28 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;