From 204c4526eb575411187bfcb50a668b45c1c1cccd Mon Sep 17 00:00:00 2001 From: Tomas Linhart Date: Sat, 3 Sep 2011 18:05:13 +0200 Subject: [PATCH] Add HoveredCellChanged event. --- .../Src/Controls/DependencyGraphLayout.cs | 1 - .../CodeQuality/Src/Controls/MatrixControl.cs | 36 +++++++++++++++---- .../Src/Controls/TreeMatrixControl.xaml | 7 ++-- .../Analysis/CodeQuality/Src/MetricsReader.cs | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraphLayout.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraphLayout.cs index 1ab43e325e..341a556be4 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraphLayout.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/DependencyGraphLayout.cs @@ -366,7 +366,6 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls New = @new; Old = old; } - } } } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs b/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs index c7e17f409c..7b5d533bad 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/MatrixControl.cs @@ -16,6 +16,8 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls public class MatrixControl : FrameworkElement, IScrollInfo where TValue : IValue { + public event EventHandler> HoveredCellChanged; + private Dictionary imgs = new Dictionary(); private Coords currentCell = new Coords(-1, -1); private string font; @@ -50,6 +52,8 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls public HoveredCell HoveredCell { get; set; } + public bool RenderZeroes { get; set; } + public MatrixControl() { CellHeight = CellWidth = 36; @@ -72,7 +76,17 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls else currentCell = new Coords(-1, -1); - InvalidateVisual(); + if (currentCell.X != HoveredCell.RowIndex || + currentCell.Y != HoveredCell.ColumnIndex) + { + InvalidateVisual(); + + HoveredCell.RowIndex = currentCell.X; + HoveredCell.ColumnIndex = currentCell.Y; + HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex]; + if (HoveredCellChanged != null) + HoveredCellChanged(this, new HoveredCellEventArgs(HoveredCell)); + } } protected override void OnRender(DrawingContext drawingContext) @@ -156,11 +170,11 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls // text for (int i = 0; i < cellsHorizontally; i++) { for (int j = 0; j < cellsVertically; j++) { - HoveredCell.RowIndex = i + scaledOffsetX; - HoveredCell.ColumnIndex = j + scaledOffsetY; - HoveredCell.Value = matrix[HoveredCell.RowIndex, HoveredCell.ColumnIndex]; + int rowIndex = i + scaledOffsetX; + int columnIndex = j + scaledOffsetY; + var value = matrix[rowIndex, columnIndex]; drawingContext.DrawImage( - CreateText(HoveredCell.Value.Text), + CreateText(value.Text), new Rect(i * CellWidth - offsetDiffX, j * CellHeight - offsetDiffY, CellWidth, CellHeight)); } } @@ -168,7 +182,7 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls public ImageSource CreateText(string text) { - if (text == "0") // rendering zeroes would be distracting + if (!RenderZeroes && text == "0") // rendering zeroes would be distracting text = string.Empty; if (imgs.ContainsKey(text)) @@ -392,4 +406,14 @@ namespace ICSharpCode.CodeQualityAnalysis.Controls public int ColumnIndex { get; set; } public TValue Value { get; set; } } + + public class HoveredCellEventArgs : EventArgs + { + public HoveredCell HoveredCell { get; set; } + + public HoveredCellEventArgs(HoveredCell cell) + { + HoveredCell = cell; + } + } } diff --git a/src/AddIns/Analysis/CodeQuality/Src/Controls/TreeMatrixControl.xaml b/src/AddIns/Analysis/CodeQuality/Src/Controls/TreeMatrixControl.xaml index d5609e190c..fd7f90f7ab 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/Controls/TreeMatrixControl.xaml +++ b/src/AddIns/Analysis/CodeQuality/Src/Controls/TreeMatrixControl.xaml @@ -6,11 +6,8 @@ xmlns:Controls="clr-namespace:ICSharpCode.CodeQualityAnalysis.Controls" xmlns:tree="http://icsharpcode.net/sharpdevelop/treeview"> - diff --git a/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs b/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs index 90d8878323..d30048ed54 100644 --- a/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs +++ b/src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs @@ -603,7 +603,7 @@ namespace ICSharpCode.CodeQualityAnalysis if (!String.IsNullOrEmpty(type.Namespace)) return type.Namespace; - return "-"; + return "(no namespace)"; } } }