Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DependencyGraphViewer: Feature add same window navigation for NodeForm #84542

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 112 additions & 7 deletions src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,60 @@ namespace DependencyLogViewer
public partial class NodeForm : Form
{
private readonly Graph _graph;
private readonly Node _node;
private Node _node;

public NodeForm(Graph g, Node n)
{
_graph = g;
_node = n;

InitializeComponent();
SetNode(n);
btnBack.Visible = btnForward.Visible = chkSameWindowNav.Checked;
// this is stupid, this is winforms
var fixControls = new Control[] {btnBack,btnForward,chkSameWindowNav,exploreDependent,dependentsListBox,exploreDependee,dependeesListBox,this,this.splitContainer1 };
foreach (var cntrl in fixControls)
{
cntrl.PreviewKeyDown += Cntrl_PreviewKeyDown;
cntrl.KeyDown += Cntrl_KeyDown;
}
}


private void Cntrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
if (!chkSameWindowNav.Checked)
return;
if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
e.IsInputKey = true;
}

private void Cntrl_KeyDown(object sender, KeyEventArgs e)
{
if (!chkSameWindowNav.Checked)
return;
if (e.KeyCode == Keys.Left)
{
if (btnBack.Enabled)
btnBack.PerformClick();
}
else if (e.KeyCode == Keys.Right)
{
if (btnForward.Enabled)
btnForward.PerformClick();
}
else
return;
e.SuppressKeyPress = true;
e.Handled = true;

}

public void SetNode(Node n)
{

_node = n;

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

lock (GraphCollection.Singleton)
{
Expand All @@ -39,6 +82,9 @@ public NodeForm(Graph g, Node n)
this.dependentsListBox.DataSource = sourceNodes;
this.dependeesListBox.DataSource = targetNodes;
}
if (CurSpotInHistory == -1 && chkSameWindowNav.Checked)//if we are in history we dont modify history
AddSelfToHistory();
SetNavButtonStates();
}

private static void ExploreSelectedItem(Graph graph, ListBox listbox)
Expand All @@ -47,21 +93,80 @@ private static void ExploreSelectedItem(Graph graph, ListBox listbox)
return;

BoxDisplay selected = (BoxDisplay)listbox.SelectedItem;

NodeForm nodeForm = new NodeForm(graph, selected.node);
nodeForm.Show();
}

private void exploreDependee_Click(object sender, EventArgs e)
{
ExploreSelectedItem(_graph, dependeesListBox);
if (chkSameWindowNav.Checked != true)
{
ExploreSelectedItem(_graph, dependeesListBox);
return;
}
ClearHistoryIfIn();
var selected = (BoxDisplay)dependeesListBox.SelectedItem;
SetNode(selected.node);
}

private void exploreDependent_Click(object sender, EventArgs e)
{
ExploreSelectedItem(_graph, dependentsListBox);
if (chkSameWindowNav.Checked != true)
{
ExploreSelectedItem(_graph, dependentsListBox);
return;
}
ClearHistoryIfIn();
var selected = (BoxDisplay)dependentsListBox.SelectedItem;
SetNode(selected.node);
}
private void AddSelfToHistory()
{
History.Add(_node);
}
private void ClearHistoryIfIn()
{

if (CurSpotInHistory != -1)
{
var removeAfter = CurSpotInHistory + 1;
if (removeAfter != History.Count)
History.RemoveRange(removeAfter, History.Count - removeAfter);
CurSpotInHistory = -1;
}

}
public int CurSpotInHistory = -1;
private List<Node> History = new();

private void btnBack_Click(object sender, EventArgs e)
{
if (CurSpotInHistory == -1)
CurSpotInHistory = History.Count - 2;
else if (CurSpotInHistory == 0) // should not get here
return;
else
CurSpotInHistory--;
SetNode(History[CurSpotInHistory]);
}
private void btnForward_Click(object sender, EventArgs e)
{
if (CurSpotInHistory == -1)// should not get here
return;
else if (CurSpotInHistory == History.Count - 1) // should not get here
return;
else
CurSpotInHistory++;
SetNode(History[CurSpotInHistory]);
}
private void SetNavButtonStates()
{
btnBack.Enabled = CurSpotInHistory != 0 && History.Count > 1;
btnForward.Enabled = CurSpotInHistory != -1 && CurSpotInHistory != History.Count - 1;

}
private void ChkSameWindowNav_CheckedChanged(object sender, System.EventArgs e) => btnBack.Visible = btnForward.Visible = chkSameWindowNav.Checked;
private void infoButton_LinkClicked(object sender, EventArgs e)
{
string dMessage = "Dependent nodes depend on the current node. The current node depends on the dependees.";
Expand Down