Browse Source
- refactored value providers - values are obtained from debugger only for displayed columns - scrolls to top when new variable inspected git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4577 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
12 changed files with 251 additions and 92 deletions
@ -0,0 +1,50 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Martin Koníèek" email="martin.konicek@gmail.com"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
using Debugger.MetaData; |
||||||
|
using Debugger.AddIn.Visualizers.Utils; |
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.SharpDevelop.Services; |
||||||
|
using ICSharpCode.NRefactory.Ast; |
||||||
|
|
||||||
|
namespace Debugger.AddIn.Visualizers.GridVisualizer |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Provides <see cref="ObjectValue"/>s to be displayed in Grid visualizer.
|
||||||
|
/// Descandants implement getting values for IList and IEnumerable.
|
||||||
|
/// </summary>
|
||||||
|
public class GridValuesProvider |
||||||
|
{ |
||||||
|
protected readonly Debugger.MetaData.BindingFlags memberBindingFlags = |
||||||
|
BindingFlags.Public | BindingFlags.Instance | BindingFlags.Field | BindingFlags.GetProperty; |
||||||
|
|
||||||
|
/// <summary> Used to quickly find MemberInfo by member name - DebugType.GetMember(name) uses a loop to search members </summary>
|
||||||
|
protected Dictionary<string, MemberInfo> memberFromNameMap; |
||||||
|
|
||||||
|
protected Expression targetObject; |
||||||
|
protected DebugType collectionType; |
||||||
|
protected DebugType itemType; |
||||||
|
|
||||||
|
public GridValuesProvider(Expression targetObject, DebugType collectionType, DebugType itemType) |
||||||
|
{ |
||||||
|
this.targetObject = targetObject; |
||||||
|
this.collectionType = collectionType; |
||||||
|
this.itemType = itemType; |
||||||
|
|
||||||
|
this.memberFromNameMap = this.GetItemTypeMembers().MakeDictionary(memberInfo => memberInfo.Name); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets members that will be displayed as columns.
|
||||||
|
/// </summary>
|
||||||
|
public IList<MemberInfo> GetItemTypeMembers() |
||||||
|
{ |
||||||
|
return itemType.GetMembers(this.memberBindingFlags); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Martin Koníèek" email="martin.konicek@gmail.com"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
namespace Debugger.AddIn.Visualizers |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of ScrollUtils.
|
||||||
|
/// </summary>
|
||||||
|
public static class ScrollUtils |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Searches VisualTree of given object for a ScrollViewer.
|
||||||
|
/// </summary>
|
||||||
|
public static ScrollViewer GetScrollViewer(this DependencyObject o) |
||||||
|
{ |
||||||
|
var scrollViewer = o as ScrollViewer; |
||||||
|
if (scrollViewer != null) { |
||||||
|
return scrollViewer; |
||||||
|
} |
||||||
|
|
||||||
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(o); i++) |
||||||
|
{ |
||||||
|
var child = VisualTreeHelper.GetChild(o, i); |
||||||
|
var result = GetScrollViewer(child); |
||||||
|
if (result != null) { |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,48 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Martin Koníèek" email="martin.konicek@gmail.com"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System; |
||||||
|
|
||||||
|
namespace Debugger.AddIn.Visualizers.Utils |
||||||
|
{ |
||||||
|
public static class IEnumerableExtensions |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Builds Dictionary for quickly searching a collection.
|
||||||
|
/// The keys must be unique.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collection">Collection for which to build Dictionary.</param>
|
||||||
|
/// <param name="keySelector">Function returning key by which to index.</param>
|
||||||
|
public static Dictionary<K, V> MakeDictionary<K, V>(this IEnumerable<V> collection, Func<V, K> keySelector) |
||||||
|
{ |
||||||
|
Dictionary<K, V> dictionary = new Dictionary<K, V>(); |
||||||
|
foreach (V item in collection) |
||||||
|
{ |
||||||
|
K key = keySelector(item); |
||||||
|
if (dictionary.ContainsKey(key)) throw new InvalidOperationException("MakeDictionary: key " + key + " seen twice"); |
||||||
|
dictionary[key] = item; |
||||||
|
} |
||||||
|
return dictionary; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds Lookup for quickly searching a collection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collection">Collection for which to build Dictionary.</param>
|
||||||
|
/// <param name="keySelector">Function returning key by which to index.</param>
|
||||||
|
public static Lookup<K, V> MakeLookup<K, V>(this IEnumerable<V> collection, Func<V, K> keySelector) |
||||||
|
{ |
||||||
|
Lookup<K, V> lookup = new Lookup<K, V>(); |
||||||
|
foreach (V item in collection) |
||||||
|
{ |
||||||
|
lookup.Add(keySelector(item), item); |
||||||
|
} |
||||||
|
return lookup; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue