aboutsummaryrefslogtreecommitdiff
path: root/src/adapad.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/adapad.adb')
-rw-r--r--src/adapad.adb158
1 files changed, 53 insertions, 105 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 5f1f347..8d0e4ac 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -2,17 +2,17 @@
with
- FLTK.Widgets.Menus,
- FLTK.Widgets.Groups.Windows,
- FLTK.Text_Buffers,
+ Ada.Strings.Unbounded,
+ Change_Vectors,
FLTK.Asks,
- Windows.Editor,
+ FLTK.Text_Buffers,
+ FLTK.Widgets.Groups.Windows,
+ FLTK.Widgets.Menus,
Windows.About,
+ Windows.Editor,
Windows.Find,
- Windows.Replace,
Windows.Jump,
- Change_Vectors,
- Ada.Strings.Unbounded;
+ Windows.Replace;
use
@@ -59,8 +59,6 @@ package body Adapad is
end Show;
-
-
procedure Hide is
begin
About.Hide;
@@ -78,7 +76,9 @@ package body Adapad is
procedure New_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
- if not Safe_To_Discard then return; end if;
+ if not Safe_To_Discard then
+ return;
+ end if;
Filename := To_Unbounded_String (0);
Buffer.Remove_Text (0, Buffer.Length);
Changed := False;
@@ -86,14 +86,14 @@ package body Adapad is
end New_CB;
-
-
procedure Open_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
- if not Safe_To_Discard then return; end if;
+ if not Safe_To_Discard then
+ return;
+ end if;
declare
- New_Filename : String :=
+ New_Filename : constant String :=
FLTK.Asks.File_Chooser ("Open File?", "*", To_String (Filename));
begin
if New_Filename /= "" then
@@ -103,8 +103,6 @@ package body Adapad is
end Open_CB;
-
-
procedure Save_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -112,8 +110,6 @@ package body Adapad is
end Save_CB;
-
-
procedure Save_As_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -121,23 +117,21 @@ package body Adapad is
end Save_As_CB;
-
-
procedure Quit_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
- if not Safe_To_Discard then return; end if;
+ if not Safe_To_Discard then
+ return;
+ end if;
Hide;
end Quit_CB;
-
-
procedure Undo_CB
(Item : in out FLTK.Widgets.Widget'Class)
is
use type FLTK.Text_Buffers.Modification;
- Bar : FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
+ Bar : constant FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
Ch : Change_Vectors.Change;
begin
Buffer.Disable_Callbacks;
@@ -164,13 +158,11 @@ package body Adapad is
end Undo_CB;
-
-
procedure Redo_CB
(Item : in out FLTK.Widgets.Widget'Class)
is
use type FLTK.Text_Buffers.Modification;
- Bar : FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
+ Bar : constant FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
Ch : Change_Vectors.Change;
begin
Buffer.Disable_Callbacks;
@@ -197,8 +189,6 @@ package body Adapad is
end Redo_CB;
-
-
procedure Cut_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -206,8 +196,6 @@ package body Adapad is
end Cut_CB;
-
-
procedure Copy_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -215,8 +203,6 @@ package body Adapad is
end Copy_CB;
-
-
procedure Paste_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -224,8 +210,6 @@ package body Adapad is
end Paste_CB;
-
-
procedure Delete_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -233,8 +217,6 @@ package body Adapad is
end Delete_CB;
-
-
procedure Select_All_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -242,8 +224,6 @@ package body Adapad is
end Select_All_CB;
-
-
procedure Find_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -252,8 +232,6 @@ package body Adapad is
end Find_CB;
-
-
procedure Find_Next_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -261,8 +239,6 @@ package body Adapad is
end Find_Next_CB;
-
-
procedure Find_Prev_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -270,8 +246,6 @@ package body Adapad is
end Find_Prev_CB;
-
-
procedure Replace_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -280,8 +254,6 @@ package body Adapad is
end Replace_CB;
-
-
procedure Jump_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -290,12 +262,10 @@ package body Adapad is
end Jump_CB;
-
-
procedure Count_CB
(Item : in out FLTK.Widgets.Widget'Class)
is
- Restore_Position : Natural := Editor.Get_Insert_Position;
+ Restore_Position : constant Natural := Editor.Get_Insert_Position;
Current_Position, Result : Natural := 0;
begin
Editor.Set_Insert_Position (0);
@@ -309,13 +279,10 @@ package body Adapad is
Result := Result + 1;
end loop;
Editor.Set_Insert_Position (Restore_Position);
- FLTK.Asks.Message_Box
- ("There are " & Integer'Image (Result) & " words in the document.");
+ FLTK.Asks.Message_Box ("There are " & Integer'Image (Result) & " words in the document.");
end Count_CB;
-
-
procedure Wrap_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -327,8 +294,6 @@ package body Adapad is
end Wrap_CB;
-
-
procedure Lines_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -341,8 +306,6 @@ package body Adapad is
end Lines_CB;
-
-
procedure About_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -362,8 +325,8 @@ package body Adapad is
Deleted_Text : in String)
is
use type FLTK.Text_Buffers.Modification;
- Bar : FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
- Pop : FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Rightclick_Menu;
+ Bar : constant FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
+ Pop : constant FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Rightclick_Menu;
begin
if Action = FLTK.Text_Buffers.Insert or Action = FLTK.Text_Buffers.Delete then
Changed := True;
@@ -376,7 +339,7 @@ package body Adapad is
Ch.Length := Length;
if Action = FLTK.Text_Buffers.Insert then
Ch.Text := To_Unbounded_String
- (Buffer.Text_At (Integer (Place), Integer (Place) + Length));
+ (Buffer.Text_At (Integer (Place), Integer (Place) + Length));
else
Ch.Text := To_Unbounded_String (Deleted_Text);
end if;
@@ -416,7 +379,7 @@ package body Adapad is
Facing : in Windows.Find.Direction)
is
use type Windows.Find.Direction;
- Bar : FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
+ Bar : constant FLTK.Widgets.Menus.Menu_Reference := Editor.Get_Menu_Bar;
Current_Position, Select_Start, Select_End, Found_At : Natural;
Was_Found : Boolean;
begin
@@ -459,8 +422,6 @@ package body Adapad is
end Do_Find_CB;
-
-
procedure Do_Replace_CB
(Item, Replace_With : in String;
Match_Case, Replace_All : in Boolean)
@@ -477,8 +438,7 @@ package body Adapad is
Editor.Set_Insert_Position (Found_At);
Editor.Show_Insert_Position;
if not Replace_All then
- User_Response := FLTK.Asks.Choice
- ("Replace?", "No", "Yes", "Cancel");
+ User_Response := FLTK.Asks.Choice ("Replace?", "No", "Yes", "Cancel");
else
User_Response := FLTK.Asks.Second;
end if;
@@ -494,16 +454,13 @@ package body Adapad is
end loop;
if Times_Replaced > 0 then
- FLTK.Asks.Message_Box
- ("Replaced " & Integer'Image (Times_Replaced) & " occurrences.");
+ FLTK.Asks.Message_Box ("Replaced " & Integer'Image (Times_Replaced) & " occurrences.");
else
FLTK.Asks.Alert ("No occurrences of '" & Item & "' found!");
end if;
end Do_Replace_CB;
-
-
procedure Do_Jump_CB
(Line_Number : in Positive) is
begin
@@ -532,32 +489,30 @@ package body Adapad is
end Set_Title;
-
-
function Safe_To_Discard
return Boolean
is
User_Response : FLTK.Asks.Choice_Result;
begin
- if not Changed then return True; end if;
+ if not Changed then
+ return True;
+ end if;
User_Response := FLTK.Asks.Choice
- ("The current file has not been saved." & Character'Val (10) &
- "Would you like to save it now?",
- "Cancel", "Save", "Discard");
+ ("The current file has not been saved." & Character'Val (10) &
+ "Would you like to save it now?",
+ "Cancel", "Save", "Discard");
case User_Response is
- when FLTK.Asks.First =>
- return False;
- when FLTK.Asks.Second =>
- Do_Save;
- return not Changed;
- when FLTK.Asks.Third =>
- return True;
+ when FLTK.Asks.First =>
+ return False;
+ when FLTK.Asks.Second =>
+ Do_Save;
+ return not Changed;
+ when FLTK.Asks.Third =>
+ return True;
end case;
end Safe_To_Discard;
-
-
procedure Do_Save is
begin
if Filename = "" then
@@ -568,11 +523,9 @@ package body Adapad is
end Do_Save;
-
-
procedure Do_Save_As is
- New_Filename : String := FLTK.Asks.File_Chooser
- ("Save File As?", "*", To_String (Filename));
+ New_Filename : constant String := FLTK.Asks.File_Chooser
+ ("Save File As?", "*", To_String (Filename));
begin
if New_Filename /= "" then
Save_File (New_Filename);
@@ -580,8 +533,6 @@ package body Adapad is
end Do_Save_As;
-
-
procedure Load_File
(Name : in String) is
begin
@@ -593,13 +544,11 @@ package body Adapad is
Editor.Get_Menu_Bar.Find_Item ("&Edit/&Undo").Deactivate;
Editor.Get_Menu_Bar.Find_Item ("&Edit/&Redo").Deactivate;
exception
- when Storage_Error =>
- FLTK.Asks.Alert ("Error reading from file " & Name);
+ when Storage_Error =>
+ FLTK.Asks.Alert ("Error reading from file " & Name);
end Load_File;
-
-
procedure Save_File
(Name : in String) is
begin
@@ -608,22 +557,20 @@ package body Adapad is
Changed := False;
Set_Title;
exception
- when Storage_Error =>
- FLTK.Asks.Alert ("Error writing to file " & Name);
+ when Storage_Error =>
+ FLTK.Asks.Alert ("Error writing to file " & Name);
end Save_File;
-
-
procedure Centre
(Win : in out FLTK.Widgets.Groups.Windows.Window'Class)
is
- Middle_X : Integer := Editor.Get_X + Editor.Get_W / 2;
- Middle_Y : Integer := Editor.Get_Y + Editor.Get_H / 2;
+ Middle_X : constant Integer := Editor.Get_X + Editor.Get_W / 2;
+ Middle_Y : constant Integer := Editor.Get_Y + Editor.Get_H / 2;
begin
Win.Reposition
- (Middle_X - Win.Get_W / 2,
- Middle_Y - Win.Get_H / 2);
+ (Middle_X - Win.Get_W / 2,
+ Middle_Y - Win.Get_H / 2);
end Centre;
@@ -635,7 +582,7 @@ begin
declare
use FLTK;
use FLTK.Widgets.Menus;
- Bar : Menu_Reference := Editor.Get_Menu_Bar;
+ Bar : constant Menu_Reference := Editor.Get_Menu_Bar;
begin
Bar.Add (Text => "&File", Flags => Flag_Submenu);
Bar.Add ("File/&New", New_CB'Access, Mod_Ctrl + 'n');
@@ -675,7 +622,7 @@ begin
declare
use FLTK;
use FLTK.Widgets.Menus;
- Pop : Menu_Reference := Editor.Get_Rightclick_Menu;
+ Pop : constant Menu_Reference := Editor.Get_Rightclick_Menu;
begin
Pop.Add ("Cu&t", Cut_CB'Access, No_Key, Flag_Inactive);
Pop.Add ("&Copy", Copy_CB'Access, No_Key, Flag_Inactive);
@@ -697,3 +644,4 @@ begin
end Adapad;
+