Browse Source

reimplement context menu for debugger tooltips

pull/59/merge
Siegfried Pammer 12 years ago
parent
commit
17ddb265d2
  1. 6
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin
  2. 5
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj
  3. 20
      src/AddIns/Debugger/Debugger.AddIn/Tooltips/DebuggerTooltipControl.xaml
  4. 38
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/Commands.cs
  5. 17
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/TreeNode.cs
  6. 2
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/ValueNode.cs
  7. 17
      src/Main/ICSharpCode.Core.Presentation/NotBoolConverter.cs

6
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin

@ -169,4 +169,10 @@ @@ -169,4 +169,10 @@
icon = "Icons.16x16.AssemblyFromFile"
class = "ICSharpCode.SharpDevelop.Gui.Pads.AddModuleToWorkspaceCommand"/>
</Path>
<Path name="/AddIns/Debugger/Tooltips/ContextMenu/TreeNode">
<MenuItem id="Copy"
label="${res:MainWindow.Windows.Debug.LocalVariables.CopyToClipboard}"
class="Debugger.AddIn.TreeModel.CopyCommand" />
</Path>
</AddIn>

5
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj

@ -142,8 +142,11 @@ @@ -142,8 +142,11 @@
<Compile Include="Service\ExecuteProcessWindow.xaml.cs">
<DependentUpon>ExecuteProcessWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Tooltips\DebuggerTooltipControl.xaml.cs" />
<Compile Include="Tooltips\DebuggerTooltipControl.xaml.cs">
<DependentUpon>DebuggerTooltipControl.xaml</DependentUpon>
</Compile>
<Compile Include="Tooltips\VisualizerPicker.cs" />
<Compile Include="TreeModel\Commands.cs" />
<Compile Include="TreeModel\SharpTreeNodeAdapter.cs" />
<Compile Include="TreeModel\TreeNode.cs" />
<Compile Include="Visualizers\Commands\ExpressionVisualizerCommand.cs" />

20
src/AddIns/Debugger/Debugger.AddIn/Tooltips/DebuggerTooltipControl.xaml

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
xmlns:debugging="clr-namespace:Debugger.AddIn.Tooltips"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
AllowsTransparency="True"
>
<Popup.Resources>
@ -115,6 +116,8 @@ @@ -115,6 +116,8 @@
</Setter>
</Style>
<core:ContextMenuBuilder x:Key="menuBuilder" />
</ResourceDictionary>
</Popup.Resources>
<StackPanel Orientation="Horizontal">
@ -126,7 +129,7 @@ @@ -126,7 +129,7 @@
MaxHeight="202"
SelectionMode="Single"
SelectionUnit="FullRow"
Name="dataGrid"
x:Name="dataGrid"
AutoGenerateColumns="False"
CanUserAddRows="False"
HeadersVisibility="None"
@ -257,21 +260,12 @@ @@ -257,21 +260,12 @@
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox
x:Name="valueText"
Style="{StaticResource TextStyle}"
IsEnabled="{Binding CanSetValue}"
ContextMenu="{Binding ContextMenuAddInTreeEntry, Converter={StaticResource menuBuilder}, ConverterParameter={x:Reference dataGrid}}"
ContextMenuService.ShowOnDisabled="True"
Text="{Binding Value}"
>
<TextBox.ContextMenu>
<ContextMenu>
<!-- <MenuItem Header="{core:Localize XML.MainMenu.EditMenu.Copy}" DataContext="{Binding}" Click="CopyMenuItemClick">
<MenuItem.Icon>
<Image Source="{core:GetBitmap Icons.16x16.CopyIcon}" />
</MenuItem.Icon>
</MenuItem>-->
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
Text="{Binding Value}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

38
src/AddIns/Debugger/Debugger.AddIn/TreeModel/Commands.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
// 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.Linq;
using System.Text;
using System.Windows.Controls;
using ICSharpCode.SharpDevelop;
namespace Debugger.AddIn.TreeModel
{
public class CopyCommand : SimpleCommand
{
public override void Execute(object parameter)
{
var grid = parameter as DataGrid;
if (grid == null) return;
var selection = FormatValue(grid.SelectedItems.OfType<ValueNode>());
SD.Clipboard.SetText(selection);
}
string FormatValue(IEnumerable<ValueNode> nodes)
{
StringBuilder b = new StringBuilder();
bool first = true;
foreach (var node in nodes) {
if (first)
first = false;
else
b.AppendLine();
b.Append(node.FullText);
}
return b.ToString();
}
}
}

17
src/AddIns/Debugger/Debugger.AddIn/TreeModel/TreeNode.cs

@ -4,9 +4,7 @@ @@ -4,9 +4,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Media;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Debugging;
@ -84,6 +82,17 @@ namespace Debugger.AddIn.TreeModel @@ -84,6 +82,17 @@ namespace Debugger.AddIn.TreeModel
}
}
string contextMenuAddInTreeEntry = "/AddIns/Debugger/Tooltips/ContextMenu/TreeNode";
public virtual string ContextMenuAddInTreeEntry {
get { return contextMenuAddInTreeEntry; }
set {
if (this.contextMenuAddInTreeEntry != value) {
contextMenuAddInTreeEntry = value;
OnPropertyChanged("ContextMenuAddInTreeEntry");
}
}
}
public Func<IEnumerable<TreeNode>> GetChildren { get; protected set; }
public bool HasChildren {
@ -92,9 +101,9 @@ namespace Debugger.AddIn.TreeModel @@ -92,9 +101,9 @@ namespace Debugger.AddIn.TreeModel
public IEnumerable<IVisualizerCommand> VisualizerCommands { get; protected set; }
public bool HasVisualizerCommands {
public bool HasVisualizerCommands {
get {
return (VisualizerCommands != null) && (VisualizerCommands.Count() > 0);
return (VisualizerCommands != null) && VisualizerCommands.Any();
}
}

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

@ -368,7 +368,7 @@ namespace Debugger.AddIn.TreeModel @@ -368,7 +368,7 @@ namespace Debugger.AddIn.TreeModel
int count = 0;
try {
Value list = getValue();
IType iListType = list.Type.GetAllBaseTypeDefinitions().Where(t => t.FullName == typeof(IList).FullName).FirstOrDefault();
IType iListType = list.Type.GetAllBaseTypeDefinitions().FirstOrDefault(t => t.FullName == typeof(IList).FullName);
itemProp = iListType.GetProperties(p => p.Name == "Item").Single();
// Do not get string representation since it can be printed in hex
count = (int)list.GetPropertyValue(WindowsDebugger.EvalThread, iListType.GetProperties(p => p.Name == "Count").Single()).PrimitiveValue;

17
src/Main/ICSharpCode.Core.Presentation/NotBoolConverter.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
#endregion
@ -29,4 +30,20 @@ namespace ICSharpCode.Core.Presentation @@ -29,4 +30,20 @@ namespace ICSharpCode.Core.Presentation
return true;
}
}
public class ContextMenuBuilder : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string) {
return MenuService.CreateContextMenu(parameter, (string)value);
}
throw new NotSupportedException();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

Loading…
Cancel
Save