Browse Source

reimplement WatchPad

pull/59/merge
Siegfried Pammer 13 years ago
parent
commit
f2c8cd5bed
  1. 25
      src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs
  2. 28
      src/AddIns/Debugger/Debugger.AddIn/Pads/CommonResources.xaml
  3. 85
      src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPad.cs
  4. 6
      src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPadCommands.cs
  5. 2
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/Utils.cs
  6. 20
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/ValueNode.cs

25
src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs

@ -28,7 +28,7 @@ namespace Debugger.AddIn.Pads.Controls
public static readonly DependencyProperty IsEditableProperty = public static readonly DependencyProperty IsEditableProperty =
DependencyProperty.Register("IsEditable", typeof(bool), typeof(AutoCompleteTextBox), DependencyProperty.Register("IsEditable", typeof(bool), typeof(AutoCompleteTextBox),
new FrameworkPropertyMetadata(true, IsEditableChanged)); new FrameworkPropertyMetadata(true, IsEditableChanged));
public string Text { public string Text {
get { return (string)GetValue(TextProperty); } get { return (string)GetValue(TextProperty); }
@ -65,16 +65,21 @@ namespace Debugger.AddIn.Pads.Controls
this.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden; this.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
this.editor.TextArea.GotKeyboardFocus += delegate { this.editor.TextArea.GotKeyboardFocus += delegate {
this.Background = Brushes.White; this.Background = Brushes.White;
this.Foreground = Brushes.Black;
}; };
this.editor.TextArea.LostKeyboardFocus += delegate { this.editor.TextArea.LostKeyboardFocus += delegate {
this.Background = Brushes.Transparent; this.Background = Brushes.Transparent;
this.ClearValue(ForegroundProperty);
this.Text = this.editor.Text; this.Text = this.editor.Text;
this.editor.Select(0, 0); this.editorAdapter.ClearSelection();
}; };
this.editor.TextArea.PreviewKeyDown += editor_TextArea_PreviewKeyDown; this.editor.TextArea.PreviewKeyDown += editor_TextArea_PreviewKeyDown;
this.editor.TextArea.TextEntered += editor_TextArea_TextEntered; this.editor.TextArea.TextEntered += editor_TextArea_TextEntered;
this.Content = this.editor.TextArea; this.Content = this.editor.TextArea;
HorizontalContentAlignment = HorizontalAlignment.Stretch;
VerticalContentAlignment = VerticalAlignment.Stretch;
} }
void editor_TextArea_PreviewKeyDown(object sender, KeyEventArgs e) void editor_TextArea_PreviewKeyDown(object sender, KeyEventArgs e)
@ -99,22 +104,22 @@ namespace Debugger.AddIn.Pads.Controls
string language = ProjectService.CurrentProject == null ? "C#" : ProjectService.CurrentProject.Language; string language = ProjectService.CurrentProject == null ? "C#" : ProjectService.CurrentProject.Language;
#warning reimplement this! #warning reimplement this!
// NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.GetLanguage(language)); // NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.GetLanguage(language));
// //
// var seg = frame.NextStatement; // var seg = frame.NextStatement;
// //
// var expressionFinder = ParserService.GetExpressionFinder(seg.Filename); // var expressionFinder = ParserService.GetExpressionFinder(seg.Filename);
// var info = ParserService.GetParseInformation(seg.Filename); // var info = ParserService.GetParseInformation(seg.Filename);
// //
// string text = ParserService.GetParseableFileContent(seg.Filename).Text; // string text = ParserService.GetParseableFileContent(seg.Filename).Text;
// //
// int currentOffset = this.editor.CaretOffset; // int currentOffset = this.editor.CaretOffset;
// //
// var expr = expressionFinder.FindExpression(currentText, currentOffset); // var expr = expressionFinder.FindExpression(currentText, currentOffset);
// //
// expr.Region = new DomRegion(seg.StartLine, seg.StartColumn, seg.EndLine, seg.EndColumn); // expr.Region = new DomRegion(seg.StartLine, seg.StartColumn, seg.EndLine, seg.EndColumn);
// //
// var rr = resolver.Resolve(expr, info, text); // var rr = resolver.Resolve(expr, info, text);
// //
// if (rr != null) { // if (rr != null) {
// editorAdapter.ShowCompletionWindow(new DotCodeCompletionItemProvider().GenerateCompletionListForResolveResult(rr, expr.Context)); // editorAdapter.ShowCompletionWindow(new DotCodeCompletionItemProvider().GenerateCompletionListForResolveResult(rr, expr.Context));
// } // }

