Skip to content

Commit 03b6178

Browse files
DependencyGraphViewer: Feature add same window navigation for NodeForm (#84542)
* DependencyGraphViewer: Feature add same window navigation for NodeForm Add ability to reuse current window rather than open new, added history (forward/back) and arrow key accelerators as well. * Fix code formatting --------- Co-authored-by: David Wrighton <[email protected]>
1 parent 16ad8cb commit 03b6178

File tree

2 files changed

+154
-9
lines changed

2 files changed

+154
-9
lines changed

src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs

Lines changed: 47 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,58 @@ namespace DependencyLogViewer
1010
public partial class NodeForm : Form
1111
{
1212
private readonly Graph _graph;
13-
private readonly Node _node;
13+
private Node _node;
1414

1515
public NodeForm(Graph g, Node n)
1616
{
1717
_graph = g;
18-
_node = n;
19-
2018
InitializeComponent();
19+
SetNode(n);
20+
btnBack.Visible = btnForward.Visible = chkSameWindowNav.Checked;
21+
var fixControls = new Control[] {btnBack, btnForward, chkSameWindowNav, exploreDependent, dependentsListBox, exploreDependee, dependeesListBox, this, this.splitContainer1 };
22+
foreach (var cntrl in fixControls)
23+
{
24+
cntrl.PreviewKeyDown += Cntrl_PreviewKeyDown;
25+
cntrl.KeyDown += Cntrl_KeyDown;
26+
}
27+
}
28+
29+
30+
private void Cntrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
31+
if (!chkSameWindowNav.Checked)
32+
return;
33+
if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
34+
e.IsInputKey = true;
35+
}
36+
37+
private void Cntrl_KeyDown(object sender, KeyEventArgs e)
38+
{
39+
if (!chkSameWindowNav.Checked)
40+
return;
41+
if (e.KeyCode == Keys.Left)
42+
{
43+
if (btnBack.Enabled)
44+
btnBack.PerformClick();
45+
}
46+
else if (e.KeyCode == Keys.Right)
47+
{
48+
if (btnForward.Enabled)
49+
btnForward.PerformClick();
50+
}
51+
else
52+
return;
53+
e.SuppressKeyPress = true;
54+
e.Handled = true;
55+
}
56+
57+
public void SetNode(Node n)
58+
{
59+
60+
_node = n;
2161

2262
this.Text = $"Graph Pid: {_graph.PID}, ID: {_graph.ID}, Node: {_node.ToString}";
23-
this.nodeTitle.Text = $"Current Node: {_node}";
63+
var nodeStr = _node.ToString().Replace(", ", "\n");
64+
this.nodeTitle.Text = $"Current Node: {nodeStr}";
2465

2566
lock (GraphCollection.Singleton)
2667
{
@@ -39,6 +80,9 @@ public NodeForm(Graph g, Node n)
3980
this.dependentsListBox.DataSource = sourceNodes;
4081
this.dependeesListBox.DataSource = targetNodes;
4182
}
83+
if (CurSpotInHistory == -1 && chkSameWindowNav.Checked)//if we are in history we dont modify history
84+
AddSelfToHistory();
85+
SetNavButtonStates();
4286
}
4387

4488
private static void ExploreSelectedItem(Graph graph, ListBox listbox)
@@ -54,14 +98,71 @@ private static void ExploreSelectedItem(Graph graph, ListBox listbox)
5498

5599
private void exploreDependee_Click(object sender, EventArgs e)
56100
{
57-
ExploreSelectedItem(_graph, dependeesListBox);
101+
if (chkSameWindowNav.Checked != true)
102+
{
103+
ExploreSelectedItem(_graph, dependeesListBox);
104+
return;
105+
}
106+
ClearHistoryIfIn();
107+
var selected = (BoxDisplay)dependeesListBox.SelectedItem;
108+
SetNode(selected.node);
58109
}
59110

60111
private void exploreDependent_Click(object sender, EventArgs e)
61112
{
62-
ExploreSelectedItem(_graph, dependentsListBox);
113+
if (chkSameWindowNav.Checked != true)
114+
{
115+
ExploreSelectedItem(_graph, dependentsListBox);
116+
return;
117+
}
118+
ClearHistoryIfIn();
119+
var selected = (BoxDisplay)dependentsListBox.SelectedItem;
120+
SetNode(selected.node);
121+
}
122+
private void AddSelfToHistory()
123+
{
124+
History.Add(_node);
125+
}
126+
private void ClearHistoryIfIn()
127+
{
128+
129+
if (CurSpotInHistory != -1)
130+
{
131+
var removeAfter = CurSpotInHistory + 1;
132+
if (removeAfter != History.Count)
133+
History.RemoveRange(removeAfter, History.Count - removeAfter);
134+
CurSpotInHistory = -1;
135+
}
63136
}
137+
public int CurSpotInHistory = -1;
138+
private List<Node> History = new();
64139

140+
private void btnBack_Click(object sender, EventArgs e)
141+
{
142+
if (CurSpotInHistory == -1)
143+
CurSpotInHistory = History.Count - 2;
144+
else if (CurSpotInHistory == 0) // should not get here
145+
return;
146+
else
147+
CurSpotInHistory--;
148+
SetNode(History[CurSpotInHistory]);
149+
}
150+
private void btnForward_Click(object sender, EventArgs e)
151+
{
152+
if (CurSpotInHistory == -1)// should not get here
153+
return;
154+
else if (CurSpotInHistory == History.Count - 1) // should not get here
155+
return;
156+
else
157+
CurSpotInHistory++;
158+
SetNode(History[CurSpotInHistory]);
159+
}
160+
private void SetNavButtonStates()
161+
{
162+
btnBack.Enabled = CurSpotInHistory != 0 && History.Count > 1;
163+
btnForward.Enabled = CurSpotInHistory != -1 && CurSpotInHistory != History.Count - 1;
164+
}
165+
private void ChkSameWindowNav_CheckedChanged(object sender, System.EventArgs e) => btnBack.Visible = btnForward.Visible = chkSameWindowNav.Checked;
65166
private void infoButton_LinkClicked(object sender, EventArgs e)
66167
{
67168
string dMessage = "Dependent nodes depend on the current node. The current node depends on the dependees.";

0 commit comments

Comments
 (0)