From a590783b6d45c51575549936a38b3b7ac85e964b Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Sun, 9 Apr 2023 03:23:25 -0700 Subject: [PATCH 1/2] 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. --- .../NodeForm.Designer.cs | 50 +++++++- .../aot/DependencyGraphViewer/NodeForm.cs | 119 ++++++++++++++++-- 2 files changed, 159 insertions(+), 10 deletions(-) diff --git a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs index e01fe39e80028c..47be46b97a1715 100644 --- a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs +++ b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs @@ -33,6 +33,9 @@ private void InitializeComponent() { this.nodeTitle = new System.Windows.Forms.Label(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + chkSameWindowNav = new System.Windows.Forms.CheckBox(); + btnBack = new System.Windows.Forms.Button(); + btnForward = new System.Windows.Forms.Button(); this.dependentsListBox = new System.Windows.Forms.ListBox(); this.exploreDependent = new System.Windows.Forms.Button(); this.dependeesListBox = new System.Windows.Forms.ListBox(); @@ -45,21 +48,22 @@ private void InitializeComponent() // // nodeTitle // - this.nodeTitle.AutoSize = true; this.nodeTitle.BackColor = System.Drawing.SystemColors.Info; this.nodeTitle.Dock = System.Windows.Forms.DockStyle.Top; this.nodeTitle.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); this.nodeTitle.Location = new System.Drawing.Point(0, 0); this.nodeTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.nodeTitle.Name = "nodeTitle"; - this.nodeTitle.Size = new System.Drawing.Size(116, 30); + this.nodeTitle.Size = new System.Drawing.Size(1220, 75); this.nodeTitle.TabIndex = 0; this.nodeTitle.Text = "Node Title"; + this.nodeTitle.TextAlign = System.Drawing.ContentAlignment.BottomLeft; + this.nodeTitle.AutoEllipsis = true; // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 30); + this.splitContainer1.Location = new System.Drawing.Point(0, 75); this.splitContainer1.Margin = new System.Windows.Forms.Padding(4); this.splitContainer1.Name = "splitContainer1"; this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; @@ -77,6 +81,39 @@ private void InitializeComponent() this.splitContainer1.SplitterDistance = 419; this.splitContainer1.SplitterWidth = 6; this.splitContainer1.TabIndex = 1; + // + // chkSameWindowNav + // + chkSameWindowNav.AutoSize = true; + chkSameWindowNav.Location = new System.Drawing.Point(890, 0); + chkSameWindowNav.Name = "chkSameWindowNav"; + chkSameWindowNav.Size = new System.Drawing.Size(322, 36); + chkSameWindowNav.TabIndex = 5; + chkSameWindowNav.Text = "Same Window Nav"; + chkSameWindowNav.UseVisualStyleBackColor = true; + chkSameWindowNav.CheckedChanged += ChkSameWindowNav_CheckedChanged; + // + // btnBack + // + btnBack.Location = new System.Drawing.Point(607, 0); + btnBack.Margin = new System.Windows.Forms.Padding(4); + btnBack.Name = "btnBack"; + btnBack.Size = new System.Drawing.Size(124, 43); + btnBack.TabIndex = 3; + btnBack.Text = "Back"; + btnBack.UseVisualStyleBackColor = true; + btnBack.Click += btnBack_Click; + // + // btnForward + // + btnForward.Location = new System.Drawing.Point(750, 0); + btnForward.Margin = new System.Windows.Forms.Padding(4); + btnForward.Name = "btnForward"; + btnForward.Size = new System.Drawing.Size(124, 43); + btnForward.TabIndex = 4; + btnForward.Text = "Forward"; + btnForward.UseVisualStyleBackColor = true; + btnForward.Click += btnForward_Click; // // dependentsListBox // @@ -133,6 +170,9 @@ private void InitializeComponent() this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1126, 836); + Controls.Add(chkSameWindowNav); + Controls.Add(btnBack); + Controls.Add(btnForward); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.nodeTitle); this.Margin = new System.Windows.Forms.Padding(4); @@ -148,6 +188,7 @@ private void InitializeComponent() } + #endregion private System.Windows.Forms.Label nodeTitle; @@ -156,5 +197,8 @@ private void InitializeComponent() private System.Windows.Forms.ListBox dependeesListBox; private System.Windows.Forms.Button exploreDependent; private System.Windows.Forms.ListBox dependentsListBox; + private System.Windows.Forms.Button btnBack; + private System.Windows.Forms.CheckBox chkSameWindowNav; + private System.Windows.Forms.Button btnForward; } } diff --git a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs index e2bcf5a4547c42..63f995d0c0bd72 100644 --- a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs +++ b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs @@ -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) { @@ -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) @@ -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 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."; From 35d79bd00be958ec826d1e49b6d7500ebd6aaa68 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Tue, 18 Jul 2023 09:50:00 -0700 Subject: [PATCH 2/2] Fix code formatting --- .../NodeForm.Designer.cs | 80 +++++++++---------- .../aot/DependencyGraphViewer/NodeForm.cs | 22 +++-- 2 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs index 47be46b97a1715..de1ee51de78eb8 100644 --- a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs +++ b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.Designer.cs @@ -33,9 +33,9 @@ private void InitializeComponent() { this.nodeTitle = new System.Windows.Forms.Label(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - chkSameWindowNav = new System.Windows.Forms.CheckBox(); - btnBack = new System.Windows.Forms.Button(); - btnForward = new System.Windows.Forms.Button(); + this.chkSameWindowNav = new System.Windows.Forms.CheckBox(); + this.btnBack = new System.Windows.Forms.Button(); + this.btnForward = new System.Windows.Forms.Button(); this.dependentsListBox = new System.Windows.Forms.ListBox(); this.exploreDependent = new System.Windows.Forms.Button(); this.dependeesListBox = new System.Windows.Forms.ListBox(); @@ -81,39 +81,39 @@ private void InitializeComponent() this.splitContainer1.SplitterDistance = 419; this.splitContainer1.SplitterWidth = 6; this.splitContainer1.TabIndex = 1; - // - // chkSameWindowNav - // - chkSameWindowNav.AutoSize = true; - chkSameWindowNav.Location = new System.Drawing.Point(890, 0); - chkSameWindowNav.Name = "chkSameWindowNav"; - chkSameWindowNav.Size = new System.Drawing.Size(322, 36); - chkSameWindowNav.TabIndex = 5; - chkSameWindowNav.Text = "Same Window Nav"; - chkSameWindowNav.UseVisualStyleBackColor = true; - chkSameWindowNav.CheckedChanged += ChkSameWindowNav_CheckedChanged; - // - // btnBack - // - btnBack.Location = new System.Drawing.Point(607, 0); - btnBack.Margin = new System.Windows.Forms.Padding(4); - btnBack.Name = "btnBack"; - btnBack.Size = new System.Drawing.Size(124, 43); - btnBack.TabIndex = 3; - btnBack.Text = "Back"; - btnBack.UseVisualStyleBackColor = true; - btnBack.Click += btnBack_Click; - // + // + // chkSameWindowNav + // + this.chkSameWindowNav.AutoSize = true; + this.chkSameWindowNav.Location = new System.Drawing.Point(890, 0); + this.chkSameWindowNav.Name = "chkSameWindowNav"; + this.chkSameWindowNav.Size = new System.Drawing.Size(322, 36); + this.chkSameWindowNav.TabIndex = 5; + this.chkSameWindowNav.Text = "Same Window Nav"; + this.chkSameWindowNav.UseVisualStyleBackColor = true; + this.chkSameWindowNav.CheckedChanged += ChkSameWindowNav_CheckedChanged; + // + // btnBack + // + this.btnBack.Location = new System.Drawing.Point(607, 0); + this.btnBack.Margin = new System.Windows.Forms.Padding(4); + this.btnBack.Name = "btnBack"; + this.btnBack.Size = new System.Drawing.Size(124, 43); + this.btnBack.TabIndex = 3; + this.btnBack.Text = "Back"; + this.btnBack.UseVisualStyleBackColor = true; + this.btnBack.Click += btnBack_Click; + // // btnForward // - btnForward.Location = new System.Drawing.Point(750, 0); - btnForward.Margin = new System.Windows.Forms.Padding(4); - btnForward.Name = "btnForward"; - btnForward.Size = new System.Drawing.Size(124, 43); - btnForward.TabIndex = 4; - btnForward.Text = "Forward"; - btnForward.UseVisualStyleBackColor = true; - btnForward.Click += btnForward_Click; + this.btnForward.Location = new System.Drawing.Point(750, 0); + this.btnForward.Margin = new System.Windows.Forms.Padding(4); + this.btnForward.Name = "btnForward"; + this.btnForward.Size = new System.Drawing.Size(124, 43); + this.btnForward.TabIndex = 4; + this.btnForward.Text = "Forward"; + this.btnForward.UseVisualStyleBackColor = true; + this.btnForward.Click += btnForward_Click; // // dependentsListBox // @@ -170,9 +170,9 @@ private void InitializeComponent() this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 30F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1126, 836); - Controls.Add(chkSameWindowNav); - Controls.Add(btnBack); - Controls.Add(btnForward); + Controls.Add(chkSameWindowNav); + Controls.Add(btnBack); + Controls.Add(btnForward); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.nodeTitle); this.Margin = new System.Windows.Forms.Padding(4); @@ -197,8 +197,8 @@ private void InitializeComponent() private System.Windows.Forms.ListBox dependeesListBox; private System.Windows.Forms.Button exploreDependent; private System.Windows.Forms.ListBox dependentsListBox; - private System.Windows.Forms.Button btnBack; - private System.Windows.Forms.CheckBox chkSameWindowNav; - private System.Windows.Forms.Button btnForward; + private System.Windows.Forms.Button btnBack; + private System.Windows.Forms.CheckBox chkSameWindowNav; + private System.Windows.Forms.Button btnForward; } } diff --git a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs index b3ede12a19472f..14793b7756de5b 100644 --- a/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs +++ b/src/coreclr/tools/aot/DependencyGraphViewer/NodeForm.cs @@ -18,8 +18,7 @@ public NodeForm(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 }; + var fixControls = new Control[] {btnBack, btnForward, chkSameWindowNav, exploreDependent, dependentsListBox, exploreDependee, dependeesListBox, this, this.splitContainer1 }; foreach (var cntrl in fixControls) { cntrl.PreviewKeyDown += Cntrl_PreviewKeyDown; @@ -53,7 +52,6 @@ private void Cntrl_KeyDown(object sender, KeyEventArgs e) return; e.SuppressKeyPress = true; e.Handled = true; - } public void SetNode(Node n) @@ -93,7 +91,7 @@ private static void ExploreSelectedItem(Graph graph, ListBox listbox) return; BoxDisplay selected = (BoxDisplay)listbox.SelectedItem; - + NodeForm nodeForm = new NodeForm(graph, selected.node); nodeForm.Show(); } @@ -103,7 +101,7 @@ private void exploreDependee_Click(object sender, EventArgs e) if (chkSameWindowNav.Checked != true) { ExploreSelectedItem(_graph, dependeesListBox); - return; + return; } ClearHistoryIfIn(); var selected = (BoxDisplay)dependeesListBox.SelectedItem; @@ -135,13 +133,12 @@ private void ClearHistoryIfIn() History.RemoveRange(removeAfter, History.Count - removeAfter); CurSpotInHistory = -1; } - } public int CurSpotInHistory = -1; private List History = new(); - private void btnBack_Click(object sender, EventArgs e) - { + private void btnBack_Click(object sender, EventArgs e) + { if (CurSpotInHistory == -1) CurSpotInHistory = History.Count - 2; else if (CurSpotInHistory == 0) // should not get here @@ -149,22 +146,21 @@ private void btnBack_Click(object sender, EventArgs e) 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++; + 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)