Browse Source

XamlBinding:

- improved attribute CC
- added GridLengthEditor to EditGridColumnsAndRowsDialog
- added XamlOutlineContentHost

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4554 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
693581e485
  1. 2
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 32
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  3. 72
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs
  4. 11
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs
  5. 9
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml
  6. 83
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs
  7. 8
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml
  8. 162
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml.cs
  9. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs
  10. 19
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj
  11. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs
  12. 13
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs
  13. 21
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs
  14. 14
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml
  15. 355
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs
  16. 4
      src/Libraries/SharpTreeView/ICSharpCode.TreeView/Properties/AssemblyInfo.cs
  17. 11
      src/Libraries/SharpTreeView/ICSharpCode.TreeView/SharpTreeNode.cs
  18. 6
      src/Libraries/SharpTreeView/ICSharpCode.TreeView/Themes/Generic.xaml
  19. 2
      src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs

2
AddIns/ICSharpCode.SharpDevelop.addin

@ -98,7 +98,7 @@
title = "${res:MainWindow.Windows.OutlinePad}" title = "${res:MainWindow.Windows.OutlinePad}"
icon = "PadIcons.Toolbar" icon = "PadIcons.Toolbar"
class = "ICSharpCode.SharpDevelop.Gui.OutlinePad" class = "ICSharpCode.SharpDevelop.Gui.OutlinePad"
defaultPosition = "Left" /> defaultPosition = "Left, Hidden" />
<Pad id = "ErrorList" <Pad id = "ErrorList"
category = "Main" category = "Main"

32
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs

@ -290,14 +290,10 @@ namespace ICSharpCode.XamlBinding
XamlCompilationUnit cu = context.ParseInformation.BestCompilationUnit as XamlCompilationUnit; XamlCompilationUnit cu = context.ParseInformation.BestCompilationUnit as XamlCompilationUnit;
IReturnType rt = null; IReturnType rt = null;
IReturnType elementReturnType = null;
bool isMember = false;
bool inContentRoot = false;
if (last != null && cu != null) { if (last != null && cu != null) {
if (!last.Name.Contains(".") || last.Name.EndsWith(".", StringComparison.OrdinalIgnoreCase)) { if (!last.Name.Contains(".") || last.Name.EndsWith(".", StringComparison.OrdinalIgnoreCase)) {
elementReturnType = rt = cu.CreateType(last.Namespace, last.Name.Trim('.')); rt = cu.CreateType(last.Namespace, last.Name.Trim('.'));
string contentPropertyName = GetContentPropertyName(rt); string contentPropertyName = GetContentPropertyName(rt);
if (!string.IsNullOrEmpty(contentPropertyName)) { if (!string.IsNullOrEmpty(contentPropertyName)) {
string fullName = string.IsNullOrEmpty(last.Prefix) ? last.Name + "." + contentPropertyName : last.Prefix + ":" + last.Name + "." + contentPropertyName; string fullName = string.IsNullOrEmpty(last.Prefix) ? last.Name + "." + contentPropertyName : last.Prefix + ":" + last.Name + "." + contentPropertyName;
@ -305,10 +301,7 @@ namespace ICSharpCode.XamlBinding
if (mrr != null) { if (mrr != null) {
rt = mrr.ResolvedType; rt = mrr.ResolvedType;
isMember = true;
} }
inContentRoot = true;
} }
} else { } else {
string fullName = string.IsNullOrEmpty(last.Prefix) ? last.Name : last.Prefix + ":" + last.Name; string fullName = string.IsNullOrEmpty(last.Prefix) ? last.Name : last.Prefix + ":" + last.Name;
@ -316,7 +309,6 @@ namespace ICSharpCode.XamlBinding
if (mrr != null) { if (mrr != null) {
rt = mrr.ResolvedType; rt = mrr.ResolvedType;
isMember = true;
} }
} }
} }
@ -352,18 +344,6 @@ namespace ICSharpCode.XamlBinding
} }
} }
if (!(rt == null || isMember || classesOnly)) {
foreach (IProperty p in rt.GetProperties()) {
if (p.IsPublic && (p.CanSet || p.ReturnType.IsCollectionReturnType()))
result.Add(new XamlCodeCompletionItem(p, last.Prefix, last.Name));
}
} else if (elementReturnType != null && inContentRoot) {
foreach (IProperty p in elementReturnType.GetProperties()) {
if (p.IsPublic && (p.CanSet || p.ReturnType.IsCollectionReturnType()))
result.Add(new XamlCodeCompletionItem(p, last.Prefix, last.Name));
}
}
string xamlPrefix = Utils.GetXamlNamespacePrefix(context); string xamlPrefix = Utils.GetXamlNamespacePrefix(context);
var xamlItems = XamlNamespaceAttributes.AsEnumerable(); var xamlItems = XamlNamespaceAttributes.AsEnumerable();
@ -439,7 +419,7 @@ namespace ICSharpCode.XamlBinding
QualifiedNameWithLocation last = context.ActiveElement; QualifiedNameWithLocation last = context.ActiveElement;
TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(last.Name, context), info, editor.Document.Text) as TypeResolveResult; TypeResolveResult trr = new XamlResolver().Resolve(new ExpressionResult(last.Name, context), info, editor.Document.Text) as TypeResolveResult;
IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null; IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null;
list = new XamlAttributeCompletionItemList();
list.Items.AddRange(CreateAttributeList(context, true)); list.Items.AddRange(CreateAttributeList(context, true));
list.Items.AddRange(standardAttributes); list.Items.AddRange(standardAttributes);
} }
@ -856,7 +836,7 @@ namespace ICSharpCode.XamlBinding
var ns = context.XmlnsDefinitions[prefixNamespace]; var ns = context.XmlnsDefinitions[prefixNamespace];
IClass c = XamlCompilationUnit.GetNamespaceMembers(pc, ns).FirstOrDefault(item => item.Name == prefixClassName); IClass c = XamlCompilationUnit.GetNamespaceMembers(pc, ns).FirstOrDefault(item => item.Name == prefixClassName);
if (c != null) { if (c != null) {
if (!(c.IsAbstract && c.IsStatic if (!(c.IsAbstract
&& !c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Attribute") && !c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Attribute")
&& c.Methods.Any(m => m.IsConstructor && m.IsPublic))) { && c.Methods.Any(m => m.IsConstructor && m.IsPublic))) {
prefixNamespace = string.IsNullOrEmpty(prefixNamespace) ? prefixNamespace : prefixNamespace + ":"; prefixNamespace = string.IsNullOrEmpty(prefixNamespace) ? prefixNamespace : prefixNamespace + ":";
@ -879,10 +859,8 @@ namespace ICSharpCode.XamlBinding
continue; continue;
if (!c.Methods.Any(m => m.IsConstructor && m.IsPublic)) if (!c.Methods.Any(m => m.IsConstructor && m.IsPublic))
continue; continue;
if (properties) if (c.HasAttached(properties, events))
AddAttachedProperties(c, result, key, string.Empty); result.Add(new XamlCodeCompletionItem(c, ns.Key));
if (events)
AddAttachedEvents(c, result, key, string.Empty);
} }
} }
} }

