diff options
Diffstat (limited to 'src/adapad.adb')
-rw-r--r-- | src/adapad.adb | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/adapad.adb b/src/adapad.adb index e72d4d6..e197097 100644 --- a/src/adapad.adb +++ b/src/adapad.adb @@ -11,6 +11,9 @@ with Windows.Replace; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Ada.Text_IO; + + package body Adapad is @@ -187,6 +190,24 @@ package body Adapad is + procedure Find_Next_CB + (Item : in out FLTK.Widgets.Widget'Class) is + begin + Find.Do_Callback (Windows.Find.Forward); + end Find_Next_CB; + + + + + procedure Find_Prev_CB + (Item : in out FLTK.Widgets.Widget'Class) is + begin + Find.Do_Callback (Windows.Find.Backward); + end Find_Prev_CB; + + + + procedure Replace_CB (Item : in out FLTK.Widgets.Widget'Class) is begin @@ -295,17 +316,43 @@ package body Adapad is - -- callbacks for the find/replace windows + -- callbacks for the extra dialog windows procedure Do_Find_CB (Item : in String; - Match_Case : in Boolean) + Match_Case : in Boolean; + Facing : in Windows.Find.Direction) is - Current_Position, Found_At : Natural; + use type Windows.Find.Direction; + Current_Position, Select_Start, Select_End, Found_At : Natural; + Was_Found : Boolean; begin Find.Hide; - Current_Position := Editor.Get_Insert_Position; - if Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case) then + + -- is it possible to improve this abomination with a modulo type? + if Buffer.Get_Selection (Select_Start, Select_End) then + if Facing = Windows.Find.Forward then + Current_Position := Select_End; + else + if Select_Start = 0 then + Current_Position := Buffer.Length; + else + Current_Position := Select_Start - 1; + end if; + end if; + else + Current_Position := Editor.Get_Insert_Position; + end if; + + if Facing = Windows.Find.Forward then + Was_Found := Buffer.Search_Forward (Current_Position, Item, Found_At, Match_Case) + or else Buffer.Search_Forward (0, Item, Found_At, Match_Case); + else + Was_Found := Buffer.Search_Backward (Current_Position, Item, Found_At, Match_Case) + or else Buffer.Search_Backward (Buffer.Length, Item, Found_At, Match_Case); + end if; + + if Was_Found then Buffer.Set_Selection (Found_At, Found_At + Item'Length); Editor.Set_Insert_Position (Found_At + Item'Length); Editor.Show_Insert_Position; @@ -488,6 +535,8 @@ begin Bar.Add (Text => "&Search", Flags => Flag_Submenu); Bar.Add ("Search/&Find...", Find_CB'Access, Mod_Ctrl + 'f'); + Bar.Add ("Search/Find &Next", Find_Next_CB'Access, Mod_Ctrl + 'g'); + Bar.Add ("Search/Find &Previous", Find_Prev_CB'Access, Mod_Shift + Mod_Ctrl + 'g'); Bar.Add ("Search/&Replace...", Replace_CB'Access, Mod_Ctrl + 'h', Flag_Divider); Bar.Add ("Search/Jump To...", Jump_CB'Access, Mod_Ctrl + 'j'); Bar.Add ("Search/Word Count", Count_CB'Access); |