-
Notifications
You must be signed in to change notification settings - Fork 5
/
lea_gwin-repair.adb
127 lines (115 loc) · 4.31 KB
/
lea_gwin-repair.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
with LEA_Common.User_options;
with LEA_GWin.MDI_Child;
with HAC_Sys.Errors;
with HAT;
with GWindows.Base,
GWindows.Scintilla;
with Ada.Strings.Unbounded,
Ada.Strings.Wide_Unbounded;
package body LEA_GWin.Repair is
Options : LEA_Common.User_options.Option_Pack_Type renames LEA_Common.User_options.Options;
procedure Do_Repair (
MDI_Main : in out LEA_GWin.MDI_Main.MDI_Main_Type;
repair : in out HAC_Sys.Defs.Diagnostic_Kit
)
is
use LEA_GWin.MDI_Child, LEA_GWin.MDI_Main,
HAC_Sys.Defs, HAC_Sys.Errors,
GWindows.Base,
Ada.Strings.Unbounded, Ada.Strings.Wide_Unbounded;
--
file_name : constant GString := S2G (To_String (repair.file_name));
--
procedure Repair_in_editor (Any_Window : GWindows.Base.Pointer_To_Base_Window_Class)
is
use GWindows.Scintilla;
line_pos, start_pos, end_pos : Position;
expanded : GString_Unbounded;
begin
if Any_Window /= null and then Any_Window.all in MDI_Child_Type'Class then
declare
pw : MDI_Child_Type renames MDI_Child_Type (Any_Window.all);
procedure Expand is
prev_is_backslash : Boolean := False;
alt : constant GString := S2G (HAT.VStr_Pkg.To_String (repair.alternative));
curr_ind : constant Integer :=
pw.editor.Get_Line_Indentation (repair.location.line - 1);
begin
for c of alt loop
case c is
when 't' => -- Tab (\t), replaced by spaces matching indentation setting.
if prev_is_backslash then
expanded := expanded & (Options.indentation) * ' ';
else
expanded := expanded & c;
end if;
when 'n' => -- New line (\n), followed by current line's indentation.
if prev_is_backslash then
expanded := expanded & pw.editor.EOL & curr_ind * ' ';
else
expanded := expanded & c;
end if;
when '\' =>
-- Delay the '\'.
null;
when others =>
if prev_is_backslash then
-- Backslash has no effect on this value of c.
expanded := expanded & '\' & c;
else
expanded := expanded & c;
end if;
end case;
prev_is_backslash := c = '\';
end loop;
if prev_is_backslash then
expanded := expanded & '\';
end if;
end Expand;
begin
if pw.ID.file_name = file_name then
pw.Focus; -- Focus on document already open in our app.
--
pw.editor.Begin_Undo_Action;
--
line_pos := pw.editor.Position_From_Line (repair.location.line - 1); -- Scintilla's lines are 0-based
start_pos := line_pos + Position (repair.location.column_start) - 1;
end_pos := line_pos + Position (repair.location.column_stop);
case repair.repair_kind is
when none =>
-- We should not get here.
null;
when insert =>
-- Set the caret right at the insersion position:
pw.editor.Set_Sel (start_pos, start_pos);
when replace_token =>
-- Mark the string to be deleted and delete it:
pw.editor.Set_Sel (start_pos, end_pos);
pw.editor.Clear;
end case;
Expand;
pw.editor.Insert_Text (pw.editor.Get_Current_Pos, GU2G (expanded));
--
pw.editor.End_Undo_Action;
end if;
end;
end if;
end Repair_in_editor;
begin
if repair.repair_kind = none then
return;
end if;
MDI_Main.Open_Child_Window_And_Load
(file_name,
repair.location.line, -- Scintilla's lines are 0-based
repair.location.column_start - 1,
repair.location.column_stop);
-- At this point, focus is on the editor window (if the file still exists).
Enumerate_Children (
MDI_Client_Window (MDI_Main).all,
Repair_in_editor'Unrestricted_Access
);
-- Disable repair:
repair.repair_kind := none;
end Do_Repair;
end LEA_GWin.Repair;