28
src/AddIns/Debugger/Debugger.AddIn/Pads/CommonResources.xaml

@ -5,7 +5,7 @@
xmlns:local="clr-namespace:Debugger.AddIn.Pads.Controls" xmlns:local="clr-namespace:Debugger.AddIn.Pads.Controls"
xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:tv="http://icsharpcode.net/sharpdevelop/treeview" xmlns:tv="http://icsharpcode.net/sharpdevelop/treeview"
> >
<Style x:Key="itemContainerStyle" TargetType="{x:Type ListViewItem}"> <Style x:Key="itemContainerStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
@ -14,13 +14,13 @@
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}"> <ControlTemplate TargetType="{x:Type ListViewItem}">
<Border Name="Bd" <Border Name="Bd"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}" Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true"> SnapsToDevicePixels="true">
<GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false"> <Trigger Property="IsEnabled" Value="false">
@ -40,7 +40,7 @@
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<tv:SharpTreeNodeView/> <tv:SharpTreeNodeView/>
<local:AutoCompleteTextBox Margin="-6 0 0 0" Text="{Binding Node.Name}" IsEditable="{Binding Node.CanSetName}"/> <local:AutoCompleteTextBox Margin="-6 0 0 0" MinWidth="100" Text="{Binding Node.Name}" IsEditable="{Binding Node.CanSetName}"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
@ -48,14 +48,14 @@
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.LocalVariables.ValueColumn}" Width="200"> <GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.LocalVariables.ValueColumn}" Width="200">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<local:AutoCompleteTextBox Text="{Binding Node.Value}" IsEditable="{Binding Node.CanSetValue}"/> <local:AutoCompleteTextBox MinWidth="100" Text="{Binding Node.Value}" IsEditable="{Binding Node.CanSetValue}"/>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.LocalVariables.TypeColumn}" Width="200"> <GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.LocalVariables.TypeColumn}" Width="200">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<local:AutoCompleteTextBox Text="{Binding Node.Type}" IsEditable="False"/> <local:AutoCompleteTextBox MinWidth="100" Text="{Binding Node.Type}" IsEditable="False"/>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
@ -78,14 +78,14 @@
<!-- Breakpoints Pad --> <!-- Breakpoints Pad -->
<GridView x:Key="breakpointsGridView" AllowsColumnReorder="False"> <GridView x:Key="breakpointsGridView" AllowsColumnReorder="False">
<GridViewColumn Header="" Width="Auto"> <GridViewColumn Header="">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<CheckBox IsChecked="{Binding Path=IsEnabled, Mode=TwoWay}" /> <CheckBox IsChecked="{Binding Path=IsEnabled, Mode=TwoWay}" />
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
<GridViewColumn Header="{core:Localize MainWindow.Windows.BookmarkPad.LocationText}" Width="Auto"> <GridViewColumn Header="{core:Localize MainWindow.Windows.BookmarkPad.LocationText}">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
@ -95,7 +95,7 @@
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.Conditional.Breakpoints.ConditionalColumnHeader}" Width="Auto"> <GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.Conditional.Breakpoints.ConditionalColumnHeader}">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<local:AutoCompleteTextBox Text="{Binding Condition}" MinWidth="100" /> <local:AutoCompleteTextBox Text="{Binding Condition}" MinWidth="100" />
@ -120,5 +120,5 @@
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.Threads.Priority}" Width="120" DisplayMemberBinding="{Binding Priority}"/> <GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.Threads.Priority}" Width="120" DisplayMemberBinding="{Binding Priority}"/>
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.Threads.Frozen}" Width="80" DisplayMemberBinding="{Binding Frozen}"/> <GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.Threads.Frozen}" Width="80" DisplayMemberBinding="{Binding Frozen}"/>
</GridView> </GridView>
</ResourceDictionary> </ResourceDictionary>

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

