Skip to content

Commit 1decad7

Browse files
committed
Merge branch '22-dap-integration-239-1' into 'master'
Scroll to the selected variable after the variable view updating See merge request eng/ide/gnatstudio!437
2 parents 6526ffc + 93801f5 commit 1decad7

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

dap/src/modules/dap-views-variables.adb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ package body DAP.Views.Variables is
366366
use type Expansions.Expansion_Status;
367367
begin
368368
if Self.Expansion /= Expansions.No_Expansion then
369-
Expansions.Set_Expansion_Status
369+
Expansions.Set_Expansion_Status_Stop_On_Dummy
370370
(Self.Tree, Self.Expansion);
371371
end if;
372372
end Restore_Expansion;
@@ -1373,11 +1373,19 @@ package body DAP.Views.Variables is
13731373
(Self : not null access DAP_Variables_View_Record)
13741374
is
13751375
use type DAP.Clients.DAP_Client_Access;
1376+
use type Expansions.Expansion_Status;
13761377

13771378
Client : constant DAP.Clients.DAP_Client_Access := Get_Client (Self);
13781379
begin
13791380
Trace (Me, "Update view");
13801381

1382+
if not Self.Tree.Items.Is_Empty
1383+
and then Self.Expansion = Expansions.No_Expansion
1384+
then
1385+
-- Store expansion if not done yet
1386+
Expansions.Get_Expansion_Status (Self.Tree, Self.Expansion);
1387+
end if;
1388+
13811389
if Client /= null
13821390
and then Client.Get_Variables /= null
13831391
then
@@ -1397,7 +1405,6 @@ package body DAP.Views.Variables is
13971405

13981406
elsif not Self.Tree.Items.Is_Empty then
13991407
Self.Tree.Types_Column.Set_Visible (Show_Types.Get_Pref);
1400-
Expansions.Get_Expansion_Status (Self.Tree, Self.Expansion);
14011408
Self.Tree.Model.Clear;
14021409

14031410
Self.Update (0);

testsuite/tests/dap.V711-016.arguments/main.adb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ procedure Main is
44
procedure Print (I : Integer; B : Boolean) is
55
begin
66
Ada.Text_IO.Put_Line ("Hello" & B'Img & I'Img);
7+
Ada.Text_IO.Put_Line ("Hello" & B'Img & I'Img);
78
end;
89

910
I : constant Integer := 0;
1011
B : constant Boolean := False;
1112
Arguments : constant Integer := 5;
13+
14+
type Rec is record
15+
A : Integer := 1;
16+
B : Boolean := False;
17+
end record;
18+
19+
R : Rec;
20+
1221
begin
1322
Print (I, B);
1423
end Main;

testsuite/tests/dap.V711-016.arguments/test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,19 @@ def run_test():
5151
dump = dump_tree_model(tree.get_model(), 0)
5252
gps_assert(dump, expected_names_1)
5353

54+
# test that we restore the variable view selection
55+
debug.send("graph display R")
56+
yield wait_until_not_busy(debug)
57+
tree = get_widget_by_name("Variables Tree")
58+
tree.expand_row(Gtk.TreePath((0)), True)
59+
tree.expand_row(Gtk.TreePath((2)), True)
60+
tree.get_selection().select_path(Gtk.TreePath("1"))
61+
62+
debug.send("step")
63+
yield wait_DAP_server("variables")
64+
yield wait_until_not_busy(debug)
65+
66+
gps_assert(tree.get_selection().iter_is_selected(tree.get_model().get_iter("1")),
67+
True,
68+
"Wrong variable is selected")
69+
gps_assert(tree.row_expanded(Gtk.TreePath((2))), True, "Expansion not restored")

widgets/src/gtkada-tree_view.adb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,90 @@ package body Gtkada.Tree_View is
12801280
end if;
12811281
end Set_Expansion_Status;
12821282

