From 693581e4855cfd1be091e44d524ca2a884a74415 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 27 Jul 2009 19:49:28 +0000 Subject: [PATCH] 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 --- AddIns/ICSharpCode.SharpDevelop.addin | 2 +- .../XamlBinding/CompletionDataHelper.cs | 36 +- .../XamlBinding/XamlBinding/Extensions.cs | 72 +++- .../Commands/EditGridColumnsAndRowsCommand.cs | 13 +- .../Dialogs/EditGridColumnsAndRowsDialog.xaml | 9 +- .../EditGridColumnsAndRowsDialog.xaml.cs | 83 +++- .../PowerToys/Dialogs/GridLengthEditor.xaml | 8 + .../Dialogs/GridLengthEditor.xaml.cs | 162 ++++++++ .../XamlBinding/PowerToys/XamlMenuCommand.cs | 4 +- .../XamlBinding/XamlBinding.csproj | 19 +- .../XamlBinding/XamlBinding/XamlColorizer.cs | 4 +- .../XamlBinding/XamlCompletionItemList.cs | 15 +- .../XamlBinding/XamlLanguageBinding.cs | 21 +- .../XamlBinding/XamlOutlineContentHost.xaml | 14 + .../XamlOutlineContentHost.xaml.cs | 355 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 4 +- .../ICSharpCode.TreeView/SharpTreeNode.cs | 11 + .../ICSharpCode.TreeView/Themes/Generic.xaml | 6 + .../Base/Project/Src/Gui/Pads/OutlinePad.cs | 2 +- 19 files changed, 762 insertions(+), 78 deletions(-) create mode 100644 src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml create mode 100644 src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/GridLengthEditor.xaml.cs create mode 100644 src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml create mode 100644 src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlOutlineContentHost.xaml.cs diff --git a/AddIns/ICSharpCode.SharpDevelop.addin b/AddIns/ICSharpCode.SharpDevelop.addin index 4f2cd6befc..5465a8e390 100644 --- a/AddIns/ICSharpCode.SharpDevelop.addin +++ b/AddIns/ICSharpCode.SharpDevelop.addin @@ -98,7 +98,7 @@ title = "${res:MainWindow.Windows.OutlinePad}" icon = "PadIcons.Toolbar" class = "ICSharpCode.SharpDevelop.Gui.OutlinePad" - defaultPosition = "Left" /> + defaultPosition = "Left, Hidden" /> item.Name == prefixClassName); if (c != null) { - if (!(c.IsAbstract && c.IsStatic + if (!(c.IsAbstract && !c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Attribute") && c.Methods.Any(m => m.IsConstructor && m.IsPublic))) { prefixNamespace = string.IsNullOrEmpty(prefixNamespace) ? prefixNamespace : prefixNamespace + ":"; @@ -879,10 +859,8 @@ namespace ICSharpCode.XamlBinding continue; if (!c.Methods.Any(m => m.IsConstructor && m.IsPublic)) continue; - if (properties) - AddAttachedProperties(c, result, key, string.Empty); - if (events) - AddAttachedEvents(c, result, key, string.Empty); + if (c.HasAttached(properties, events)) + result.Add(new XamlCodeCompletionItem(c, ns.Key)); } } } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs index 80651f2d2b..ed7bcd77ad 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs @@ -254,7 +254,77 @@ namespace ICSharpCode.XamlBinding return false; } - /// Works only if fullyQualyfiedClassName is the name of a class! + 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; + } + + /// Works only if fullyQualifiedClassName is the name of a class! public static bool DerivesFrom(this IClass myClass, string fullyQualifiedClassName) { return myClass.ClassInheritanceTreeClassesOnly.Any(c => c.FullyQualifiedName == fullyQualifiedClassName); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs index 3bf2c6f9e0..a71536f4f7 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs @@ -5,12 +5,13 @@ // $Revision$ // -using ICSharpCode.NRefactory; +using ICSharpCode.SharpDevelop.Gui; using System; -using System.Linq; using System.Collections.Generic; +using System.Linq; using System.Xml.Linq; using ICSharpCode.Core; +using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.XamlBinding.PowerToys.Dialogs; @@ -22,12 +23,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands public class EditGridColumnsAndRowsCommand : XamlMenuCommand { 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 endLoc = editor.Document.OffsetToPosition(editor.SelectionStart + editor.SelectionLength); @@ -40,6 +36,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands } EditGridColumnsAndRowsDialog dialog = new EditGridColumnsAndRowsDialog(selectedItem); + dialog.Owner = WorkbenchSingleton.MainWindow; if (dialog.ShowDialog() ?? false) { selectedItem.ReplaceWith(dialog.ConstructedTree); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml index 5ed8c2ba89..5bcebdf3dc 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sd="http://icsharpcode.net/sharpdevelop/core" Title="Edit grid columns and rows" Height="500" Width="500" + ShowInTaskbar="False" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">