Browse Source

code cleanup - remove dynamic code from Debugger.AddIn

pull/18/head
Siegfried Pammer 14 years ago
parent
commit
f93a898750
  1. 7
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj
  2. 16
      src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/SimpleListViewControl.xaml
  3. 62
      src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/SimpleListViewControl.xaml.cs
  4. 60
      src/AddIns/Debugger/Debugger.AddIn/Pads/LoadedModulesPad.cs
  5. 180
      src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ParallelStackFrameModel.cs
  6. 92
      src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ParallelStackPad.cs
  7. 45
      src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ThreadStack.xaml.cs
  8. 15
      src/AddIns/Debugger/Debugger.AddIn/Pads/RunningThreadsPad.Menu.cs
  9. 85
      src/AddIns/Debugger/Debugger.AddIn/Pads/RunningThreadsPad.cs
  10. 8
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/PresentationBindings/EnumViewModel.cs
  11. 6
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/PresentationBindings/GridViewColumnHider.cs
  12. 23
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/PresentationBindings/ViewModelBase.cs
  13. 13
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs
  14. 93
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ViewModelBase.cs

7
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj

@ -114,10 +114,6 @@ @@ -114,10 +114,6 @@
<DependentUpon>ConditionCell.xaml</DependentUpon>
</Compile>
<Compile Include="Pads\Controls\Converters.cs" />
<Compile Include="Pads\Controls\SimpleListViewControl.xaml.cs">
<DependentUpon>SimpleListViewControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Pads\Controls\WatchList.xaml.cs">
<DependentUpon>WatchList.xaml</DependentUpon>
</Compile>
@ -129,6 +125,7 @@ @@ -129,6 +125,7 @@
<DependentUpon>DrawSurface.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Pads\ParallelPad\ParallelStackFrameModel.cs" />
<Compile Include="Pads\ParallelPad\ParallelStackPad.cs" />
<Compile Include="Pads\ParallelPad\ParallelStacksGraph.cs" />
<Compile Include="Pads\ParallelPad\SelectedFrameBookmark.cs" />
@ -327,7 +324,6 @@ @@ -327,7 +324,6 @@
</Compile>
<Compile Include="Visualizers\PresentationBindings\DisplayAttribute.cs" />
<Compile Include="Visualizers\PresentationBindings\EnumViewModel.cs" />
<Compile Include="Visualizers\PresentationBindings\ViewModelBase.cs" />
<None Include="COPYING" />
</ItemGroup>
<ItemGroup>
@ -385,7 +381,6 @@ @@ -385,7 +381,6 @@
<Page Include="Options\DebuggingOptionsPanel.xaml" />
<Page Include="Pads\CallStackPad.xaml" />
<Page Include="Pads\Controls\ConditionCell.xaml" />
<Page Include="Pads\Controls\SimpleListViewControl.xaml" />
<Page Include="Pads\Controls\WatchList.xaml" />
<Page Include="Pads\Controls\WatchListAutoCompleteCell.xaml" />
<Page Include="Pads\ParallelPad\DrawSurface.xaml" />

16
src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/SimpleListViewControl.xaml

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="Debugger.AddIn.Pads.Controls.SimpleListViewControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<ListView
ItemsSource="{Binding ItemCollection}"
x:Name="ItemsListView">
<ListView.View>
<GridView>
<GridView.Columns>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</UserControl>

62
src/AddIns/Debugger/Debugger.AddIn/Pads/Controls/SimpleListViewControl.xaml.cs

