diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs index 02e475a54b..4409fe4d6d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs @@ -5,26 +5,21 @@ // $Revision$ // -using ICSharpCode.AvalonEdit.Document; using System; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; +using System.Collections.ObjectModel; using System.Linq; -using System.Xml; + using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor.CodeCompletion; -using ICSharpCode.SharpDevelop.Project; using ICSharpCode.XmlEditor; -using LoggingService = ICSharpCode.Core.LoggingService; namespace ICSharpCode.XamlBinding { public static class CompletionDataHelper { - #region Pre-defined lists static readonly List standardElements = new List { new SpecialCompletionItem("!--"), new SpecialCompletionItem("![CDATA["), @@ -43,16 +38,15 @@ namespace ICSharpCode.XamlBinding new SpecialCompletionItem("xmlns:") }; - public static readonly List XamlNamespaceAttributes = new List { + public static readonly ReadOnlyCollection XamlNamespaceAttributes = new List { "Class", "ClassModifier", "FieldModifier", "Name", "Subclass", "TypeArguments", "Uid", "Key" - }; + }.AsReadOnly(); // TODO : .AsReadOnly() cannot be resolved, report to Daniel - public static readonly List RootOnlyElements = new List { + public static readonly ReadOnlyCollection RootOnlyElements = new List { "Class", "ClassModifier", "Subclass" - }; + }.AsReadOnly(); static readonly List emptyList = new List(); - #endregion public const string XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml"; public const string WpfXamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; @@ -73,22 +67,16 @@ namespace ICSharpCode.XamlBinding AttributeValue value = MarkupExtensionParser.ParseValue(attributeValue); XamlContextDescription description = XamlContextDescription.None; - Dictionary xmlnsDefs; - List ignoredXmlns; - QualifiedNameWithLocation active, parent; - int elementStartIndex; - bool isRoot; - - Utils.LookUpInfoAtTarget(text, line, col, offset, out xmlnsDefs, out ignoredXmlns, out active, out parent, out elementStartIndex, out isRoot); + var lookUpInfo = Utils.LookupInfoAtTarget(text, line, col, offset); string wordBeforeIndex = text.GetWordBeforeOffset(offset); - if (active != null && parent != active) + if (lookUpInfo.Active != null && lookUpInfo.Parent != lookUpInfo.Active) description = XamlContextDescription.AtTag; - if (elementStartIndex > -1 && + if (lookUpInfo.ActiveElementStartIndex > -1 && (char.IsWhiteSpace(text[offset]) || !string.IsNullOrEmpty(attribute) || - Extensions.Is(text[offset], '"', '\'') || !wordBeforeIndex.StartsWith("<"))) + Extensions.Is(text[offset], '"', '\'') || !wordBeforeIndex.StartsWith("<", StringComparison.OrdinalIgnoreCase))) description = XamlContextDescription.InTag; if (inAttributeValue) { @@ -115,22 +103,22 @@ namespace ICSharpCode.XamlBinding localName = attribute.Substring(prefixEnd + 1, attribute.Length - prefix.Length - 1); } - xmlnsDefs.TryGetValue(prefix, out xmlNamespace); + lookUpInfo.XmlnsDefinitions.TryGetValue(prefix, out xmlNamespace); var qAttribute = new QualifiedNameWithLocation(localName, xmlNamespace, prefix, -1, -1); var context = new XamlContext() { Description = description, - ActiveElement = active, - ParentElement = parent, + ActiveElement = lookUpInfo.Active, + ParentElement = lookUpInfo.Parent, AttributeName = string.IsNullOrEmpty(attribute) ? null : qAttribute, - InRoot = isRoot, + InRoot = lookUpInfo.IsRoot, AttributeValue = value, RawAttributeValue = attributeValue, ValueStartOffset = offsetFromValueStart, - XmlnsDefinitions = xmlnsDefs, + XmlnsDefinitions = lookUpInfo.XmlnsDefinitions, ParseInformation = info, - IgnoredXmlns = ignoredXmlns + IgnoredXmlns = lookUpInfo.IgnoredXmlns.AsReadOnly() }; return context; @@ -164,8 +152,8 @@ namespace ICSharpCode.XamlBinding if (xamlBuiltInTypes.Concat(XamlNamespaceAttributes).Select(s => xKey + s).Contains(lastElement.FullXmlName)) return emptyList; - if (lastElement.Name.EndsWith(".") || context.PressedKey == '.') { - if (context.ParentElement.Name.StartsWith(lastElement.Name.TrimEnd('.'))) + if (lastElement.Name.EndsWith(".", StringComparison.OrdinalIgnoreCase) || context.PressedKey == '.') { + if (context.ParentElement.Name.StartsWith(lastElement.Name.TrimEnd('.'), StringComparison.OrdinalIgnoreCase)) AddAttributes(rt, list, includeEvents); else if (rt != null && rt.GetUnderlyingClass() != null) { string key = string.IsNullOrEmpty(lastElement.Prefix) ? "" : lastElement.Prefix + ":"; @@ -308,7 +296,7 @@ namespace ICSharpCode.XamlBinding bool inContentRoot = false; if (last != null && cu != null) { - if (!last.Name.Contains(".") || last.Name.EndsWith(".")) { + if (!last.Name.Contains(".") || last.Name.EndsWith(".", StringComparison.OrdinalIgnoreCase)) { elementReturnType = rt = cu.CreateType(last.Namespace, last.Name.Trim('.')); string contentPropertyName = GetContentPropertyName(rt); if (!string.IsNullOrEmpty(contentPropertyName)) { @@ -434,7 +422,6 @@ namespace ICSharpCode.XamlBinding } break; case XamlContextDescription.InTag: - var existingAttribs = Utils.GetListOfExistingAttributeNames(editor.Document.Text, editor.Caret.Line, editor.Caret.Column); string word = context.Editor.GetWordBeforeCaretExtended(); if (context.PressedKey == '.') { @@ -471,14 +458,14 @@ namespace ICSharpCode.XamlBinding { if (context.ParentElement != null && !context.InRoot) { ResolveResult rr = XamlResolver.Resolve(context.ParentElement.FullXmlName, context); + TypeResolveResult trr = rr as TypeResolveResult; + MemberResolveResult mrr = rr as MemberResolveResult; - if (rr is TypeResolveResult) { - TypeResolveResult trr = rr as TypeResolveResult; + if (trr != null) { if (trr.ResolvedClass == null) return; list.Items.Add(new XamlCodeCompletionItem("/" + context.ParentElement.FullXmlName, trr.ResolvedClass)); - } else if (rr is MemberResolveResult) { - MemberResolveResult mrr = rr as MemberResolveResult; + } else if (mrr != null) { if (mrr.ResolvedMember == null) return; list.Items.Add(new XamlCodeCompletionItem("/" + context.ParentElement.FullXmlName, mrr.ResolvedMember)); @@ -530,12 +517,12 @@ namespace ICSharpCode.XamlBinding static void DoNamedArgsCompletion(XamlCompletionItemList list, XamlCompletionContext context, IReturnType type, MarkupExtensionInfo markup) { - if (markup.NamedArguments.Count > 0 && !context.Editor.GetWordBeforeCaret().StartsWith(",")) { + if (markup.NamedArguments.Count > 0 && !context.Editor.GetWordBeforeCaret().StartsWith(",", StringComparison.OrdinalIgnoreCase)) { int lastStart = markup.NamedArguments.Max(i => i.Value.StartOffset); var item = markup.NamedArguments.First(p => p.Value.StartOffset == lastStart); - if (context.RawAttributeValue.EndsWith("=") || - (item.Value.IsString && item.Value.StringValue.EndsWith(context.Editor.GetWordBeforeCaretExtended()))) { + if (context.RawAttributeValue.EndsWith("=", StringComparison.OrdinalIgnoreCase) || + (item.Value.IsString && item.Value.StringValue.EndsWith(context.Editor.GetWordBeforeCaretExtended(), StringComparison.Ordinal))) { MemberResolveResult mrr = XamlResolver.ResolveMember(item.Key, context) as MemberResolveResult; if (mrr != null && mrr.ResolvedMember != null && mrr.ResolvedMember.ReturnType != null) { IReturnType memberType = mrr.ResolvedMember.ReturnType; diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs index ae9d9abf96..9c1fd28e57 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Extensions.cs @@ -33,7 +33,7 @@ namespace ICSharpCode.XamlBinding return element; } - public static XElement MoveBefore(this XElement element, XElement target) + public static XElement MoveBefore(this XElement element, XNode target) { if (element == null) throw new ArgumentNullException("element"); @@ -47,7 +47,7 @@ namespace ICSharpCode.XamlBinding return element; } - public static XElement MoveAfter(this XElement element, XElement target) + public static XElement MoveAfter(this XElement element, XNode target) { if (element == null) throw new ArgumentNullException("element"); @@ -61,10 +61,10 @@ namespace ICSharpCode.XamlBinding return element; } - public static void AddRange(this UIElementCollection coll, IEnumerable items) + public static void AddRange(this UIElementCollection collection, IEnumerable items) { foreach (var item in items) - coll.Add(item); + collection.Add(item); } public static string[] Split(this string thisValue, StringSplitOptions options, params char[] delimiters) @@ -88,24 +88,24 @@ namespace ICSharpCode.XamlBinding return false; } - public static string Replace(this string str, int index, int length, string text) + public static string Replace(this string thisValue, int index, int length, string text) { - if (str == null) - throw new ArgumentNullException("str"); - if (index < 0 || index > str.Length) - throw new ArgumentOutOfRangeException("index", index, "Value must be between 0 and " + str.Length); - if (length < 0 || length > str.Length) - throw new ArgumentOutOfRangeException("length", length, "Value must be between 0 and " + str.Length); - if ((index + length) > str.Length) - throw new ArgumentOutOfRangeException("index + length", index + length, "Value must be between 0 and " + str.Length); + if (thisValue == null) + throw new ArgumentNullException("thisValue"); + if (index < 0 || index > thisValue.Length) + throw new ArgumentOutOfRangeException("index", index, "Value must be between 0 and " + thisValue.Length); + if (length < 0 || length > thisValue.Length) + throw new ArgumentOutOfRangeException("length", length, "Value must be between 0 and " + thisValue.Length); + if ((index + length) > thisValue.Length) + throw new ArgumentOutOfRangeException("index + length", index + length, "Value must be between 0 and " + thisValue.Length); - return str.Substring(0, index) + text + str.Substring(index + length); + return thisValue.Substring(0, index) + text + thisValue.Substring(index + length); } - public static bool Is(char value, params char[] chars) + public static bool Is(char value, params char[] choice) { - foreach (var c in chars) { - if (c == value) + foreach (var ch in choice) { + if (ch == value) return true; } @@ -175,9 +175,9 @@ namespace ICSharpCode.XamlBinding return text.Substring(startIndex, offset - startIndex + 1).Trim(); } - public static TKey GetKeyByValue(this Dictionary dict, TValue value) + public static TKey GetKeyByValue(this Dictionary thisValue, TValue value) { - foreach (var pair in dict) { + foreach (var pair in thisValue) { if (pair.Value.Equals(value)) return pair.Key; } @@ -185,22 +185,22 @@ namespace ICSharpCode.XamlBinding return default(TKey); } - public static int GetLineNumber(this XObject item) + public static int GetLineNumber(this IXmlLineInfo thisValue) { - return (item as IXmlLineInfo).LineNumber; + return thisValue.LineNumber; } - public static int GetLinePosition(this XObject item) + public static int GetLinePosition(this IXmlLineInfo thisValue) { - return (item as IXmlLineInfo).LinePosition; + return thisValue.LinePosition; } - public static bool IsInRange(this XObject item, Location begin, Location end) + public static bool IsInRange(this IXmlLineInfo item, Location begin, Location end) { return IsInRange(item, begin.Line, begin.Column, end.Line, end.Column); } - public static bool IsInRange(this XObject item, int beginLine, int beginColumn, int endLine, int endColumn) + public static bool IsInRange(this IXmlLineInfo item, int beginLine, int beginColumn, int endLine, int endColumn) { if (item.GetLineNumber() >= beginLine && item.GetLineNumber() <= endLine) { if (item.GetLineNumber() == beginLine) { @@ -215,11 +215,11 @@ namespace ICSharpCode.XamlBinding return false; } - public static bool IsCollectionType(this IClass c) + public static bool IsCollectionType(this IClass thisValue) { - if (c == null) - throw new ArgumentNullException("c"); - return c.ClassInheritanceTree.Any(cla => cla.FullyQualifiedName == "System.Collections.ICollection"); + if (thisValue == null) + throw new ArgumentNullException("thisValue"); + return thisValue.ClassInheritanceTree.Any(cla => cla.FullyQualifiedName == "System.Collections.ICollection"); } public static bool IsCollectionReturnType(this IReturnType type) @@ -232,11 +232,11 @@ namespace ICSharpCode.XamlBinding return false; } - public static bool IsListType(this IClass c) + public static bool IsListType(this IClass thisValue) { - if (c == null) - throw new ArgumentNullException("c"); - return c.ClassInheritanceTree.Any(cla => cla.FullyQualifiedName == "System.Collections.IList"); + if (thisValue == null) + throw new ArgumentNullException("thisValue"); + return thisValue.ClassInheritanceTree.Any(cla => cla.FullyQualifiedName == "System.Collections.IList"); } public static bool IsListReturnType(this IReturnType type) @@ -250,9 +250,9 @@ namespace ICSharpCode.XamlBinding } /// Works only if fullyQualyfiedClassName is the name of a class! - public static bool DerivesFrom(this IClass myClass, string fullyQualyfiedClassName) + public static bool DerivesFrom(this IClass myClass, string fullyQualifiedClassName) { - return myClass.ClassInheritanceTreeClassesOnly.Any(c => c.FullyQualifiedName == fullyQualyfiedClassName); + return myClass.ClassInheritanceTreeClassesOnly.Any(c => c.FullyQualifiedName == fullyQualifiedClassName); } public static T PopOrDefault(this Stack stack) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/LookupInfo.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/LookupInfo.cs new file mode 100644 index 0000000000..c6c3ab4fbe --- /dev/null +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/LookupInfo.cs @@ -0,0 +1,32 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.NRefactory; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Xml; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.XmlEditor; + +namespace ICSharpCode.XamlBinding +{ + public class LookupInfo { + public LookupInfo() { } + + public Dictionary XmlnsDefinitions { get; set; } + public List IgnoredXmlns { get; set; } + public QualifiedNameWithLocation Active { get; set; } + public QualifiedNameWithLocation Parent { get; set; } + public int ActiveElementStartIndex { get; set; } + public bool IsRoot { get; set; } + } +} diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs index b0c7f439b6..3bf2c6f9e0 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/EditGridColumnsAndRowsCommand.cs @@ -42,7 +42,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands EditGridColumnsAndRowsDialog dialog = new EditGridColumnsAndRowsDialog(selectedItem); if (dialog.ShowDialog() ?? false) { - selectedItem.ReplaceWith(dialog.GetConstructedTree()); + selectedItem.ReplaceWith(dialog.ConstructedTree); return true; } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/ExtractPropertiesAsStyleCommand.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/ExtractPropertiesAsStyleCommand.cs index 45bd81cca6..b8e0bec231 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/ExtractPropertiesAsStyleCommand.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/ExtractPropertiesAsStyleCommand.cs @@ -100,7 +100,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands // TODO : make the methods xmlns independent - XElement CreateStyle(string name, string targetType, IEnumerable entries) + static XElement CreateStyle(string name, string targetType, IEnumerable entries) { XElement style = new XElement(XName.Get("Style", CompletionDataHelper.WpfXamlNamespace)); if (!string.IsNullOrEmpty(name)) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/GroupIntoRefactorings.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/GroupIntoRefactorings.cs index e958a1f3b8..abcb78efd5 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/GroupIntoRefactorings.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Commands/GroupIntoRefactorings.cs @@ -102,7 +102,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Commands { public abstract ICollection BuildItems(Codon codon, object owner); - protected MenuItem CreateItem(string header, Action clickAction) + protected static MenuItem CreateItem(string header, Action clickAction) { MenuItem item = new MenuItem() { Header = header }; item.Click += new RoutedEventHandler(delegate { clickAction(); }); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs index f4fb719c20..89c6cc08e5 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/Dialogs/EditGridColumnsAndRowsDialog.xaml.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; using System.Text; using System.Windows; @@ -62,11 +63,6 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs AdditionalProperties = propertiesCopy }; } - - public static UndoStep Copy(UndoStep original) - { - return CreateStep(original.Tree, original.RowDefinitions, original.ColumnDefinitions, original.AdditionalProperties); - } } Stack undoStack; @@ -138,7 +134,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1); + item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); @@ -176,7 +172,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1); + item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); @@ -229,14 +225,14 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) - 1); + item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) - 1); } ); controlsDown.ForEach( item2 => { var rowAttrib = item2.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item2.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1); + item2.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); @@ -290,14 +286,14 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) + 1); + item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); controlsUp.ForEach( item2 => { var rowAttrib = item2.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item2.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) - 1); + item2.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) - 1); } ); @@ -331,7 +327,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var rowAttrib = item.Attribute(XName.Get("Grid.Row")) ?? new XAttribute(XName.Get("Grid.Row"), 0); - item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value) - 1); + item.SetAttributeValue(XName.Get("Grid.Row"), int.Parse(rowAttrib.Value, CultureInfo.InvariantCulture) - 1); } ); @@ -368,7 +364,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1); + item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); @@ -405,7 +401,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1); + item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); @@ -459,14 +455,14 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) - 1); + item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) - 1); } ); controlsLeft.ForEach( item2 => { var colAttrib = item2.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item2.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1); + item2.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); @@ -521,14 +517,14 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) + 1); + item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) + 1); } ); controlsRight.ForEach( item2 => { var colAttrib = item2.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item2.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) - 1); + item2.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) - 1); } ); @@ -562,7 +558,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs controls.ForEach( item => { var colAttrib = item.Attribute(XName.Get("Grid.Column")) ?? new XAttribute(XName.Get("Grid.Column"), 0); - item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value) - 1); + item.SetAttributeValue(XName.Get("Grid.Column"), int.Parse(colAttrib.Value, CultureInfo.InvariantCulture) - 1); } ); @@ -702,7 +698,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs Point p = e.GetPosition(target); TextBlock block = target.InputHitTest(p) as TextBlock; - + if (block != null) { Debug.Assert(block.Tag != null && block.Tag is XElement); XElement element = block.Tag as XElement; @@ -756,7 +752,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs label.MouseLeftButtonDown += new MouseButtonEventHandler(LabelMouseLeftButtonDown); - Debug.Assert(label.Tag != null); + Debug.Assert(label.Tag != null); yield return label; } @@ -765,7 +761,8 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs void LabelMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragDropEffects allowedEffects = DragDropEffects.Move; - DragDrop.DoDragDrop(sender as Label, (sender as Label).Tag, allowedEffects); + Label label = sender as Label; + DragDrop.DoDragDrop(label, label.Tag, allowedEffects); } void UpdateUndoRedoState() @@ -774,13 +771,15 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs this.redoStack.Clear(); } - public XElement GetConstructedTree() + public XElement ConstructedTree { - gridTree.AddFirst(additionalProperties); - gridTree.AddFirst(colDefitions); - gridTree.AddFirst(rowDefitions); - - return gridTree; + get { + gridTree.AddFirst(additionalProperties); + gridTree.AddFirst(colDefitions); + gridTree.AddFirst(rowDefitions); + + return gridTree; + } } void DisplayRectContextMenuOpening(object sender, ContextMenuEventArgs e) @@ -859,7 +858,7 @@ namespace ICSharpCode.XamlBinding.PowerToys.Dialogs } void BtnDeleteItemClick(object sender, RoutedEventArgs e) - { + { Button source = sender as Button; XElement item = source.Tag as XElement; if (item != null) { diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs index e10ef5ee04..5564d4f8ae 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/PowerToys/XamlMenuCommand.cs @@ -5,17 +5,19 @@ // $Revision$ // -using ICSharpCode.XmlEditor; using System; +using System.Globalization; using System.IO; using System.Windows.Forms; using System.Xaml; using System.Xml; using System.Xml.Linq; + using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.XmlEditor; namespace ICSharpCode.XamlBinding.PowerToys { @@ -38,7 +40,7 @@ namespace ICSharpCode.XamlBinding.PowerToys document.Declaration = null; if (Refactor(provider.TextEditor, document)) { using (provider.TextEditor.Document.OpenUndoGroup()) { - StringWriter sWriter = new StringWriter(); + StringWriter sWriter = new StringWriter(CultureInfo.InvariantCulture); XmlWriter writer = XmlWriter.Create(sWriter, CreateSettings()); document.WriteTo(writer); writer.Flush(); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/QualifiedNameWithLocation.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/QualifiedNameWithLocation.cs index 0b070d303e..249324ec1d 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/QualifiedNameWithLocation.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/QualifiedNameWithLocation.cs @@ -68,13 +68,13 @@ namespace ICSharpCode.XamlBinding return Name.GetHashCode() ^ Location.GetHashCode(); } - public bool Equals(QualifiedNameWithLocation obj) + public bool Equals(QualifiedNameWithLocation other) { - if (obj == null) + if (other == null) return false; - return obj.QualifiedName == QualifiedName && - obj.Location == Location; + return other.QualifiedName == QualifiedName && + other.Location == Location; } public static bool operator ==(QualifiedNameWithLocation lhs, QualifiedNameWithLocation rhs) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs index 7d7745cc74..37300c0a91 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs @@ -250,14 +250,12 @@ namespace ICSharpCode.XamlBinding public QualifiedNameWithLocation Item { get; set; } } - public static void LookUpInfoAtTarget(string fileContent, int caretLine, int caretColumn, int offset, - out Dictionary xmlns, out List ignoredXmlns, out QualifiedNameWithLocation active, - out QualifiedNameWithLocation parent, out int activeElementStartIndex, out bool isRoot) + public static LookupInfo LookupInfoAtTarget(string fileContent, int caretLine, int caretColumn, int offset) { Stack stack = new Stack(); Stack ignoredXmlnsStack = new Stack(); - isRoot = false; + var isRoot = false; XmlTextReader r = new XmlTextReader(new StringReader(fileContent)); r.XmlResolver = null; @@ -266,8 +264,9 @@ namespace ICSharpCode.XamlBinding ' ', '\t', '\n', '\r' }; - ignoredXmlns = new List(); - + var ignoredXmlns = new List(); + Dictionary xmlns; + try { r.WhitespaceHandling = WhitespaceHandling.Significant; // move reader to correct position @@ -306,10 +305,10 @@ namespace ICSharpCode.XamlBinding xmlns = new Dictionary(r.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)); } - activeElementStartIndex = XmlParser.GetActiveElementStartIndex(fileContent, Math.Min(offset + 1, fileContent.Length - 1)); + var activeElementStartIndex = XmlParser.GetActiveElementStartIndex(fileContent, Math.Min(offset + 1, fileContent.Length - 1)); - active = ResolveCurrentElement(fileContent, activeElementStartIndex, xmlns); - parent = stack.PopOrDefault(); + var active = ResolveCurrentElement(fileContent, activeElementStartIndex, xmlns); + var parent = stack.PopOrDefault(); if (active == parent) parent = stack.PopOrDefault(); @@ -319,6 +318,15 @@ namespace ICSharpCode.XamlBinding if (active == null) active = parent; + + return new LookupInfo() { + Active = active, + ActiveElementStartIndex = activeElementStartIndex, + IgnoredXmlns = ignoredXmlns, + IsRoot = isRoot, + Parent = parent, + XmlnsDefinitions = xmlns + }; } public static XmlTextReader CreateReaderAtTarget(string fileContent, int caretLine, int caretColumn) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj index cf6b846d95..f5194d3864 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj @@ -66,6 +66,7 @@ Properties\GlobalAssemblyInfo.cs + MarkupExtensionTokenizer.cs diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs index 49001c0d02..3bd55e2fda 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.XamlBinding case '{': // starting point for Markup Extension Completion if (context.AttributeName != null && XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset) - && !(context.RawAttributeValue.StartsWith("{}") && context.RawAttributeValue.Length != 2)) { + && !(context.RawAttributeValue.StartsWith("{}", StringComparison.OrdinalIgnoreCase) && context.RawAttributeValue.Length != 2)) { if (editor.SelectionLength != 0) editor.Document.Remove(editor.SelectionStart, editor.SelectionLength); @@ -97,7 +97,7 @@ namespace ICSharpCode.XamlBinding break; case ':': if (context.ActiveElement != null && XmlParser.GetQualifiedAttributeNameAtIndex(editor.Document.Text, editor.Caret.Offset) == null) { - if (context.AttributeName != null && !context.AttributeName.Name.StartsWith("xmlns")) { + if (context.AttributeName != null && !context.AttributeName.Name.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase)) { list = CompletionDataHelper.CreateListForContext(context); list.PreselectionLength = editor.GetWordBeforeCaretExtended().Length; editor.ShowCompletionWindow(list); @@ -143,7 +143,7 @@ namespace ICSharpCode.XamlBinding string attributeName = (context.AttributeName != null) ? context.AttributeName.Name : string.Empty; - if (!attributeName.StartsWith("xmlns")) + if (!attributeName.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase)) this.CtrlSpace(editor); trackForced = true; return CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion; @@ -174,8 +174,6 @@ namespace ICSharpCode.XamlBinding var mrr = XamlResolver.Resolve(context.AttributeName.FullXmlName, context) as MemberResolveResult; if (mrr != null && mrr.ResolvedType != null) { - var c = mrr.ResolvedType.GetUnderlyingClass(); - completionList.Items.AddRange(CompletionDataHelper.MemberCompletion(context, mrr.ResolvedType, string.Empty)); editor.ShowInsightWindow(CompletionDataHelper.MemberInsight(mrr)); } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs index de9dd69f65..45a6e0348c 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlColorizer.cs @@ -103,7 +103,7 @@ namespace ICSharpCode.XamlBinding if (task.IsCancellationRequested) return; - if (!info.Token.StartsWith("xmlns")) { + if (!info.Token.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase)) { MemberResolveResult rr = new XamlResolver().Resolve(info.GetExpressionResult(), info.Context.ParseInformation, FileContent) as MemberResolveResult; member = (rr != null) ? rr.ResolvedMember : null; } @@ -148,7 +148,7 @@ namespace ICSharpCode.XamlBinding index += attribute.Substring(propertyNameIndex).Length; } if (context.Description != XamlContextDescription.InComment && !string.IsNullOrEmpty(attribute)) { - int startIndex = LineText.Substring(0, Math.Min(index, LineText.Length)).LastIndexOf(attribute); + int startIndex = LineText.Substring(0, Math.Min(index, LineText.Length)).LastIndexOf(attribute, StringComparison.Ordinal); if (startIndex >= 0) { if (propertyNameIndex > -1) infos.Add(new HighlightingInfo(attribute.Trim('/'), startIndex + propertyNameIndex + 1, startIndex + attribute.TrimEnd('/').Length, Offset, context)); @@ -226,7 +226,7 @@ namespace ICSharpCode.XamlBinding void ColorizeMember(HighlightingInfo info, DocumentLine line, IMember member) { - if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":"))) { + if (info.Context.IgnoredXmlns.Any(item => info.Token.StartsWith(item + ":", StringComparison.OrdinalIgnoreCase))) { ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightIgnored); } else { if (member != null) { @@ -235,7 +235,7 @@ namespace ICSharpCode.XamlBinding else ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightProperty); } else { - if (info.Token.StartsWith("xmlns") || info.Token.StartsWith(Utils.GetNamespacePrefix(CompletionDataHelper.MarkupCompatibilityNamespace, info.Context) + ":")) + if (info.Token.StartsWith("xmlns", StringComparison.OrdinalIgnoreCase) || info.Token.StartsWith(Utils.GetNamespacePrefix(CompletionDataHelper.MarkupCompatibilityNamespace, info.Context) + ":", StringComparison.OrdinalIgnoreCase)) ChangeLinePart(line.Offset + info.StartOffset, line.Offset + info.EndOffset, HighlightNamespaceDeclaration); else Core.LoggingService.Debug(info.Token + " not highlighted; line " + line.LineNumber); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs index df159b6cb7..b3428bccf3 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.XamlBinding if (string.IsNullOrEmpty(className) || className.Contains(".")) return null; - if (xmlNamespace.StartsWith("clr-namespace:")) { + if (xmlNamespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase)) { return CreateClrNamespaceType(this.ProjectContent, xmlNamespace, className); } else { return new XamlClassReturnType(this, xmlNamespace, className); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItem.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItem.cs index bc7e3cadd7..56395b052c 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItem.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItem.cs @@ -5,10 +5,12 @@ // $Revision: 3731 $ // -using ICSharpCode.Core; using System; +using System.Globalization; using System.Linq; using System.Text.RegularExpressions; + +using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; @@ -66,27 +68,6 @@ namespace ICSharpCode.XamlBinding this.name = name; this.Image = ClassBrowserIconService.Namespace; } - - public XamlCompletionItem(string @namespace, string name) - : base(name) - { - this.prefix = ""; - this.@namespace = @namespace; - this.name = name; - this.Image = ClassBrowserIconService.Namespace; - } - - public string Prefix { - get { return prefix; } - } - - public string Namespace { - get { return @namespace; } - } - - public string Name { - get { return name; } - } } class SpecialCompletionItem : DefaultCompletionItem @@ -196,19 +177,19 @@ namespace ICSharpCode.XamlBinding while (namePatternRegex.IsMatch(name)) { Match match = namePatternRegex.Match(name); - switch (match.Value.ToLowerInvariant()) { - case "%object%": + switch (match.Value.ToUpperInvariant()) { + case "%OBJECT%": if (char.IsUpper(match.Value[1])) - objectName = objectName.ToUpper()[0] + objectName.Substring(1, objectName.Length - 1); + objectName = objectName.ToUpperInvariant()[0] + objectName.Substring(1, objectName.Length - 1); else - objectName = objectName.ToLower()[0] + objectName.Substring(1, objectName.Length - 1); + objectName = objectName.ToLowerInvariant()[0] + objectName.Substring(1, objectName.Length - 1); name = name.Replace(match.Index, match.Length, objectName); break; - case "%event%": + case "%EVENT%": if (char.IsUpper(match.Value[1])) - eventName = eventName.ToUpper()[0] + eventName.Substring(1, eventName.Length - 1); + eventName = eventName.ToUpperInvariant()[0] + eventName.Substring(1, eventName.Length - 1); else - eventName = eventName.ToLower()[0] + eventName.Substring(1, eventName.Length - 1); + eventName = eventName.ToLowerInvariant()[0] + eventName.Substring(1, eventName.Length - 1); name = name.Replace(match.Index, match.Length, eventName); break; case "%%": @@ -234,10 +215,6 @@ namespace ICSharpCode.XamlBinding this.ctor = entity; } - public IMethod Ctor { - get { return ctor; } - } - string headerText; bool descriptionCreated; string description; @@ -276,10 +253,6 @@ namespace ICSharpCode.XamlBinding bool descriptionCreated; IMember member; - public IMember Member { - get { return member; } - } - public MemberInsightItem(IMember member, string insightText) { this.member = member; diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs index 1848a21908..a43cbbfca6 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs @@ -79,7 +79,7 @@ namespace ICSharpCode.XamlBinding int spaces = CountWhiteSpacesAtEnd(context.Editor.GetWordBeforeCaret()); int typeNameStart = markup.ExtensionType.IndexOf(':') + 1; - if (!word.EndsWith(",") && markup.ExtensionType.Substring(typeNameStart, markup.ExtensionType.Length - typeNameStart) != word) { + if (!word.EndsWith(",", StringComparison.OrdinalIgnoreCase) && markup.ExtensionType.Substring(typeNameStart, markup.ExtensionType.Length - typeNameStart) != word) { context.Editor.Document.Replace(context.Editor.Caret.Offset - spaces, spaces, ", "); oldOffset += (2 - spaces); } @@ -88,7 +88,7 @@ namespace ICSharpCode.XamlBinding } } - if (cItem.Text.EndsWith("=")) + if (cItem.Text.EndsWith("=", StringComparison.OrdinalIgnoreCase)) XamlCodeCompletionBinding.Instance.CtrlSpace(context.Editor); } } @@ -104,7 +104,6 @@ namespace ICSharpCode.XamlBinding } if (item is XamlCompletionItem && xamlContext.Description == XamlContextDescription.InTag) { - XamlCompletionItem xamlItem = item as XamlCompletionItem; context.Editor.Document.Insert(context.EndOffset, "=\"\""); context.Editor.Caret.Offset--; } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs index 88fcbb1ea1..f0085b27ad 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs @@ -5,15 +5,17 @@ // $Revision: 3731 $ // -using ICSharpCode.SharpDevelop.Editor; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Xml; + using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.XmlEditor; namespace ICSharpCode.XamlBinding @@ -29,7 +31,7 @@ namespace ICSharpCode.XamlBinding public Dictionary XmlnsDefinitions { get; set; } public ParseInformation ParseInformation { get; set; } public bool InRoot { get; set; } - public List IgnoredXmlns { get; set; } + public ReadOnlyCollection IgnoredXmlns { get; set; } public XamlContext() {}