From 770a95e888849f0756c98079a90164b832b1825f Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 14 Nov 2016 14:43:10 +1100 Subject: Edit and search menu items now grey themselves out when appropriate --- src/adapad.adb | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/adapad.adb') diff --git a/src/adapad.adb b/src/adapad.adb index dd5afd5..78b0684 100644 --- a/src/adapad.adb +++ b/src/adapad.adb @@ -11,9 +11,6 @@ with Windows.Replace; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; -with Ada.Text_IO; - - package body Adapad is @@ -306,11 +303,29 @@ package body Adapad is Deleted_Text : in String) is use type FLTK.Text_Buffers.Modification; + Bar : FLTK.Widgets.Menus.Menu_Cursor := Editor.Get_Menu_Bar; + Pop : FLTK.Widgets.Menus.Menu_Cursor := Editor.Get_Rightclick_Menu; begin if Action = FLTK.Text_Buffers.Insert or Action = FLTK.Text_Buffers.Delete then Changed := True; + Set_Title; + end if; + + if Buffer.Has_Selection then + Bar.Find_Item ("&Edit/Cu&t").Activate; + Bar.Find_Item ("&Edit/&Copy").Activate; + Bar.Find_Item ("&Edit/&Delete").Activate; + Pop.Find_Item ("Cu&t").Activate; + Pop.Find_Item ("&Copy").Activate; + Pop.Find_Item ("&Delete").Activate; + else + Bar.Find_Item ("&Edit/Cu&t").Deactivate; + Bar.Find_Item ("&Edit/&Copy").Deactivate; + Bar.Find_Item ("&Edit/&Delete").Deactivate; + Pop.Find_Item ("Cu&t").Deactivate; + Pop.Find_Item ("&Copy").Deactivate; + Pop.Find_Item ("&Delete").Deactivate; end if; - Set_Title; end Mod_CB; @@ -324,6 +339,7 @@ package body Adapad is Facing : in Windows.Find.Direction) is use type Windows.Find.Direction; + Bar : FLTK.Widgets.Menus.Menu_Cursor := Editor.Get_Menu_Bar; Current_Position, Select_Start, Select_End, Found_At : Natural; Was_Found : Boolean; begin @@ -352,12 +368,16 @@ package body Adapad is or else Buffer.Search_Backward (Buffer.Length, Item, Found_At, Match_Case); end if; - if Was_Found then + if Item /= "" and Was_Found then Buffer.Set_Selection (Found_At, Found_At + Item'Length); Editor.Set_Insert_Position (Found_At + Item'Length); Editor.Show_Insert_Position; + Bar.Find_Item ("&Search/Find &Next").Activate; + Bar.Find_Item ("&Search/Find &Previous").Activate; else FLTK.Dialogs.Alert ("No occurrences of '" & Item & "' found!"); + Bar.Find_Item ("&Search/Find &Next").Deactivate; + Bar.Find_Item ("&Search/Find &Previous").Deactivate; end if; end Do_Find_CB; @@ -514,6 +534,7 @@ package body Adapad is begin + -- definitely need to work out a better tabular structure for this code block declare use FLTK.Widgets.Menus; Bar : Menu_Cursor := Editor.Get_Menu_Bar; @@ -527,16 +548,16 @@ begin Bar.Add (Text => "&Edit", Flags => Flag_Submenu); Bar.Add ("Edit/&Undo", Undo_CB'Access, Mod_Ctrl + 'z', Flag_Divider); - Bar.Add ("Edit/Cu&t", Cut_CB'Access, Mod_Ctrl + 'x'); - Bar.Add ("Edit/&Copy", Copy_CB'Access, Mod_Ctrl + 'c'); + Bar.Add ("Edit/Cu&t", Cut_CB'Access, Mod_Ctrl + 'x', Flag_Inactive); + Bar.Add ("Edit/&Copy", Copy_CB'Access, Mod_Ctrl + 'c', Flag_Inactive); Bar.Add ("Edit/&Paste", Paste_CB'Access, Mod_Ctrl + 'v'); - Bar.Add ("Edit/&Delete", Delete_CB'Access, No_Key, Flag_Divider); + Bar.Add ("Edit/&Delete", Delete_CB'Access, No_Key, Flag_Inactive + Flag_Divider); Bar.Add ("Edit/Select &All", Select_All_CB'Access, Mod_Ctrl + 'a'); 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/Find &Next", Find_Next_CB'Access, Mod_Ctrl + 'g', Flag_Inactive); + Bar.Add ("Search/Find &Previous", Find_Prev_CB'Access, Mod_Shift + Mod_Ctrl + 'g', Flag_Inactive); 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); @@ -554,10 +575,10 @@ begin use FLTK.Widgets.Menus; Pop : Menu_Cursor := Editor.Get_Rightclick_Menu; begin - Pop.Add ("Cu&t", Cut_CB'Access); - Pop.Add ("&Copy", Copy_CB'Access); + Pop.Add ("Cu&t", Cut_CB'Access, No_Key, Flag_Inactive); + Pop.Add ("&Copy", Copy_CB'Access, No_Key, Flag_Inactive); Pop.Add ("&Paste", Paste_CB'Access); - Pop.Add ("&Delete", Delete_CB'Access, No_Key, Flag_Divider); + Pop.Add ("&Delete", Delete_CB'Access, No_Key, Flag_Inactive + Flag_Divider); Pop.Add ("Select &All", Select_All_CB'Access); end; -- cgit