@ -1,62 +0,0 @@ @@ -1,62 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace Debugger.AddIn.Pads.Controls
{
public partial class SimpleListViewControl : UserControl
{
public event EventHandler ItemActivated;
private ObservableCollection<ExpandoObject> itemCollection = new ObservableCollection<ExpandoObject>();
public SimpleListViewControl()
{
InitializeComponent();
ItemsListView.MouseDoubleClick += new MouseButtonEventHandler(ItemsListView_MouseDoubleClick);
}
public ObservableCollection<ExpandoObject> ItemCollection {
get { return itemCollection; }
}
public IList<ExpandoObject> SelectedItems {
get {
var result = new List<ExpandoObject>();
foreach (var item in ItemsListView.SelectedItems)
result.Add((ExpandoObject)item);
return result;
}
}
public void ClearColumns()
{
((GridView)this.ItemsListView.View).Columns.Clear();
}
public void AddColumn(string header, Binding binding, double width)
{
GridViewColumn column = new GridViewColumn();
column.Width = width;
column.DisplayMemberBinding = binding;
column.Header = header;
((GridView)this.ItemsListView.View).Columns.Add(column);
}
void ItemsListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var handler = ItemActivated;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
}

60
src/AddIns/Debugger/Debugger.AddIn/Pads/LoadedModulesPad.cs

@ -2,24 +2,30 @@ @@ -2,24 +2,30 @@
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Debugger;
using Debugger.AddIn.Pads.Controls;
using Debugger.AddIn.Pads.ParallelPad;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Gui.Pads
{
public class LoadedModulesPad : DebuggerPad
{
SimpleListViewControl loadedModulesList;
ListView loadedModulesList;
Process debuggedProcess;
ObservableCollection<ModuleModel> loadedModules;
protected override void InitializeComponents()
{
loadedModulesList = new SimpleListViewControl();
loadedModulesList = new ListView();
loadedModules = new ObservableCollection<ModuleModel>();
loadedModulesList.ItemsSource = loadedModules;
loadedModulesList.View = new GridView();
panel.Children.Add(loadedModulesList);
RedrawContent();
ResourceService.LanguageChanged += delegate { RedrawContent(); };
@ -66,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -66,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
protected override void RefreshPad()
{
loadedModulesList.ItemCollection.Clear();
loadedModules.Clear();
if (debuggedProcess != null) {
foreach(Module module in debuggedProcess.Modules) {
AddModule(module);
@ -76,31 +82,35 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -76,31 +82,35 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
void AddModule(Module module)
{
dynamic obj = new ExpandoObject();
obj.Tag = module;
RefreshItem(obj);
module.SymbolsUpdated += delegate { RefreshItem(obj); };
loadedModulesList.ItemCollection.Add(obj);
}
void RefreshItem(ExpandoObject obj)
{
dynamic item = obj;
Module module = (Module)item.Tag;
item.Name = module.Name;
item.Address = String.Format("{0:X8}", module.BaseAdress);
item.Path = module.IsDynamic ? "(dynamic)" : module.IsInMemory ? "(in memory)" : module.FullPath;
item.Order = module.OrderOfLoading.ToString();
item.Symbols = StringParser.Parse(module.HasSymbols ? "${res:MainWindow.Windows.Debug.Modules.HasSymbols}" : "${res:MainWindow.Windows.Debug.Modules.HasNoSymbols}");
loadedModules.Add(new ModuleModel(module));
}
void RemoveModule(Module module)
{
foreach (dynamic item in loadedModulesList.ItemCollection) {
if (item.Tag == module) {
loadedModulesList.ItemCollection.Remove(item);
break;
}
loadedModules.RemoveWhere(model => model.Module == module);
}
}
static class ListViewExtensions
{
public static void ClearColumns(this ListView view)
{
if (view == null)
throw new ArgumentNullException("view");
if (view.View is GridView)
((GridView)view.View).Columns.Clear();
}
public static void AddColumn(this ListView view, string header, Binding binding, double width)
{
if (view == null)
throw new ArgumentNullException("view");
if (view.View is GridView) {
GridViewColumn column = new GridViewColumn {
Width = width,
DisplayMemberBinding = binding,
Header = header };
((GridView)view.View).Columns.Add(column);
}
}
}

180
src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ParallelStackFrameModel.cs

@ -0,0 +1,180 @@ @@ -0,0 +1,180 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Widgets;
namespace Debugger.AddIn.Pads.ParallelPad
{
public class ParallelStackFrameModel : ViewModelBase
{
FontWeight fontWeight;
public FontWeight FontWeight {
get { return fontWeight; }
set {
fontWeight = value;
RaisePropertyChanged(() => FontWeight);
}
}
Brush foreground;
public Brush Foreground {
get { return foreground; }
set {
foreground = value;
RaisePropertyChanged(() => Foreground);
}
}
ImageSource image;
public ImageSource Image {
get { return image; }
set {
image = value;
RaisePropertyChanged(() => Image);
}
}
string methodName;
public string MethodName {
get { return methodName; }
set {
methodName = value;
RaisePropertyChanged(() => MethodName);
}
}
bool isRunningStackFrame;
public bool IsRunningStackFrame {
get { return isRunningStackFrame; }
set {
isRunningStackFrame = value;
RaisePropertyChanged(() => IsRunningStackFrame);
}
}
}
public class ThreadModel : ViewModelBase
{
Thread thread;
public ThreadModel(Thread thread)
{
if (thread == null)
throw new ArgumentNullException("thread");
this.thread = thread;
thread.NameChanged += delegate { RaisePropertyChanged(() => Name); };
}
public Thread Thread {
get { return thread; }
}
public uint ID {
get { return thread.ID; }
}
public string Name {
get { return thread.Name; }
}
public string Priority {
get {
switch (thread.Priority) {
case System.Threading.ThreadPriority.Highest:
return ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Highest");
case System.Threading.ThreadPriority.AboveNormal:
return ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.AboveNormal");
case System.Threading.ThreadPriority.Normal:
return ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Normal");
case System.Threading.ThreadPriority.BelowNormal:
return ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.BelowNormal");
case System.Threading.ThreadPriority.Lowest:
return ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Lowest");
default:
return thread.Priority.ToString();
}
}
}
public string Location {
get {
if (thread.Process.IsPaused && thread.MostRecentStackFrame != null)
return thread.MostRecentStackFrame.MethodInfo.Name;
return ResourceService.GetString("Global.NA");
}
}
public string Frozen {
get {
return ResourceService.GetString(thread.Suspended ? "Global.Yes" : "Global.No");
}
}
}
public class ModuleModel : ViewModelBase
{
Module module;
public ModuleModel(Module module)
{
if (module == null)
throw new ArgumentNullException("module");
this.module = module;
this.module.SymbolsUpdated += delegate {
RaisePropertyChanged(() => Name);
RaisePropertyChanged(() => Address);
RaisePropertyChanged(() => Path);
RaisePropertyChanged(() => Order);
RaisePropertyChanged(() => Symbols);
};
}
public Module Module {
get { return module; }
}
public string Name {
get { return module.Name; }
}
public string Address {
get { return string.Format("{0:X8}", module.BaseAdress); }
}
public string Path {
get {
if (module.IsDynamic)
return StringParser.Parse("${res:MainWindow.Windows.Debug.Modules.DynamicModule}");
if (module.IsInMemory)
return StringParser.Parse("${res:MainWindow.Windows.Debug.Modules.InMemoryModule}");
return module.FullPath;
}
}
public string Order {
get {
return module.OrderOfLoading.ToString();
}
}
public string Symbols {
get {
if (module.HasSymbols)
return StringParser.Parse("${res:MainWindow.Windows.Debug.Modules.HasSymbols}");
return StringParser.Parse("${res:MainWindow.Windows.Debug.Modules.HasNoSymbols}");
}
}
}
}

92
src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ParallelStackPad.cs

@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
@ -32,13 +31,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -32,13 +31,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
public class ParallelStackPad : DebuggerPad
{
private DrawSurface surface;
private Process debuggedProcess;
private ParallelStacksGraph graph;
private List<ThreadStack> currentThreadStacks = new List<ThreadStack>();
private ParallelStacksView parallelStacksView;
private StackFrame selectedFrame;
private bool isMethodView;
DrawSurface surface;
Process debuggedProcess;
ParallelStacksGraph graph;
List<ThreadStack> currentThreadStacks = new List<ThreadStack>();
ParallelStacksView parallelStacksView;
StackFrame selectedFrame;
bool isMethodView;
#region Overrides
@ -155,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -155,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
#region Private Methods
private void OnReset(object sender, EventArgs e)
void OnReset(object sender, EventArgs e)
{
currentThreadStacks.Clear();
selectedFrame = null;
@ -164,12 +163,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -164,12 +163,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
BookmarkManager.RemoveAll(b => b is SelectedFrameBookmark);
}
private void OnProcessPaused(object sender, ProcessEventArgs e)
void OnProcessPaused(object sender, ProcessEventArgs e)
{
InvalidatePad();
}
private void AddChildren(ThreadStack parent)
void AddChildren(ThreadStack parent)
{
if(parent.ThreadStackChildren == null || parent.ThreadStackChildren.Count == 0)
return;
@ -188,7 +187,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -188,7 +187,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
}
private void CreateCommonStacks()
void CreateCommonStacks()
{
// stack.ItemCollection order
// 0 -> top of stack = S.C
@ -212,7 +211,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -212,7 +211,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
//get all thread stacks with common start frame
foreach (var stack in currentThreadStacks) {
int count = stack.ItemCollection.Count;
dynamic frame = stack.ItemCollection[count - 1];
ParallelStackFrameModel frame = stack.ItemCollection[count - 1];
string fullname = frame.MethodName + stack.Level.ToString();
if (!commonFrameThreads.ContainsKey(fullname))
@ -247,7 +246,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -247,7 +246,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
canContinue = false;
break;
}
dynamic item = stack.ItemCollection[stack.ItemCollection.Count - frameIndex - 1];
ParallelStackFrameModel item = stack.ItemCollection[stack.ItemCollection.Count - frameIndex - 1];
string currentName = item.MethodName;
@ -269,7 +269,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -269,7 +269,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
// remove last [frameIndex] and create a new ThreadStack as the parent of what remained in the children
var threadIds = new List<uint>();
var parentItems = new Stack<ExpandoObject>();
var parentItems = new Stack<ParallelStackFrameModel>();
while (frameIndex > 0) {
for (int i = 0 ; i < listOfCurrentStacks.Count; ++i) {
@ -277,7 +277,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -277,7 +277,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
int indexToRemove = stack.ItemCollection.Count - 1;
#if DEBUG
dynamic d_item = stack.ItemCollection[indexToRemove];
ParallelStackFrameModel d_item = stack.ItemCollection[indexToRemove];
string name = d_item.MethodName;
#endif
if (i == 0)
@ -319,7 +319,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -319,7 +319,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
currentThreadStacks.Remove(stack);
continue;
}
dynamic item = stack.ItemCollection[stack.ItemCollection.Count - 1];
ParallelStackFrameModel item = stack.ItemCollection[stack.ItemCollection.Count - 1];
// add the parent to the parent
if (stack.ThreadStackParents != null) {
// remove stack from it's parent because it will have the commonParent as parent
@ -369,10 +369,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -369,10 +369,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
}
private void CreateMethodViewStacks()
void CreateMethodViewStacks()
{
var list =
new List<Tuple<ObservableCollection<ExpandoObject>, ObservableCollection<ExpandoObject>, List<uint>>>();
var list = new List<Tuple<ObservableCollection<ParallelStackFrameModel>, ObservableCollection<ParallelStackFrameModel>, List<uint>>>();
// find all threadstacks that contains the selected frame
for (int i = currentThreadStacks.Count - 1; i >= 0; --i) {
@ -385,9 +384,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -385,9 +384,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
// common
ThreadStack common = new ThreadStack();
var observ = new ObservableCollection<ExpandoObject>();
var observ = new ObservableCollection<ParallelStackFrameModel>();
bool dummy = false;
dynamic obj = CreateItemForFrame(selectedFrame, ref dummy);
ParallelStackFrameModel obj = CreateItemForFrame(selectedFrame, ref dummy);
obj.Image = PresentationResourceService.GetImage("Icons.48x48.CurrentFrame").Source;
observ.Add(obj);
common.ItemCollection = observ;
@ -438,7 +437,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -438,7 +437,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
common.IsSelected = true;
}
private void CreateThreadStack(Thread thread)
void CreateThreadStack(Thread thread)
{
var items = CreateItems(thread);
if (items == null || items.Count == 0)
@ -460,16 +459,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -460,16 +459,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
currentThreadStacks.Add(threadStack);
}
private ObservableCollection<ExpandoObject> CreateItems(Thread thread)
ObservableCollection<ParallelStackFrameModel> CreateItems(Thread thread)
{
bool lastItemIsExternalMethod = false;
int noTasks = 0;
var result = new ObservableCollection<ExpandoObject>();
var result = new ObservableCollection<ParallelStackFrameModel>();
var callstack = thread.GetCallstack(100);
if (parallelStacksView == ParallelStacksView.Threads) {
foreach (StackFrame frame in callstack) {
dynamic obj = CreateItemForFrame(frame, ref lastItemIsExternalMethod);
ParallelStackFrameModel obj = CreateItemForFrame(frame, ref lastItemIsExternalMethod);
if (obj != null)
result.Add(obj);
@ -477,7 +476,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -477,7 +476,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
} else {
for (int i = 0 ; i < callstack.Length; ++i) {
StackFrame frame = callstack[i];
dynamic obj = CreateItemForFrame(frame, ref lastItemIsExternalMethod);
ParallelStackFrameModel obj = CreateItemForFrame(frame, ref lastItemIsExternalMethod);
if (frame.MethodInfo.FullName.IndexOf("System.Threading.Tasks.Task.ExecuteEntry") != -1) {
noTasks++;
@ -519,22 +518,22 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -519,22 +518,22 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
return result;
}
private ExpandoObject CreateItemForFrame(StackFrame frame, ref bool lastItemIsExternalMethod)
ParallelStackFrameModel CreateItemForFrame(StackFrame frame, ref bool lastItemIsExternalMethod)
{
dynamic obj = new ExpandoObject();
ParallelStackFrameModel model = new ParallelStackFrameModel();
string fullName;
if (frame.HasSymbols) {
// Show the method in the list
fullName = frame.GetMethodName();
lastItemIsExternalMethod = false;
obj.FontWeight = FontWeights.Normal;
obj.Foreground = Brushes.Black;
model.FontWeight = FontWeights.Normal;
model.Foreground = Brushes.Black;
} else {
// Show [External methods] in the list
if (lastItemIsExternalMethod) return null;
fullName = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods").Trim();
obj.FontWeight = FontWeights.Normal;
obj.Foreground = Brushes.Gray;
model.FontWeight = FontWeights.Normal;
model.Foreground = Brushes.Gray;
lastItemIsExternalMethod = true;
}
@ -542,23 +541,23 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -542,23 +541,23 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
frame.Thread.ID == debuggedProcess.SelectedThread.ID &&
frame.Thread.SelectedStackFrame.IP == frame.IP &&
frame.Thread.SelectedStackFrame.GetMethodName() == frame.GetMethodName()) {
obj.Image = PresentationResourceService.GetImage("Bookmarks.CurrentLine").Source;
obj.IsRunningStackFrame = true;
model.Image = PresentationResourceService.GetImage("Bookmarks.CurrentLine").Source;
model.IsRunningStackFrame = true;
} else {
if (selectedFrame != null && frame.Thread.ID == selectedFrame.Thread.ID &&
frame.GetMethodName() == selectedFrame.GetMethodName())
obj.Image = PresentationResourceService.GetImage("Icons.48x48.CurrentFrame").Source;
model.Image = PresentationResourceService.GetImage("Icons.48x48.CurrentFrame").Source;
else
obj.Image = null;
obj.IsRunningStackFrame = false;
model.Image = null;
model.IsRunningStackFrame = false;
}
obj.MethodName = fullName;
model.MethodName = fullName;
return obj;
return model;
}
private void ToggleSelectedFrameBookmark(Location location)
void ToggleSelectedFrameBookmark(Location location)
{
// remove all
BookmarkManager.RemoveAll(b => b is SelectedFrameBookmark);
@ -570,7 +569,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -570,7 +569,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
}
private void OnThreadStackSelected(object sender, EventArgs e)
void OnThreadStackSelected(object sender, EventArgs e)
{
foreach (var ts in this.currentThreadStacks) {
if (ts.IsSelected)
@ -579,7 +578,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -579,7 +578,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
}
private void OnFrameSelected(object sender, FrameSelectedEventArgs e)
void OnFrameSelected(object sender, FrameSelectedEventArgs e)
{
selectedFrame = e.Item;
@ -592,7 +591,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -592,7 +591,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
#endregion
}
internal static class StackFrameExtensions
static class StackFrameExtensions
{
internal static string GetMethodName(this StackFrame frame)
{
@ -608,7 +607,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -608,7 +607,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
}
internal static class ParallelStackExtensions
static class ParallelStackExtensions
{
internal static List<T> Clone<T>(this List<T> listToClone)
{
@ -654,8 +653,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -654,8 +653,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
int found = 0;
foreach (dynamic item in source)
{
foreach (dynamic item in source) {
if (item.MethodName == frame.GetMethodName())
found = 1;

45
src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ThreadStack.xaml.cs

@ -48,10 +48,10 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -48,10 +48,10 @@ namespace Debugger.AddIn.Pads.ParallelPad
public event EventHandler<FrameSelectedEventArgs> FrameSelected;
private ObservableCollection<ExpandoObject> itemCollection = new ObservableCollection<ExpandoObject>();
ObservableCollection<ParallelStackFrameModel> itemCollection = new ObservableCollection<ParallelStackFrameModel>();
private ToolTip toolTip = new ToolTip();
private List<uint> threadIds = new List<uint>();
ToolTip toolTip = new ToolTip();
List<uint> threadIds = new List<uint>();
public ThreadStack()
{
@ -91,16 +91,11 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -91,16 +91,11 @@ namespace Debugger.AddIn.Pads.ParallelPad
public List<ThreadStack> ThreadStackChildren { get; set; }
public List<uint> ThreadIds {
get {
return threadIds;
}
get { return threadIds; }
}
public ObservableCollection<ExpandoObject> ItemCollection {
get {
return itemCollection;
}
public ObservableCollection<ParallelStackFrameModel> ItemCollection {
get { return itemCollection; }
set {
itemCollection = value;
this.datagrid.ItemsSource = itemCollection;
@ -132,7 +127,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -132,7 +127,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
public void ClearImages()
{
foreach(dynamic item in itemCollection) {
foreach (ParallelStackFrameModel item in itemCollection) {
if (!item.IsRunningStackFrame)
item.Image = null;
}
@ -170,7 +165,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -170,7 +165,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
{
if (Process.IsRunning) return;
dynamic selectedItem = datagrid.SelectedItem;
ParallelStackFrameModel selectedItem = datagrid.SelectedItem as ParallelStackFrameModel;
if (selectedItem != null) {
if (ThreadIds.Count > 1) {
datagrid.ContextMenu = CreateContextMenu(selectedItem);
@ -183,7 +178,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -183,7 +178,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
}
}
private void SelectFrame(uint threadId, ExpandoObject selectedItem)
private void SelectFrame(uint threadId, ParallelStackFrameModel selectedItem)
{
if (selectedItem == null)
return;
@ -197,14 +192,12 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -197,14 +192,12 @@ namespace Debugger.AddIn.Pads.ParallelPad
this.IsSelected = true;
dynamic obj = selectedItem;
foreach(var frame in thread.Callstack)
{
if (frame.GetMethodName() == obj.MethodName)
if (frame.GetMethodName() == selectedItem.MethodName)
{
if (!obj.IsRunningStackFrame)
obj.Image = PresentationResourceService.GetImage("Icons.48x48.CurrentFrame").Source;
if (!selectedItem.IsRunningStackFrame)
selectedItem.Image = PresentationResourceService.GetImage("Icons.48x48.CurrentFrame").Source;
SourcecodeSegment nextStatement = frame.NextStatement;
if (nextStatement != null) {
@ -225,7 +218,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -225,7 +218,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
{
if (Process.IsRunning) return;
dynamic selectedItem = datagrid.SelectedItem;
ParallelStackFrameModel selectedItem = datagrid.SelectedItem as ParallelStackFrameModel;
if (selectedItem == null)
return;
@ -233,13 +226,11 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -233,13 +226,11 @@ namespace Debugger.AddIn.Pads.ParallelPad
datagrid.ContextMenu.IsOpen = true;
}
private ContextMenu CreateContextMenu(ExpandoObject item)
ContextMenu CreateContextMenu(ParallelStackFrameModel item)
{
dynamic obj = item;
var menu = new ContextMenu();
foreach (var id in ThreadIds)
{
foreach (var id in ThreadIds) {
MenuItem m = new MenuItem();
m.IsCheckable = true;
m.IsChecked = id == Process.SelectedThread.ID;
@ -248,7 +239,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -248,7 +239,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
SelectFrame((uint)menuItem.Tag, item);
};
m.Tag = id;
m.Header = id.ToString() + ":" + obj.MethodName;
m.Header = id.ToString() + ":" + item.MethodName;
menu.Items.Add(m);
}
@ -263,7 +254,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -263,7 +254,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
StackPanel panel = new StackPanel();
dynamic selectedItem = datagrid.SelectedItem;
ParallelStackFrameModel selectedItem = datagrid.SelectedItem as ParallelStackFrameModel;
if (selectedItem == null) {
panel.Children.Add(new TextBlock { Text = "No item selected" });
this.toolTip.Content = panel;

15
src/AddIns/Debugger/Debugger.AddIn/Pads/RunningThreadsPad.Menu.cs

@ -3,10 +3,11 @@ @@ -3,10 +3,11 @@
using System.Collections;
using System.Dynamic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Debugger;
using Debugger.AddIn.Pads.ParallelPad;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Gui.Pads
@ -28,7 +29,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -28,7 +29,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
return;
}
dynamic item = items[0];
ThreadModel item = items[0] as ThreadModel;
if (item == null)
return;
ContextMenu menu = sender as ContextMenu;
menu.Items.Clear();
@ -36,22 +39,22 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -36,22 +39,22 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
MenuItem freezeItem;
freezeItem = new MenuItem();
freezeItem.Header = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Freeze");
freezeItem.IsChecked = (item.Tag as Thread).Suspended;
freezeItem.IsChecked = item.Thread.Suspended;
freezeItem.Click +=
delegate {
if (items == null || items.Count == 0) {
e.Handled = true;
return;
}
bool suspended = (item.Tag as Thread).Suspended;
bool suspended = item.Thread.Suspended;
if (!debuggedProcess.IsPaused) {
MessageService.ShowMessage("${res:MainWindow.Windows.Debug.Threads.CannotFreezeWhileRunning}", "${res:MainWindow.Windows.Debug.Threads.Freeze}");
return;
}
foreach(dynamic current in items) {
(current.Tag as Thread).Suspended = !suspended;
foreach(ThreadModel current in items.OfType<ThreadModel>()) {
current.Thread.Suspended = !suspended;
}
InvalidatePad();
};

85
src/AddIns/Debugger/Debugger.AddIn/Pads/RunningThreadsPad.cs

@ -2,12 +2,13 @@ @@ -2,12 +2,13 @@
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Dynamic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Debugger;
using Debugger.AddIn.Pads.Controls;
using Debugger.AddIn.Pads.ParallelPad;
using Debugger.AddIn.TreeModel;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
@ -19,14 +20,18 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -19,14 +20,18 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
{
public partial class RunningThreadsPad : DebuggerPad
{
SimpleListViewControl runningThreadsList;
ListView runningThreadsList;
ObservableCollection<ThreadModel> runningThreads;
Process debuggedProcess;
protected override void InitializeComponents()
{
runningThreadsList = new SimpleListViewControl();
runningThreads = new ObservableCollection<ThreadModel>();
runningThreadsList = new ListView();
runningThreadsList.ContextMenu = CreateContextMenuStrip();
runningThreadsList.ItemActivated += RunningThreadsListItemActivate;
runningThreadsList.MouseDoubleClick += RunningThreadsListItemActivate;
runningThreadsList.ItemsSource = runningThreads;
runningThreadsList.View = new GridView();
panel.Children.Add(runningThreadsList);
RedrawContent();
@ -64,7 +69,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -64,7 +69,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
debuggedProcess.Paused += debuggedProcess_Paused;
debuggedProcess.Threads.Added += debuggedProcess_ThreadStarted;
}
runningThreadsList.ItemCollection.Clear();
runningThreads.Clear();
InvalidatePad();
}
@ -81,7 +86,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -81,7 +86,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
protected override void RefreshPad()
{
if (debuggedProcess == null || debuggedProcess.IsRunning) {
runningThreadsList.ItemCollection.Clear();
runningThreads.Clear();
return;
}
@ -106,8 +111,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -106,8 +111,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
{
if (debuggedProcess.IsPaused) {
if (debuggedProcess != null) {
dynamic obj = runningThreadsList.SelectedItems[0];
Thread thread = (Thread)(obj.Tag);
ThreadModel obj = runningThreadsList.SelectedItems[0] as ThreadModel;
Thread thread = obj.Thread;
// check for options - if these options are enabled, selecting the frame should not continue
if ((thread.MostRecentStackFrame == null || !thread.MostRecentStackFrame.HasSymbols) &&
@ -138,59 +143,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -138,59 +143,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
// remove the object if exists
RemoveThread(thread);
dynamic obj = new ExpandoObject();
obj.Tag = thread;
RefreshItem(obj);
runningThreadsList.ItemCollection.Add(obj);
thread.NameChanged += delegate {
RefreshItem(obj);
};
thread.Exited += (s, e) => RemoveThread(e.Thread);
}
void RefreshItem(ExpandoObject obj)
{
dynamic item = obj;
if (item == null) return;
var thread = item.Tag as Thread;
if (thread == null)
return;
ThreadModel obj = new ThreadModel(thread);
item.ID = thread.ID;
item.Tag = thread;
StackFrame location = null;
if (thread.Process.IsPaused) {
location = thread.MostRecentStackFrame;
}
if (location != null) {
item.Location = location.MethodInfo.Name;
} else {
item.Location = ResourceService.GetString("Global.NA");
}
switch (thread.Priority) {
case System.Threading.ThreadPriority.Highest:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Highest");
break;
case System.Threading.ThreadPriority.AboveNormal:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.AboveNormal");
break;
case System.Threading.ThreadPriority.Normal:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Normal");
break;
case System.Threading.ThreadPriority.BelowNormal:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.BelowNormal");
break;
case System.Threading.ThreadPriority.Lowest:
item.Priority = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Priority.Lowest");
break;
default:
item.Priority = thread.Priority.ToString();
break;
}
item.Frozen = ResourceService.GetString(thread.Suspended ? "Global.Yes" : "Global.No");
runningThreads.Add(obj);
thread.Exited += (s, e) => RemoveThread(e.Thread);
}
void RemoveThread(Thread thread)
@ -198,12 +154,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -198,12 +154,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
if (thread == null)
return;
foreach (dynamic item in runningThreadsList.ItemCollection) {
if (thread.ID == item.ID) {
runningThreadsList.ItemCollection.Remove(item);
break;
}
}
runningThreads.RemoveWhere(model => model.Thread == thread);
}
}
}

8
src/AddIns/Debugger/Debugger.AddIn/Visualizers/PresentationBindings/EnumViewModel.cs

@ -3,11 +3,13 @@ @@ -3,11 +3,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;
using System.Reflection;
using ICSharpCode.SharpDevelop.Widgets;
namespace Debugger.AddIn.Visualizers
{
@ -65,7 +67,7 @@ namespace Debugger.AddIn.Visualizers @@ -65,7 +67,7 @@ namespace Debugger.AddIn.Visualizers
{
if (_enumValue.Equals(value)) return;
_enumValue = value;
OnPropertyChanged("SelectedEnumValue");
RaisePropertyChanged(() => SelectedEnumValue);
}
}
}

6
src/AddIns/Debugger/Debugger.AddIn/Visualizers/PresentationBindings/GridViewColumnHider.cs

@ -1,12 +1,14 @@ @@ -1,12 +1,14 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using Debugger.AddIn.Visualizers.PresentationBindings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using Debugger.AddIn.Visualizers.PresentationBindings;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Widgets;
namespace Debugger.AddIn.Visualizers
{
@ -26,7 +28,7 @@ namespace Debugger.AddIn.Visualizers @@ -26,7 +28,7 @@ namespace Debugger.AddIn.Visualizers
set {
if (isVisible != value) {
isVisible = value;
OnPropertyChanged("IsVisible");
RaisePropertyChanged(() => IsVisible);
ExtensionMethods.RaiseEvent(IsVisibleChanged, this, EventArgs.Empty);
}
}

23
src/AddIns/Debugger/Debugger.AddIn/Visualizers/PresentationBindings/ViewModelBase.cs

@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ICSharpCode.SharpDevelop;
namespace Debugger.AddIn.Visualizers
{
public class ViewModelBase : INotifyPropertyChanged
{
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}

13
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -499,6 +499,19 @@ namespace ICSharpCode.SharpDevelop @@ -499,6 +499,19 @@ namespace ICSharpCode.SharpDevelop
list.Add(itemToAdd);
}
public static void RemoveWhere<T>(this IList<T> list, Predicate<T> condition)
{
if (list == null)
throw new ArgumentNullException("list");
int i = 0;
while (i < list.Count) {
if (condition(list[i]))
list.RemoveAt(i);
else
i++;
}
}
public static ExpressionResult FindFullExpressionAtCaret(this ITextEditor editor)
{
if (editor == null)

93
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ViewModelBase.cs

@ -1,11 +1,6 @@ @@ -1,11 +1,6 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 16.10.2011
* Time: 19:35
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel;
using System.Linq.Expressions;
@ -25,55 +20,55 @@ namespace ICSharpCode.SharpDevelop.Widgets @@ -25,55 +20,55 @@ namespace ICSharpCode.SharpDevelop.Widgets
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
protected virtual void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpresssion)
{
var propertyName = ExtractPropertyName(propertyExpresssion);
this.RaisePropertyChanged(propertyName);
}
{
var propertyName = ExtractPropertyName(propertyExpresssion);
this.RaisePropertyChanged(propertyName);
}
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
private static String ExtractPropertyName<T>(Expression<Func<T>> propertyExpresssion)
{
if (propertyExpresssion == null)
{
throw new ArgumentNullException("propertyExpresssion");
}
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
private static String ExtractPropertyName<T>(Expression<Func<T>> propertyExpresssion)
{
if (propertyExpresssion == null)
{
throw new ArgumentNullException("propertyExpresssion");
}
var memberExpression = propertyExpresssion.Body as MemberExpression;
if (memberExpression == null)
{
throw new ArgumentException("The expression is not a member access expression.", "propertyExpresssion");
}
var memberExpression = propertyExpresssion.Body as MemberExpression;
if (memberExpression == null)
{
throw new ArgumentException("The expression is not a member access expression.", "propertyExpresssion");
}
var property = memberExpression.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException("The member access expression does not access a property.", "propertyExpresssion");
}
var property = memberExpression.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException("The member access expression does not access a property.", "propertyExpresssion");
}
var getMethod = property.GetGetMethod(true);
if (getMethod.IsStatic)
{
throw new ArgumentException("The referenced property is a static property.", "propertyExpresssion");
}
var getMethod = property.GetGetMethod(true);
if (getMethod.IsStatic)
{
throw new ArgumentException("The referenced property is a static property.", "propertyExpresssion");
}
return memberExpression.Member.Name;
}
return memberExpression.Member.Name;
}
}
}

Loading…
Cancel
Save