@ -3,7 +3,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading; using System.Windows.Threading;
@ -14,7 +13,6 @@ using Debugger.AddIn.Pads.Controls;
using Debugger.AddIn.TreeModel; using Debugger.AddIn.TreeModel;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.Core.Presentation; using ICSharpCode.Core.Presentation;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Services; using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.SharpDevelop.Workbench; using ICSharpCode.SharpDevelop.Workbench;
@ -43,45 +41,52 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
var res = new CommonResources(); var res = new CommonResources();
res.InitializeComponent(); res.InitializeComponent();
this.tree = new SharpTreeView(); tree = new SharpTreeView();
this.tree.Root = new SharpTreeNode(); tree.Root = new SharpTreeNode();
this.tree.ShowRoot = false; tree.ShowRoot = false;
this.tree.View = (GridView)res["variableGridView"]; tree.View = (GridView)res["variableGridView"];
this.tree.ContextMenu = MenuService.CreateContextMenu(this, "/SharpDevelop/Pads/WatchPad/ContextMenu"); tree.SetValue(GridViewColumnAutoSize.AutoWidthProperty, "50%;25%;25%");
this.tree.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) { tree.ContextMenu = MenuService.CreateContextMenu(this, "/SharpDevelop/Pads/WatchPad/ContextMenu");
tree.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) {
if (this.tree.SelectedItem == null) { if (this.tree.SelectedItem == null) {
AddWatchCommand cmd = new AddWatchCommand { Owner = this }; AddWatchCommand cmd = new AddWatchCommand { Owner = this };
cmd.Run(); cmd.Run();
} }
}; };
ProjectService.SolutionLoaded += delegate { LoadNodes(); }; // ProjectService.SolutionLoaded += delegate { LoadNodes(); };
ProjectService.SolutionClosing += delegate { SaveNodes(); }; // ProjectService.SolutionClosing += delegate { SaveNodes(); };
LoadNodes(); // LoadNodes();
WindowsDebugger.RefreshingPads += RefreshPad; WindowsDebugger.RefreshingPads += RefreshPad;
RefreshPad(); RefreshPad();
} }
void LoadNodes() // void LoadNodes()
{ // {
if (ProjectService.OpenSolution != null) { // if (ProjectService.OpenSolution != null) {
var props = ProjectService.OpenSolution.Preferences.NestedProperties("Watches"); // var props = ProjectService.OpenSolution.Preferences.NestedProperties("Watches");
foreach (var key in props.Keys) { // foreach (var key in props.Keys) {
this.Items.Add(new TreeNode(props.Get(key, ""), () => null).ToSharpTreeNode()); // this.Items.Add(new TreeNode(props.Get(key, ""), () => null).ToSharpTreeNode());
} // }
} // }
} // }
//
void SaveNodes() // void SaveNodes()
// {
// if (ProjectService.OpenSolution != null) {
// var props = new Properties();
// ProjectService.OpenSolution.Preferences.SetNestedProperties("Watches", props);
// foreach(var node in this.Items.OfType<TreeNode>()) {
// props.Set(node.Name, node.EvalEnabled);
// }
// }
// }
public void AddWatch(string expression = null)
{ {
if (ProjectService.OpenSolution != null) { var node = MakeNode(expression);
var props = new Properties(); this.Items.Add(node);
ProjectService.OpenSolution.Preferences.SetNestedProperties("Watches", props);
foreach(var node in this.Items.OfType<TreeNode>()) {
props.Set(node.Name, (object)null);
}
}
} }
SharpTreeNodeAdapter MakeNode(string name) SharpTreeNodeAdapter MakeNode(string name)
@ -89,13 +94,21 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
LoggingService.Info("Evaluating watch: " + name); LoggingService.Info("Evaluating watch: " + name);
TreeNode node = null; TreeNode node = null;
try { try {
node = new ValueNode(null, name, () => WindowsDebugger.Evaluate(name)); node = new ValueNode(null, name,
() => {
if (string.IsNullOrWhiteSpace(name))
return null;
return WindowsDebugger.Evaluate(name);
});
} catch (GetValueException e) { } catch (GetValueException e) {
node = new TreeNode(SD.ResourceService.GetImage("Icons.16x16.Error"), name, e.Message, string.Empty, null); node = new TreeNode(null, name, e.Message, string.Empty, null);
} }
node.CanDelete = true; node.CanDelete = true;
node.CanSetName = true; node.CanSetName = true;
node.PropertyChanged += (s, e) => { if (e.PropertyName == "Name") WindowsDebugger.RefreshPads(); }; node.PropertyChanged += (s, e) => {
if (e.PropertyName == "Name")
WindowsDebugger.RefreshPads();
};
return node.ToSharpTreeNode(); return node.ToSharpTreeNode();
} }
@ -103,12 +116,14 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
{ {
Process process = WindowsDebugger.CurrentProcess; Process process = WindowsDebugger.CurrentProcess;
if (process != null) { if (process != null) {
var names = this.Items.OfType<SharpTreeNodeAdapter>().Select(n => n.Node.Name).ToList(); var expressions = this.Items.OfType<SharpTreeNodeAdapter>()
.Select(n => n.Node.Name)
.ToList();
this.Items.Clear(); this.Items.Clear();
process.EnqueueForEach( process.EnqueueForEach(
Dispatcher.CurrentDispatcher, Dispatcher.CurrentDispatcher,
names, expressions,
name => this.Items.Add(MakeNode(name)) expr => this.Items.Add(MakeNode(expr))
); );
} }
} }

