summaryrefslogtreecommitdiff
path: root/src/adapad.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/adapad.adb')
-rw-r--r--src/adapad.adb88
1 files changed, 83 insertions, 5 deletions
diff --git a/src/adapad.adb b/src/adapad.adb
index 82aa1ad..154e636 100644
--- a/src/adapad.adb
+++ b/src/adapad.adb
@@ -4,14 +4,19 @@ with FLTK.Widgets.Menus;
with FLTK.Widgets.Groups.Windows;
with FLTK.Text_Buffers;
with FLTK.Dialogs;
+with FLTK.Enums; use FLTK.Enums;
with Windows.Editor;
with Windows.About;
with Windows.Find;
with Windows.Replace;
with Windows.Jump;
+with Change_Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
+with Ada.Text_IO;
+
+
package body Adapad is
@@ -37,8 +42,9 @@ package body Adapad is
Replace : Windows.Replace.Replace_Window := Windows.Replace.Create;
Jump : Windows.Jump.Jump_Window := Windows.Jump.Create;
- Changed : Boolean := False;
- Filename : Unbounded_String := To_Unbounded_String (0);
+ Changed : Boolean := False;
+ Mod_List : Change_Vectors.Change_Vector := Change_Vectors.Empty_Vector;
+ Filename : Unbounded_String := To_Unbounded_String (0);
@@ -126,14 +132,67 @@ package body Adapad is
procedure Undo_CB
- (Item : in out FLTK.Widgets.Widget'Class) is
+ (Item : in out FLTK.Widgets.Widget'Class)
+ is
+ use type FLTK.Text_Buffers.Modification;
+ Bar : FLTK.Widgets.Menus.Menu_Cursor := Editor.Get_Menu_Bar;
+ Ch : Change_Vectors.Change;
begin
- Editor.Undo;
+ Buffer.Disable_Callbacks;
+
+ if Mod_List.Peek (Ch) then
+ if Ch.Action = FLTK.Text_Buffers.Insert then
+ Buffer.Remove_Text (Integer (Ch.Place), Integer (Ch.Place) + Ch.Length);
+ Editor.Set_Insert_Position (Integer (Ch.Place));
+ else
+ Buffer.Insert_Text (Integer (Ch.Place), To_String (Ch.Text));
+ Editor.Set_Insert_Position (Integer (Ch.Place) + Ch.Length);
+ end if;
+ Editor.Show_Insert_Position;
+ Mod_List.Pop;
+ Bar.Find_Item ("&Edit/&Redo").Activate;
+ if Mod_List.At_Start then
+ Bar.Find_Item ("&Edit/&Undo").Deactivate;
+ end if;
+ end if;
+
+ Buffer.Enable_Callbacks;
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_Cursor := Editor.Get_Menu_Bar;
+ Ch : Change_Vectors.Change;
+ begin
+ Buffer.Disable_Callbacks;
+
+ if Mod_List.Re_Push then
+ Mod_List.Peek (Ch);
+ if Ch.Action = FLTK.Text_Buffers.Insert then
+ Buffer.Insert_Text (Integer (Ch.Place), To_String (Ch.Text));
+ Editor.Set_Insert_Position (Integer (Ch.Place) + Ch.Length);
+ else
+ Buffer.Remove_Text (Integer (Ch.Place), Integer (Ch.Place) + Ch.Length);
+ Editor.Set_Insert_Position (Integer (Ch.Place));
+ end if;
+ Editor.Show_Insert_Position;
+ Bar.Find_Item ("&Edit/&Undo").Activate;
+ if Mod_List.At_End then
+ Bar.Find_Item ("&Edit/&Redo").Deactivate;
+ end if;
+ end if;
+
+ Buffer.Enable_Callbacks;
+ end Redo_CB;
+
+
+
+
procedure Cut_CB
(Item : in out FLTK.Widgets.Widget'Class) is
begin
@@ -302,6 +361,24 @@ package body Adapad is
if Action = FLTK.Text_Buffers.Insert or Action = FLTK.Text_Buffers.Delete then
Changed := True;
Set_Title;
+ declare
+ Ch : Change_Vectors.Change;
+ begin
+ Ch.Action := Action;
+ Ch.Place := Place;
+ Ch.Length := Length;
+ if Action = FLTK.Text_Buffers.Insert then
+ Ch.Text := To_Unbounded_String
+ (Buffer.Text_At (Integer (Place), Integer (Place) + Length));
+ else
+ Ch.Text := To_Unbounded_String (Deleted_Text);
+ end if;
+ Mod_List.Push (Ch);
+ Bar.Find_Item ("&Edit/&Undo").Activate;
+ if Mod_List.At_End then
+ Bar.Find_Item ("&Edit/&Redo").Deactivate;
+ end if;
+ end;
end if;
if Buffer.Has_Selection then
@@ -558,7 +635,8 @@ begin
Bar.Add ("File/&Quit", Quit_CB'Access, Mod_Ctrl + 'q');
Bar.Add (Text => "&Edit", Flags => Flag_Submenu);
- Bar.Add ("Edit/&Undo", Undo_CB'Access, Mod_Ctrl + 'z', Flag_Divider);
+ Bar.Add ("Edit/&Undo", Undo_CB'Access, Mod_Ctrl + 'z', Flag_Inactive);
+ Bar.Add ("Edit/&Redo", Redo_CB'Access, Mod_Shift + Mod_Ctrl + 'z', Flag_Inactive + Flag_Divider);
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');