72
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs

@ -254,7 +254,77 @@ namespace ICSharpCode.XamlBinding
return false; return false;
} }
/// <remarks>Works only if fullyQualyfiedClassName is the name of a class!</remarks> public static bool HasAttached(this IClass thisValue, bool lookForProperties, bool lookForEvents)
{
if (!lookForProperties && !lookForEvents)
return false;
foreach (IField field in thisValue.Fields) {
if (!field.IsPublic || !field.IsStatic || !field.IsReadonly || field.ReturnType == null)
continue;
bool foundMethod = false;
if (lookForProperties) {
if (field.ReturnType.FullyQualifiedName != "System.Windows.DependencyProperty")
continue;
if (field.Name.Length <= "Property".Length)
continue;
if (!field.Name.EndsWith("Property", StringComparison.Ordinal))
continue;
string fieldName = field.Name.Remove(field.Name.Length - "Property".Length);
foreach (IMethod method in thisValue.Methods) {
if (!method.IsPublic || !method.IsStatic || method.Name.Length <= 3)
continue;
if (!method.Name.StartsWith("Get") && !method.Name.StartsWith("Set"))
continue;
foundMethod = method.Name.Remove(0, 3) == fieldName;
if (foundMethod)
return true;
}
}
if (lookForEvents && !foundMethod) {
if (field.ReturnType.FullyQualifiedName != "System.Windows.RoutedEvent")
continue;
if (field.Name.Length <= "Event".Length)
continue;
if (!field.Name.EndsWith("Event", StringComparison.Ordinal))
continue;
string fieldName = field.Name.Remove(field.Name.Length - "Event".Length);
foreach (IMethod method in thisValue.Methods) {
if (!method.IsPublic || !method.IsStatic || method.Name.Length <= 3)
continue;
string methodName = string.Empty;
if (methodName.EndsWith("Handler", StringComparison.Ordinal))
methodName = method.Name.Remove(method.Name.Length - "Handler".Length);
else
continue;
if (methodName.StartsWith("Add"))
methodName = methodName.Remove(0, 3);
else if (methodName.StartsWith("Remove"))
methodName = methodName.Remove(0, 6);
else
continue;
foundMethod = methodName == fieldName;
if (foundMethod)
return true;
}
}
}
return false;
}
/// <remarks>Works only if fullyQualifiedClassName is the name of a class!</remarks>
public static bool DerivesFrom(this IClass myClass, string fullyQualifiedClassName) public static bool DerivesFrom(this IClass myClass, string fullyQualifiedClassName)
{ {
return myClass.ClassInheritanceTreeClassesOnly.Any(c => c.FullyQualifiedName == fullyQualifiedClassName); return myClass.ClassInheritanceTreeClassesOnly.Any(c => c.FullyQualifiedName == fullyQualifiedClassName);

11
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs

@ -5,12 +5,13 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop.Gui;
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.XamlBinding.PowerToys.Dialogs; using ICSharpCode.XamlBinding.PowerToys.Dialogs;
@ -23,11 +24,6 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
{ {
protected override bool Refactor(ITextEditor editor, XDocument document) protected override bool Refactor(ITextEditor editor, XDocument document)
{ {
if (editor.SelectionLength == 0) {
MessageService.ShowError("Please select a Grid!");
return false;
}
Location startLoc = editor.Document.OffsetToPosition(editor.SelectionStart); Location startLoc = editor.Document.OffsetToPosition(editor.SelectionStart);
Location endLoc = editor.Document.OffsetToPosition(editor.SelectionStart + editor.SelectionLength); Location endLoc = editor.Document.OffsetToPosition(editor.SelectionStart + editor.SelectionLength);
@ -40,6 +36,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands
} }
EditGridColumnsAndRowsDialog dialog = new EditGridColumnsAndRowsDialog(selectedItem); EditGridColumnsAndRowsDialog dialog = new EditGridColumnsAndRowsDialog(selectedItem);
dialog.Owner = WorkbenchSingleton.MainWindow;
if (dialog.ShowDialog() ?? false) { if (dialog.ShowDialog() ?? false) {
selectedItem.ReplaceWith(dialog.ConstructedTree); selectedItem.ReplaceWith(dialog.ConstructedTree);

9
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
Title="Edit grid columns and rows" Height="500" Width="500" Title="Edit grid columns and rows" Height="500" Width="500"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow"> WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
<Window.Resources> <Window.Resources>
<Style x:Key="normal" TargetType="{x:Type Button}"> <Style x:Key="normal" TargetType="{x:Type Button}">
@ -44,6 +45,12 @@
<Button x:Name="btnOK" Content="{sd:Localize Global.OKButtonText}" Click="BtnOKClick" Style="{StaticResource normal}" /> <Button x:Name="btnOK" Content="{sd:Localize Global.OKButtonText}" Click="BtnOKClick" Style="{StaticResource normal}" />
<Button x:Name="btnCancel" Content="{sd:Localize Global.CancelButtonText}" Click="BtnCancelClick" Style="{StaticResource normal}" /> <Button x:Name="btnCancel" Content="{sd:Localize Global.CancelButtonText}" Click="BtnCancelClick" Style="{StaticResource normal}" />
</StackPanel> </StackPanel>
<Grid x:Name="gridDisplay" /> <Grid DockPanel.Dock="Top" x:Name="columnWidthGrid">
</Grid>
<Grid DockPanel.Dock="Left" x:Name="rowHeightGrid">
</Grid>
<Grid x:Name="gridDisplay" ShowGridLines="True" />
</DockPanel> </DockPanel>
</Window> </Window>

83
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs

@ -41,6 +41,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
XElement colDefitions; XElement colDefitions;
IList<XElement> additionalProperties; IList<XElement> additionalProperties;
bool gridLengthInvalid;
class UndoStep class UndoStep
{ {
public XElement Tree { get; set; } public XElement Tree { get; set; }
@ -81,6 +83,30 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
if (this.colDefitions.Parent != null) if (this.colDefitions.Parent != null)
this.colDefitions.Remove(); this.colDefitions.Remove();
this.rowDefitions
.Elements()
.Select(row => row.Attribute("Height"))
.ForEach(
height => {
if (height.Value.Trim() == "1*")
height.Value = "*";
else
height.Value = height.Value.Trim();
}
);
this.colDefitions
.Elements()
.Select(col => col.Attribute("Width"))
.ForEach(
width => {
if (width.Value.Trim() == "1*")
width.Value = "*";
else
width.Value = width.Value.Trim();
}
);
this.additionalProperties = gridTree.Elements().Where(e => e.Name.LocalName.Contains(".")).ToList(); this.additionalProperties = gridTree.Elements().Where(e => e.Name.LocalName.Contains(".")).ToList();
this.additionalProperties.ForEach(item => { if (item.Parent != null) item.Remove(); }); this.additionalProperties.ForEach(item => { if (item.Parent != null) item.Remove(); });
@ -110,7 +136,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
int row = (int)block.GetValue(Grid.RowProperty); int row = (int)block.GetValue(Grid.RowProperty);
var newRow = new XElement(rowDefName); var newRow = new XElement(rowDefName);
newRow.SetAttributeValue(XName.Get("Height"), "Auto"); newRow.SetAttributeValue(XName.Get("Height"), "*");
var items = rowDefitions.Elements().Skip(row); var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault(); var selItem = items.FirstOrDefault();
if (selItem != null) if (selItem != null)
@ -148,7 +174,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
int row = (int)block.GetValue(Grid.RowProperty); int row = (int)block.GetValue(Grid.RowProperty);
var newRow = new XElement(rowDefName); var newRow = new XElement(rowDefName);
newRow.SetAttributeValue(XName.Get("Height"), "Auto"); newRow.SetAttributeValue(XName.Get("Height"), "*");
var items = rowDefitions.Elements().Skip(row); var items = rowDefitions.Elements().Skip(row);
var selItem = items.FirstOrDefault(); var selItem = items.FirstOrDefault();
if (selItem != null) if (selItem != null)
@ -572,6 +598,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
void BtnOKClick(object sender, RoutedEventArgs e) void BtnOKClick(object sender, RoutedEventArgs e)
{ {
if (gridLengthInvalid) {
MessageService.ShowError("Grid is invalid, please check the row heights and column widths!");
return;
}
this.DialogResult = true; this.DialogResult = true;
} }
@ -582,24 +613,40 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.gridDisplay.RowDefinitions.Clear(); this.gridDisplay.RowDefinitions.Clear();
this.gridDisplay.ColumnDefinitions.Clear(); this.gridDisplay.ColumnDefinitions.Clear();
this.columnWidthGrid.ColumnDefinitions.Clear();
this.columnWidthGrid.Children.Clear();
this.rowHeightGrid.RowDefinitions.Clear();
this.rowHeightGrid.Children.Clear();
int rows = rowDefitions.Elements().Count(); int rows = rowDefitions.Elements().Count();
int cols = colDefitions.Elements().Count(); int cols = colDefitions.Elements().Count();
if (rows == 0) { if (rows == 0) {
rowDefitions.Add(new XElement(rowDefName).AddAttribute("Height", "Auto")); rowDefitions.Add(new XElement(rowDefName).AddAttribute("Height", "*"));
rows = 1; rows = 1;
} }
if (cols == 0) { if (cols == 0) {
colDefitions.Add(new XElement(colDefName).AddAttribute("Width", "Auto")); colDefitions.Add(new XElement(colDefName).AddAttribute("Width", "*"));
cols = 1; cols = 1;
} }
for (int i = 0; i < cols; i++) for (int i = 0; i < cols; i++) {
this.gridDisplay.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); this.gridDisplay.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
this.columnWidthGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
GridLengthEditor editor = new GridLengthEditor(Orientation.Horizontal, i, (colDefitions.Elements().ElementAt(i).Attribute("Width") ?? new XAttribute("Width", "")).Value);
editor.SelectedValueChanged += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorSelectedValueChanged);
this.columnWidthGrid.Children.Add(editor);
}
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
this.gridDisplay.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); this.gridDisplay.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
this.rowHeightGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
GridLengthEditor editor = new GridLengthEditor(Orientation.Vertical, i, (rowDefitions.Elements().ElementAt(i).Attribute("Height") ?? new XAttribute("Height", "")).Value);
editor.SelectedValueChanged += new EventHandler<GridLengthSelectionChangedEventArgs>(EditorSelectedValueChanged);
this.rowHeightGrid.Children.Add(editor);
for (int j = 0; j < cols; j++) { for (int j = 0; j < cols; j++) {
StackPanel displayRect = new StackPanel() { StackPanel displayRect = new StackPanel() {
Margin = new Thickness(5), Margin = new Thickness(5),
@ -626,6 +673,29 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
this.InvalidateVisual(); this.InvalidateVisual();
} }
void EditorSelectedValueChanged(object sender, GridLengthSelectionChangedEventArgs e)
{
gridLengthInvalid = colDefitions.Elements().Any(col => (col.Attribute("Width") ?? new XAttribute("Width", "*")).Value == "Invalid")
|| rowDefitions.Elements().Any(row => (row.Attribute("Height") ?? new XAttribute("Height", "*")).Value == "Invalid")
|| !e.Value.HasValue;
string value = "Invalid";
if (e.Value.HasValue) {
if (e.Value.Value.IsAuto)
value = "Auto";
if (e.Value.Value.IsStar)
value = (e.Value.Value.Value == 1) ? "*" : e.Value.Value.Value + "*";
if (e.Value.Value.IsAbsolute)
value = e.Value.Value.Value + "px";
}
if (e.Type == Orientation.Horizontal)
colDefitions.Elements().ElementAt(e.Cell).SetAttributeValue("Width", value);
else
rowDefitions.Elements().ElementAt(e.Cell).SetAttributeValue("Height", value);
}
class DragDropMarkerAdorner : Adorner class DragDropMarkerAdorner : Adorner
{ {
DragDropMarkerAdorner(UIElement adornedElement) DragDropMarkerAdorner(UIElement adornedElement)
@ -658,14 +728,11 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
if (aboveElement is StackPanel) { if (aboveElement is StackPanel) {
aboveElement = (panel.Children.Count > 0 ? panel.Children[panel.Children.Count - 1] : panel) as FrameworkElement; aboveElement = (panel.Children.Count > 0 ? panel.Children[panel.Children.Count - 1] : panel) as FrameworkElement;
Core.LoggingService.Info("aboveElement second");
adorner = new DragDropMarkerAdorner(aboveElement); adorner = new DragDropMarkerAdorner(aboveElement);
adorner.start = new Point(5, 5 + aboveElement.DesiredSize.Height); adorner.start = new Point(5, 5 + aboveElement.DesiredSize.Height);
adorner.end = new Point(panel.ActualWidth - 10, 5 + aboveElement.DesiredSize.Height); adorner.end = new Point(panel.ActualWidth - 10, 5 + aboveElement.DesiredSize.Height);
} else { } else {
aboveElement = aboveElement.TemplatedParent as FrameworkElement; aboveElement = aboveElement.TemplatedParent as FrameworkElement;
Core.LoggingService.Info("aboveElement normal: " + aboveElement);
adorner = new DragDropMarkerAdorner(aboveElement); adorner = new DragDropMarkerAdorner(aboveElement);
adorner.start = new Point(5, 0); adorner.start = new Point(5, 0);
adorner.end = new Point(panel.ActualWidth - 10, 0); adorner.end = new Point(panel.ActualWidth - 10, 0);

8
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml

@ -0,0 +1,8 @@
<UserControl x:Class="ICSharpCode.XamlBinding.PowerToys.Dialogs.GridLengthEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel x:Name="panel" Orientation="Horizontal" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="btnType" Margin="3" Content=" * " Click="BtnTypeClick" />
<TextBox x:Name="txtNumericValue" MaxLength="10" Width="50" Margin="3" TextChanged="TxtNumericValueTextChanged" />
</StackPanel>
</UserControl>

162
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml.cs

@ -0,0 +1,162 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.XamlBinding.PowerToys.Dialogs
{
/// <summary>
/// Interaction logic for GridLengthEditor.xaml
/// </summary>
public partial class GridLengthEditor : UserControl
{
GridUnitType type = GridUnitType.Star;
int cell;
public GridLengthEditor(Orientation type, int cell, string value)
{
InitializeComponent();
if (type == Orientation.Horizontal)
this.SetValue(Grid.ColumnProperty, cell);
else
this.SetValue(Grid.RowProperty, cell);
SetValue(value.Trim());
this.cell = cell;
this.panel.Orientation = type;
}
void SetValue(string value)
{
if (value.Equals("Auto", StringComparison.OrdinalIgnoreCase)) {
type = GridUnitType.Auto;
txtNumericValue.Text = "";
} else {
if (value.EndsWith("px", StringComparison.OrdinalIgnoreCase)) {
type = GridUnitType.Pixel;
txtNumericValue.Text = value.Remove(value.Length - 2);
} else if (value.EndsWith("*", StringComparison.OrdinalIgnoreCase)) {
type = GridUnitType.Star;
txtNumericValue.Text = value.Remove(value.Length - 1);
} else if (string.IsNullOrEmpty(value)) {
type = GridUnitType.Star;
txtNumericValue.Text = "";
} else {
type = GridUnitType.Pixel;
txtNumericValue.Text = value;
}
}
switch (type) {
case GridUnitType.Star:
btnType.Content = " * ";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Pixel:
btnType.Content = "Pixel";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Auto:
btnType.Content = "Auto";
txtNumericValue.Visibility = Visibility.Collapsed;
break;
}
}
void BtnTypeClick(object sender, RoutedEventArgs e)
{
switch (type) {
case GridUnitType.Auto:
type = GridUnitType.Star;
btnType.Content = " * ";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Star:
type = GridUnitType.Pixel;
btnType.Content = "Pixel";
txtNumericValue.Visibility = Visibility.Visible;
break;
case GridUnitType.Pixel:
type = GridUnitType.Auto;
btnType.Content = "Auto";
txtNumericValue.Visibility = Visibility.Collapsed;
break;
}
OnSelectedValueChanged(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, this.cell, SelectedValue));
}
public GridLength? SelectedValue {
get {
if (type == GridUnitType.Star || type == GridUnitType.Pixel) {
double value;
if (type == GridUnitType.Star && string.IsNullOrEmpty(txtNumericValue.Text)) {
return new GridLength(1, type);
} else {
if (double.TryParse(txtNumericValue.Text, out value))
return new GridLength(value, type);
}
return null;
}
return GridLength.Auto;
}
}
public event EventHandler<GridLengthSelectionChangedEventArgs> SelectedValueChanged;
protected virtual void OnSelectedValueChanged(GridLengthSelectionChangedEventArgs e)
{
if (SelectedValueChanged != null) {
SelectedValueChanged(this, e);
}
}
void TxtNumericValueTextChanged(object sender, TextChangedEventArgs e)
{
if (type == GridUnitType.Star && string.IsNullOrEmpty(txtNumericValue.Text)) {
txtNumericValue.ClearValue(TextBox.BackgroundProperty);
txtNumericValue.ClearValue(TextBox.ForegroundProperty);
} else {
double x;
if (!double.TryParse(txtNumericValue.Text, out x)) {
txtNumericValue.Background = Brushes.Red;
txtNumericValue.Foreground = Brushes.White;
} else {
txtNumericValue.ClearValue(TextBox.BackgroundProperty);
txtNumericValue.ClearValue(TextBox.ForegroundProperty);
}
}
OnSelectedValueChanged(new GridLengthSelectionChangedEventArgs(this.panel.Orientation, cell, SelectedValue));
}
}
public class GridLengthSelectionChangedEventArgs : EventArgs
{
public Orientation Type { get; private set; }
public int Cell { get; private set; }
public GridLength? Value { get; private set; }
public GridLengthSelectionChangedEventArgs(Orientation type, int cell, GridLength? value)
{
this.Type = type;
this.Cell = cell;
this.Value = value;
}
}
}

4
src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs

@ -36,7 +36,7 @@ namespace ICSharpCode.XamlBinding.PowerToys
if (provider != null) { if (provider != null) {
TextReader reader = provider.TextEditor.Document.CreateReader(); TextReader reader = provider.TextEditor.Document.CreateReader();
XDocument document = XDocument.Load(reader, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); XDocument document = XDocument.Load(reader, LoadOptions.SetLineInfo);
document.Declaration = null; document.Declaration = null;
if (Refactor(provider.TextEditor, document)) { if (Refactor(provider.TextEditor, document)) {
using (provider.TextEditor.Document.OpenUndoGroup()) { using (provider.TextEditor.Document.OpenUndoGroup()) {
@ -45,7 +45,6 @@ namespace ICSharpCode.XamlBinding.PowerToys
document.WriteTo(writer); document.WriteTo(writer);
writer.Flush(); writer.Flush();
provider.TextEditor.Document.Text = sWriter.ToString(); provider.TextEditor.Document.Text = sWriter.ToString();
XmlView.FormatXml(provider.TextEditor);
} }
} }
} }
@ -59,6 +58,7 @@ namespace ICSharpCode.XamlBinding.PowerToys
XmlWriterSettings settings = new XmlWriterSettings(); XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true; settings.Indent = true;
settings.OmitXmlDeclaration = true; settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;
return settings; return settings;
} }

19
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj

@ -68,9 +68,7 @@
</Compile> </Compile>
<Compile Include="LookupInfo.cs" /> <Compile Include="LookupInfo.cs" />
<Compile Include="MarkupExtensionInfo.cs" /> <Compile Include="MarkupExtensionInfo.cs" />
<Compile Include="MarkupExtensionParser.cs"> <Compile Include="MarkupExtensionParser.cs" />
<DependentUpon>MarkupExtensionTokenizer.cs</DependentUpon>
</Compile>
<Compile Include="CompletionDataHelper.cs" /> <Compile Include="CompletionDataHelper.cs" />
<Compile Include="Extensions.cs" /> <Compile Include="Extensions.cs" />
<Compile Include="MarkupExtensionTokenizer.cs" /> <Compile Include="MarkupExtensionTokenizer.cs" />
@ -99,6 +97,10 @@
<DependentUpon>ExtractPropertiesAsStyleDialog.xaml</DependentUpon> <DependentUpon>ExtractPropertiesAsStyleDialog.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="PowerToys\Dialogs\GridLengthEditor.xaml.cs">
<DependentUpon>GridLengthEditor.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="PowerToys\Dialogs\SelectSourceClassDialog.xaml.cs"> <Compile Include="PowerToys\Dialogs\SelectSourceClassDialog.xaml.cs">
<DependentUpon>SelectSourceClassDialog.xaml</DependentUpon> <DependentUpon>SelectSourceClassDialog.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
@ -126,6 +128,10 @@
<Compile Include="MarkupExtensionParseException.cs"> <Compile Include="MarkupExtensionParseException.cs">
</Compile> </Compile>
<Compile Include="XamlLanguageBinding.cs" /> <Compile Include="XamlLanguageBinding.cs" />
<Compile Include="XamlOutlineContentHost.xaml.cs">
<DependentUpon>XamlOutlineContentHost.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="XamlParser.cs" /> <Compile Include="XamlParser.cs" />
<Compile Include="XamlResolver.cs" /> <Compile Include="XamlResolver.cs" />
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> <ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">
@ -138,6 +144,11 @@
<Name>NRefactory</Name> <Name>NRefactory</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\SharpTreeView\ICSharpCode.TreeView\ICSharpCode.TreeView.csproj">
<Project>{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}</Project>
<Name>ICSharpCode.TreeView</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> <ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> <Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name> <Name>ICSharpCode.SharpDevelop</Name>
@ -183,7 +194,9 @@
<Page Include="Options\CodeCompletion.xaml" /> <Page Include="Options\CodeCompletion.xaml" />
<Page Include="PowerToys\Dialogs\EditGridColumnsAndRowsDialog.xaml" /> <Page Include="PowerToys\Dialogs\EditGridColumnsAndRowsDialog.xaml" />
<Page Include="PowerToys\Dialogs\ExtractPropertiesAsStyleDialog.xaml" /> <Page Include="PowerToys\Dialogs\ExtractPropertiesAsStyleDialog.xaml" />
<Page Include="PowerToys\Dialogs\GridLengthEditor.xaml" />
<Page Include="PowerToys\Dialogs\SelectSourceClassDialog.xaml" /> <Page Include="PowerToys\Dialogs\SelectSourceClassDialog.xaml" />
<Page Include="PowerToys\Dialogs\SourceClassFormEditor.xaml" /> <Page Include="PowerToys\Dialogs\SourceClassFormEditor.xaml" />
<Page Include="XamlOutlineContentHost.xaml" />
</ItemGroup> </ItemGroup>
</Project> </Project>

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs

@ -137,6 +137,8 @@ namespace ICSharpCode.XamlBinding
index = LineText.IndexOfAny(index + 1, '=', '.'); index = LineText.IndexOfAny(index + 1, '=', '.');
if (index > -1) { if (index > -1) {
context = CompletionDataHelper.ResolveContext(FileContent, FileName, LineNumber, index); context = CompletionDataHelper.ResolveContext(FileContent, FileName, LineNumber, index);
if (context.ActiveElement == null)
continue;
string elementName = context.ActiveElement.FullXmlName; string elementName = context.ActiveElement.FullXmlName;
int propertyNameIndex = elementName.IndexOf('.'); int propertyNameIndex = elementName.IndexOf('.');
string attribute = (context.AttributeName != null) ? context.AttributeName.FullXmlName : string.Empty; string attribute = (context.AttributeName != null) ? context.AttributeName.FullXmlName : string.Empty;

13
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

@ -18,12 +18,19 @@ using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding namespace ICSharpCode.XamlBinding
{ {
public sealed class XamlCompletionItemList : DefaultCompletionItemList public class XamlAttributeCompletionItemList : XamlCompletionItemList
{ {
public XamlCompletionItemList() public override CompletionItemListKeyResult ProcessInput(char key)
{ {
if (key == '.')
return CompletionItemListKeyResult.NormalKey;
return base.ProcessInput(key);
} }
}
public class XamlCompletionItemList : DefaultCompletionItemList
{
public override CompletionItemListKeyResult ProcessInput(char key) public override CompletionItemListKeyResult ProcessInput(char key)
{ {
if (key == ':' || key == '/') if (key == ':' || key == '/')
@ -32,7 +39,7 @@ namespace ICSharpCode.XamlBinding
return base.ProcessInput(key); return base.ProcessInput(key);
} }
public static int CountWhiteSpacesAtEnd(string text) static int CountWhiteSpacesAtEnd(string text)
{ {
if (string.IsNullOrEmpty(text)) if (string.IsNullOrEmpty(text))
return 0; return 0;

21
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs

@ -5,12 +5,15 @@
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.AvalonEdit.Editing;
using System; using System;
using System.Linq;
using System.Windows.Controls;
using ICSharpCode.AvalonEdit.Rendering; using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.XmlEditor; using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding namespace ICSharpCode.XamlBinding
@ -55,20 +58,4 @@ namespace ICSharpCode.XamlBinding
} }
} }
} }
class XamlOutlineContentHost : IOutlineContentHost
{
ITextEditor editor;
public XamlOutlineContentHost(ITextEditor editor)
{
this.editor = editor;
}
public object OutlineContent {
get {
return "Hello from XAML " + editor.FileName;
}
}
}
} }

14
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml

@ -0,0 +1,14 @@
<DockPanel x:Class="ICSharpCode.XamlBinding.XamlOutlineContentHost"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:treeview="http://icsharpcode.net/sharpdevelop/treeview"
>
<ToolBar DockPanel.Dock="Top">
<Button>Test</Button>
</ToolBar>
<treeview:SharpTreeView
x:Name="treeView"
AllowDrop="True"
AllowDropOrder="True"
MouseDoubleClick="TreeViewMouseDoubleClick" />
</DockPanel>

355
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs

@ -0,0 +1,355 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TreeView;
namespace ICSharpCode.XamlBinding
{
/// <summary>
/// Interaction logic for XamlOutlineContentHost.xaml
/// </summary>
public partial class XamlOutlineContentHost : DockPanel, IOutlineContentHost
{
ITextEditor editor;
Task updateTask;
DispatcherTimer timer;
public XamlOutlineContentHost(ITextEditor editor)
{
this.editor = editor;
InitializeComponent();
this.timer = new DispatcherTimer(DispatcherPriority.Background, this.Dispatcher);
this.timer.Tick += new EventHandler(XamlOutlineContentHostTick);
this.timer.Interval = new TimeSpan(0, 0, 2);
this.timer.Start();
}
void XamlOutlineContentHostTick(object sender, EventArgs e)
{
if (updateTask != null && updateTask.Status == TaskStatus.Running)
updateTask.Wait();
updateTask = new Task(UpdateTask);
updateTask.Start();
}
void UpdateTask()
{
string content = WorkbenchSingleton.SafeThreadFunction(() => editor.Document.Text);
Stack<NodeWrapper> nodes = new Stack<NodeWrapper>();
NodeWrapper root = null;
using (XmlTextReader reader = new XmlTextReader(new StringReader(content))) {
try {
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
NodeWrapper node = new NodeWrapper() {
ElementName = reader.LocalName,
Line = reader.LineNumber,
Column = reader.LinePosition,
EndColumn = -1,
EndLine = -1,
Children = new List<NodeWrapper>()
};
if (reader.HasAttributes) {
string name = reader.GetAttribute("Name");
if (name == null)
name = reader.GetAttribute("Name", CompletionDataHelper.XamlNamespace);
if (name != null)
node.Name = name;
}
if (root == null) {
root = node;
nodes.Push(root);
} else {
if (nodes.Count > 0)
nodes.Peek().Children.Add(node);
if (!reader.IsEmptyElement)
nodes.Push(node);
}
break;
case XmlNodeType.EndElement:
if (nodes.Count > 1) {
NodeWrapper n = nodes.Pop();
n.EndLine = reader.LineNumber;
n.EndColumn = reader.LinePosition;
}
break;
}
}
} catch (XmlException) {
return;
}
WorkbenchSingleton.SafeThreadCall(() => UpdateTree(root));
}
}
void UpdateTree(NodeWrapper root)
{
if (this.treeView.Root == null)
this.treeView.Root = BuildNode(root);
else {
UpdateNode(this.treeView.Root as XamlOutlineNode, root);
}
}
void UpdateNode(XamlOutlineNode node, NodeWrapper dataNode)
{
if (dataNode != null && node != null) {
node.Name = dataNode.Name;
node.ElementName = dataNode.ElementName;
node.Marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(dataNode.Line, dataNode.Column));
ITextAnchor marker = null;
if (dataNode.EndLine != -1 && dataNode.EndColumn != -1) {
marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(dataNode.EndLine, dataNode.EndColumn));
}
node.EndMarker = marker;
int childrenCount = node.Children.Count;
int dataCount = dataNode.Children.Count;
for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) {
if (i >= childrenCount) {
node.Children.Add(BuildNode(dataNode.Children[i]));
} else if (i >= dataCount) {
while (node.Children.Count > dataCount)
node.Children.RemoveAt(dataCount);
} else {
UpdateNode(node.Children[i] as XamlOutlineNode, dataNode.Children[i]);
}
}
}
}
XamlOutlineNode BuildNode(NodeWrapper item)
{
ITextAnchor marker = null;
if (item.EndLine != -1 && item.EndColumn != -1) {
marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(item.EndLine, item.EndColumn));
}
XamlOutlineNode node = new XamlOutlineNode() {
Name = item.Name,
ElementName = item.ElementName,
ShowIcon = false,
Marker = editor.Document.CreateAnchor(editor.Document.PositionToOffset(item.Line, item.Column)),
EndMarker = marker,
Editor = editor
};
foreach (var child in item.Children)
node.Children.Add(BuildNode(child));
return node;
}
void TreeViewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
XamlOutlineNode node = treeView.SelectedItem as XamlOutlineNode;
int offset = editor.Document.PositionToOffset(node.Marker.Line, node.Marker.Column);
int endOffset = node.GetEndOffset();
editor.Select(offset - 1, endOffset - offset);
}
public object OutlineContent {
get {
return this;
}
}
}
class NodeWrapper {
public string ElementName { get; set; }
public string Name { get; set; }
public int Line { get; set; }
public int Column { get; set; }
public int EndLine { get; set; }
public int EndColumn { get; set; }
public IList<NodeWrapper> Children { get; set; }
}
class XamlOutlineNode : SharpTreeNode {
string elementName, name;
public string ElementName {
get { return elementName; }
set {
this.elementName = value;
this.RaisePropertyChanged("Text");
}
}
public string Name {
get { return name; }
set {
this.name = value;
this.RaisePropertyChanged("Text");
}
}
public ITextAnchor Marker { get; set; }
public ITextAnchor EndMarker { get; set; }
public ITextEditor Editor { get; set; }
public XamlOutlineNode Successor {
get {
if (this.Parent == null)
return null;
int index = this.Parent.Children.IndexOf(this);
if (index + 1 < this.Parent.Children.Count)
return this.Parent.Children[index + 1] as XamlOutlineNode;
else
return null;
}
}
public override bool CanDrag(SharpTreeNode[] nodes)
{
return nodes.All(node => node.Parent != null);
}
public override DropEffect CanDrop(IDataObject data, DropEffect requestedEffect)
{
return DropEffect.Move;
}
public override bool CanCopy(SharpTreeNode[] nodes)
{
return true;
}
public int GetEndOffset()
{
if (EndMarker != null) {
return EndMarker.Offset + ElementName.Length + 2;
} else {
XamlOutlineNode successor = Successor;
if (successor != null) {
return successor.Marker.Offset;
} else {
XamlOutlineNode parent = Parent as XamlOutlineNode;
if (parent != null)
return parent.EndMarker.Offset - 1;
}
}
return Editor.Document.TextLength + 1;
}
public string GetMarkupText()
{
int offset = Editor.Document.PositionToOffset(Marker.Line, Marker.Column);
return Editor.Document.GetText(offset - 1, GetEndOffset() - offset);
}
public override IDataObject Copy(SharpTreeNode[] nodes)
{
string[] data = nodes
.OfType<XamlOutlineNode>()
.Select(item => item.GetMarkupText())
.ToArray();
var dataObject = new DataObject();
dataObject.SetData(typeof(string[]), data);
return dataObject;
}
public override bool CanDelete(SharpTreeNode[] nodes)
{
return nodes.All(node => node.Parent != null);
}
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
{
try {
string insertText = (data.GetData(typeof(string[])) as string[])
.Aggregate((text, part) => text += part);
ITextAnchor marker;
int length = 0;
if (index == this.Children.Count) {
if (index == 0)
marker = null;
else
marker = (this.Children[index - 1] as XamlOutlineNode).EndMarker;
if (marker == null) {
marker = this.EndMarker;
length = -1; // move backwards
} else {
length = 2 + (this.Children[index - 1] as XamlOutlineNode).elementName.Length;
}
} else
marker = (this.Children[index] as XamlOutlineNode).Marker;
int offset = marker.Offset + length;
Editor.Document.Insert(offset - 1, insertText);
} catch (Exception ex) {
throw ex;
}
}
public override void Delete(SharpTreeNode[] nodes)
{
DeleteCore(nodes);
}
public override void DeleteCore(SharpTreeNode[] nodes)
{
foreach (XamlOutlineNode node in nodes.OfType<XamlOutlineNode>()) {
node.Editor.Document.Remove(node.Marker.Offset - 1, node.GetEndOffset() - node.Marker.Offset);
}
}
ContextMenu menu;
public override ContextMenu GetContextMenu()
{
if (menu == null) {
menu = new ContextMenu();
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Cut });
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Copy });
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Paste });
menu.Items.Add(new Separator());
menu.Items.Add(new MenuItem() { Command = ApplicationCommands.Delete });
}
return menu;
}
public override object Text {
get { return (!string.IsNullOrEmpty(Name) ? ElementName + " (" + Name + ")" : ElementName); }
}
}
}