1283+
----------------------------------------
1284+
-- Set_Expansion_Status_Stop_On_Dummy --
1285+
----------------------------------------
1286+
1287+
procedure Set_Expansion_Status_Stop_On_Dummy
1288+
(Self : not null access Tree_Record'Class;
1289+
Status : in out Expansion_Status)
1290+
is
1291+
Stopped : Boolean := False;
1292+
-- Flag to stop expanding when we found a dummy node that means that
1293+
-- not all data is loaded
1294+
1295+
function Expand_Node
1296+
(Model : Gtk_Tree_Model;
1297+
Path : Gtk_Tree_Path;
1298+
Iter : Gtk_Tree_Iter) return Boolean;
1299+
1300+
-----------------
1301+
-- Expand_Node --
1302+
-----------------
1303+
1304+
function Expand_Node
1305+
(Model : Gtk_Tree_Model;
1306+
Path : Gtk_Tree_Path;
1307+
Iter : Gtk_Tree_Iter) return Boolean
1308+
is
1309+
pragma Unreferenced (Path);
1310+
1311+
Dummy : Boolean;
1312+
The_Id : constant Id := Get_Id (Self, Iter);
1313+
Sortable_Path : Gtk_Tree_Path;
1314+
1315+
begin
1316+
if Status.Expanded.Contains (The_Id) then
1317+
1318+
-- check whether the node contains the dummy node
1319+
if Model.Has_Child (Iter) then
1320+
Stopped := Get_Flag
1321+
(Self, Model.Children (Iter), Flag_Is_Dummy);
1322+
end if;
1323+
1324+
Sortable_Path := Self.Get_Sortable_Path_For_Store_Iter (Iter);
1325+
Dummy := Self.Expand_Row (Sortable_Path, Open_All => False);
1326+
Path_Free (Sortable_Path);
1327+
end if;
1328+
1329+
if not Stopped then
1330+
if Status.Selection.Contains (The_Id) then
1331+
Self.Get_Selection.Select_Iter
1332+
(Self.Convert_To_Sortable_Model_Iter (Iter));
1333+
end if;
1334+
end if;
1335+
1336+
-- Return True to stop iterating or False to continue
1337+
return Stopped;
1338+
end Expand_Node;
1339+
1340+
begin
1341+
if Status = No_Expansion then
1342+
return;
1343+
end if;
1344+
1345+
Self.Collapse_All;
1346+
Self.Model.Foreach (Expand_Node'Unrestricted_Access);
1347+
1348+
if Stopped then
1349+
-- we found the dummy node, stop for now
1350+
return;
1351+
end if;
1352+
1353+
-- here we have all nodes created
1354+
if Status.Has_Scroll_Info then
1355+
Gtk_Tree_View_Record (Self.all).Scroll_To_Cell
1356+
(Path => Status.Scroll_Y,
1357+
Column => null,
1358+
Use_Align => False,
1359+
Row_Align => 0.0,
1360+
Col_Align => 0.0);
1361+
Path_Free (Status.Scroll_Y);
1362+
end if;
1363+
1364+
Status := No_Expansion;
1365+
end Set_Expansion_Status_Stop_On_Dummy;
1366+
12831367
-----------------------
12841368
-- On_Tree_Destroyed --
12851369
-----------------------

widgets/src/gtkada-tree_view.ads

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ package Gtkada.Tree_View is
191191
-- across refresh of the model.
192192
-- This also preserves the current scrolling position
193193

194+
procedure Set_Expansion_Status_Stop_On_Dummy
195+
(Self : not null access Tree_Record'Class;
196+
Status : in out Expansion_Status);
197+
-- Same as above but stop on the first expanding node that contains
198+
-- the "dummy" child. Clears Status when not stopped and expansion,
199+
-- scrolling, and selection are restored. Is used when getting/filling
200+
-- data asynchronous.
201+
194202
type Detached_Model is new Ada.Finalization.Limited_Controlled
195203
with private;
196204
type Detached_Model_Access is access all Detached_Model'Class;

0 commit comments

Comments
 (0)