Browse Source

reimplement WatchPad

pull/59/merge
Siegfried Pammer 13 years ago
parent
commit
f2c8cd5bed
  1. 7
      src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs
  2. 26
      src/AddIns/Debugger/Debugger.AddIn/Pads/CommonResources.xaml
  3. 83
      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

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

@ -65,16 +65,21 @@ namespace Debugger.AddIn.Pads.Controls @@ -65,16 +65,21 @@ namespace Debugger.AddIn.Pads.Controls
this.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
this.editor.TextArea.GotKeyboardFocus += delegate {
this.Background = Brushes.White;
this.Foreground = Brushes.Black;
};
this.editor.TextArea.LostKeyboardFocus += delegate {
this.Background = Brushes.Transparent;
this.ClearValue(ForegroundProperty);
this.Text = this.editor.Text;
this.editor.Select(0, 0);
this.editorAdapter.ClearSelection();
};
this.editor.TextArea.PreviewKeyDown += editor_TextArea_PreviewKeyDown;
this.editor.TextArea.TextEntered += editor_TextArea_TextEntered;
this.Content = this.editor.TextArea;
HorizontalContentAlignment = HorizontalAlignment.Stretch;
VerticalContentAlignment = VerticalAlignment.Stretch;
}
void editor_TextArea_PreviewKeyDown(object sender, KeyEventArgs e)

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

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

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

@ -3,7 +3,6 @@ @@ -3,7 +3,6 @@
using System;
using System.Linq;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
@ -14,7 +13,6 @@ using Debugger.AddIn.Pads.Controls; @@ -14,7 +13,6 @@ using Debugger.AddIn.Pads.Controls;
using Debugger.AddIn.TreeModel;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Services;
using ICSharpCode.SharpDevelop.Workbench;
@ -43,45 +41,52 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -43,45 +41,52 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
var res = new CommonResources();
res.InitializeComponent();
this.tree = new SharpTreeView();
this.tree.Root = new SharpTreeNode();
this.tree.ShowRoot = false;
this.tree.View = (GridView)res["variableGridView"];
this.tree.ContextMenu = MenuService.CreateContextMenu(this, "/SharpDevelop/Pads/WatchPad/ContextMenu");
this.tree.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) {
tree = new SharpTreeView();
tree.Root = new SharpTreeNode();
tree.ShowRoot = false;
tree.View = (GridView)res["variableGridView"];
tree.SetValue(GridViewColumnAutoSize.AutoWidthProperty, "50%;25%;25%");
tree.ContextMenu = MenuService.CreateContextMenu(this, "/SharpDevelop/Pads/WatchPad/ContextMenu");
tree.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) {
if (this.tree.SelectedItem == null) {
AddWatchCommand cmd = new AddWatchCommand { Owner = this };
cmd.Run();
}
};
ProjectService.SolutionLoaded += delegate { LoadNodes(); };
ProjectService.SolutionClosing += delegate { SaveNodes(); };
LoadNodes();
// ProjectService.SolutionLoaded += delegate { LoadNodes(); };
// ProjectService.SolutionClosing += delegate { SaveNodes(); };
// LoadNodes();
WindowsDebugger.RefreshingPads += RefreshPad;
RefreshPad();
}
void LoadNodes()
{
if (ProjectService.OpenSolution != null) {
var props = ProjectService.OpenSolution.Preferences.NestedProperties("Watches");
foreach (var key in props.Keys) {
this.Items.Add(new TreeNode(props.Get(key, ""), () => null).ToSharpTreeNode());
}
}
}
// void LoadNodes()
// {
// if (ProjectService.OpenSolution != null) {
// var props = ProjectService.OpenSolution.Preferences.NestedProperties("Watches");
// foreach (var key in props.Keys) {
// this.Items.Add(new TreeNode(props.Get(key, ""), () => null).ToSharpTreeNode());
// }
// }
// }
//
// 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);
// }
// }
// }
void SaveNodes()
public void AddWatch(string expression = null)
{
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, (object)null);
}
}
var node = MakeNode(expression);
this.Items.Add(node);
}
SharpTreeNodeAdapter MakeNode(string name)
@ -89,13 +94,21 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -89,13 +94,21 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
LoggingService.Info("Evaluating watch: " + name);
TreeNode node = null;
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) {
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.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();
}
@ -103,12 +116,14 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -103,12 +116,14 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
{
Process process = WindowsDebugger.CurrentProcess;
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();
process.EnqueueForEach(
Dispatcher.CurrentDispatcher,
names,
name => this.Items.Add(MakeNode(name))
expressions,
expr => this.Items.Add(MakeNode(expr))
);
}
}

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

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

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

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

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

@ -107,6 +107,14 @@ namespace Debugger.AddIn.TreeModel @@ -107,6 +107,14 @@ namespace Debugger.AddIn.TreeModel
// Do not keep permanent reference
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
if (val.IsNull) {
this.GetChildren = null;
@ -187,12 +195,12 @@ namespace Debugger.AddIn.TreeModel @@ -187,12 +195,12 @@ namespace Debugger.AddIn.TreeModel
this.Type = string.Empty;
this.GetChildren = 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>
@ -231,7 +239,7 @@ namespace Debugger.AddIn.TreeModel @@ -231,7 +239,7 @@ namespace Debugger.AddIn.TreeModel
foreach(LocalVariable locVar in localVars) {
var locVarCopy = locVar;
yield return new ValueNode(ClassBrowserIconService.LocalVariable, locVar.Name,
() => locVarCopy.GetValue(stackFrame));
() => locVarCopy.GetValue(stackFrame));
}
}

Loading…
Cancel
Save