4
src/Libraries/SharpTreeView/ICSharpCode.TreeView/Properties/AssemblyInfo.cs

@ -46,6 +46,6 @@ using System.Windows.Markup;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: XmlnsPrefix("http://sharpdevelop.net", "sd")] [assembly: XmlnsPrefix("http://icsharpcode.net/sharpdevelop/treeview", "treeview")]
[assembly: XmlnsDefinition("http://sharpdevelop.net", "ICSharpCode.TreeView")] [assembly: XmlnsDefinition("http://icsharpcode.net/sharpdevelop/treeview", "ICSharpCode.TreeView")]

11
src/Libraries/SharpTreeView/ICSharpCode.TreeView/SharpTreeNode.cs

@ -148,6 +148,17 @@ namespace ICSharpCode.TreeView
} }
} }
bool showIcon;
public bool ShowIcon
{
get { return showIcon; }
set {
showIcon = value;
RaisePropertyChanged("ShowIcon");
}
}
public virtual void LoadChildren() public virtual void LoadChildren()
{ {
} }

6
src/Libraries/SharpTreeView/ICSharpCode.TreeView/Themes/Generic.xaml

@ -273,6 +273,12 @@
Property="Visibility" Property="Visibility"
Value="Collapsed" /> Value="Collapsed" />
</DataTrigger> </DataTrigger>
<DataTrigger Binding="{Binding ShowIcon}"
Value="False">
<Setter TargetName="icon"
Property="Visibility"
Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsExpanded}" <DataTrigger Binding="{Binding IsExpanded}"
Value="True"> Value="True">
<Setter TargetName="icon" <Setter TargetName="icon"

2
src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.SharpDevelop.Gui
return; return;
} }
} }
contentControl.SetContent(StringParser.Parse("${res:SharpDevelop.SideBar.NoOutlineContentAvailableForCurrentDocument}")); contentControl.SetContent(StringParser.Parse("${res:MainWindow.Windows.OutlinePad.NoContentAvailable}"));
} }
} }
} }

Loading…
Cancel
Save