6
src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPadCommands.cs

@ -20,11 +20,7 @@ namespace Debugger.AddIn
{ {
if (this.Owner is WatchPad) { if (this.Owner is WatchPad) {
WatchPad pad = (WatchPad)this.Owner; WatchPad pad = (WatchPad)this.Owner;
var node = new TreeNode(string.Empty, null); pad.AddWatch();
node.CanSetName = true;
var sharpNode = node.ToSharpTreeNode();
pad.Items.Add(sharpNode);
pad.Tree.FocusNode(sharpNode);
} }
} }
} }

2
src/AddIns/Debugger/Debugger.AddIn/TreeModel/Utils.cs

@ -76,7 +76,7 @@ namespace Debugger.AddIn.TreeModel
if (watch.ElapsedMilliseconds > 100) { if (watch.ElapsedMilliseconds > 100) {
dispatcher.BeginInvoke( dispatcher.BeginInvoke(
DispatcherPriority.Background, DispatcherPriority.Background,
(Action)delegate { ProcessItems(process, dispatcher, index, items, work, debuggeeStateWhenEnqueued); } (Action)delegate { ProcessItems(process, dispatcher, index + 1, items, work, debuggeeStateWhenEnqueued); }
); );
break; break;
} }

20
src/AddIns/Debugger/Debugger.AddIn/TreeModel/ValueNode.cs

@ -107,6 +107,14 @@ namespace Debugger.AddIn.TreeModel
// Do not keep permanent reference // Do not keep permanent reference
Value val = this.getValue(); Value val = this.getValue();
if (val == null) {
Value = string.Empty;
Type = string.Empty;
GetChildren = null;
VisualizerCommands = null;
return;
}
// Note that the child collections are lazy-evaluated // Note that the child collections are lazy-evaluated
if (val.IsNull) { if (val.IsNull) {
this.GetChildren = null; this.GetChildren = null;
@ -187,12 +195,12 @@ namespace Debugger.AddIn.TreeModel
this.Type = string.Empty; this.Type = string.Empty;
this.GetChildren = null; this.GetChildren = null;
this.VisualizerCommands = null; this.VisualizerCommands = null;
} finally {
if (error == null)
ContextMenuAddInTreeEntry = "/AddIns/Debugger/Tooltips/ContextMenu/ValueNode";
else
ContextMenuAddInTreeEntry = "/AddIns/Debugger/Tooltips/ContextMenu/ErrorNode";
} }
if (error == null)
ContextMenuAddInTreeEntry = "/AddIns/Debugger/Tooltips/ContextMenu/ValueNode";
else
ContextMenuAddInTreeEntry = "/AddIns/Debugger/Tooltips/ContextMenu/ErrorNode";
} }
/// <summary> /// <summary>
@ -231,7 +239,7 @@ namespace Debugger.AddIn.TreeModel
foreach(LocalVariable locVar in localVars) { foreach(LocalVariable locVar in localVars) {
var locVarCopy = locVar; var locVarCopy = locVar;
yield return new ValueNode(ClassBrowserIconService.LocalVariable, locVar.Name, yield return new ValueNode(ClassBrowserIconService.LocalVariable, locVar.Name,
() => locVarCopy.GetValue(stackFrame)); () => locVarCopy.GetValue(stackFrame));
} }
} }

Loading…
Cancel
Save