summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2016-11-14 17:38:44 +1100
committerJed Barber <jjbarber@y7mail.com>2016-11-14 17:38:44 +1100
commitb787152c2603f8d51b1626f163d234b343dbeb6f (patch)
tree58b3664f2c8f5df1ed57123f718e4bcaed2984c4
parent770a95e888849f0756c98079a90164b832b1825f (diff)
Improved replace
-rw-r--r--src/adapad.adb35
-rw-r--r--to_do.txt2
2 files changed, 22 insertions, 15 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 78b0684..fb34196 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -388,25 +388,32 @@ package body Adapad is
(Item, Replace_With : in String;
Match_Case, Replace_All : in Boolean)
is
- Current_Position, Found_At : Natural;
- Times_Replaced : Natural := 0;
+ use type FLTK.Dialogs.Choice;
+ User_Response : FLTK.Dialogs.Choice;
+ Found_At : Natural;
+ Current_Position, Times_Replaced : Natural := 0;
begin
Replace.Hide;
- if Replace_All then
- 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);
+ while Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case) loop
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.Set_Insert_Position (Found_At);
Editor.Show_Insert_Position;
- Times_Replaced := Times_Replaced + 1;
- exit when not Replace_All and Times_Replaced > 0;
+ if not Replace_All then
+ User_Response := FLTK.Dialogs.Three_Way_Choice
+ ("Replace?", "No", "Yes", "Cancel");
+ else
+ User_Response := FLTK.Dialogs.Second;
+ end if;
+ exit when User_Response = FLTK.Dialogs.Third;
+ if User_Response = FLTK.Dialogs.Second then
+ Buffer.Remove_Selected_Text;
+ Buffer.Insert_Text (Found_At, Replace_With);
+ Current_Position := Found_At + Replace_With'Length;
+ Times_Replaced := Times_Replaced + 1;
+ else
+ Current_Position := Found_At + Item'Length;
+ end if;
end loop;
if Times_Replaced > 0 then
diff --git a/to_do.txt b/to_do.txt
index e9934f4..9c8f205 100644
--- a/to_do.txt
+++ b/to_do.txt
@@ -3,7 +3,7 @@
To Do:
- change build to be dynamically linked
-- improve replace, undo/redo, jump to
+- improve undo/redo, jump to
- suppress unnecessary left/right scrollbar
- clean up menu widget code, adapad menu and callback code
- introduce maybe type to eliminate out parameters in search_forward/search_backward