From e978f7fbee2f70d2fc61208eb9ba6b7bf36861d6 Mon Sep 17 00:00:00 2001 From: Noam Wies Date: Wed, 26 Dec 2012 17:31:53 +0200 Subject: [PATCH 001/172] prepare goto class to support CamelHumps --- src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs index af431072f9..d681b47f59 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs @@ -274,7 +274,7 @@ namespace ICSharpCode.SharpDevelop.Gui foreach (IClass c in classes) { string className = c.Name; if (className.Length >= classPart.Length) { - if (className.IndexOf(classPart, StringComparison.OrdinalIgnoreCase) >= 0) { + if (CamelHumpsMatch(className,classPart)){ if (memberPart.Length > 0) { AddAllMembersMatchingText(c, memberPart, false); } else { @@ -286,6 +286,11 @@ namespace ICSharpCode.SharpDevelop.Gui } } + private bool CamelHumpsMatch(string entity,string entityPart) + { + return ((className.IndexOf(classPart, StringComparison.OrdinalIgnoreCase) >= 0) || (false)); + } + const int MatchType_NoMatch = -1; const int MatchType_ContainsMatch_CaseInsensitive = 0; const int MatchType_ContainsMatch = 1; From 5e0a0f44db6f5a1190d46ccfb2abb8299a30e70e Mon Sep 17 00:00:00 2001 From: Noam Wies Date: Wed, 26 Dec 2012 18:41:08 +0200 Subject: [PATCH 002/172] implement CamelHumpsAutoComplete move code to extention method add tests --- .../Project/Src/Gui/Dialogs/GotoDialog.cs | 9 +--- .../Base/Project/Src/Util/ExtensionMethods.cs | 12 +++++ .../ICSharpCode.SharpDevelop.Tests.csproj | 1 + .../Test/Utils/Tests/CamelHumpsMatchTests.cs | 49 +++++++++++++++++++ 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 src/Main/Base/Test/Utils/Tests/CamelHumpsMatchTests.cs diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs index d681b47f59..c0e69a02fa 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs @@ -274,7 +274,7 @@ namespace ICSharpCode.SharpDevelop.Gui foreach (IClass c in classes) { string className = c.Name; if (className.Length >= classPart.Length) { - if (CamelHumpsMatch(className,classPart)){ + if (className.AutoCompleteWithCamelHumpsMatch(classPart)){ if (memberPart.Length > 0) { AddAllMembersMatchingText(c, memberPart, false); } else { @@ -284,12 +284,7 @@ namespace ICSharpCode.SharpDevelop.Gui } AddClasses(classPart, memberPart, list, c.InnerClasses); } - } - - private bool CamelHumpsMatch(string entity,string entityPart) - { - return ((className.IndexOf(classPart, StringComparison.OrdinalIgnoreCase) >= 0) || (false)); - } + } const int MatchType_NoMatch = -1; const int MatchType_ContainsMatch_CaseInsensitive = 0; diff --git a/src/Main/Base/Project/Src/Util/ExtensionMethods.cs b/src/Main/Base/Project/Src/Util/ExtensionMethods.cs index 80699864ac..d31d4fb4a6 100644 --- a/src/Main/Base/Project/Src/Util/ExtensionMethods.cs +++ b/src/Main/Base/Project/Src/Util/ExtensionMethods.cs @@ -619,6 +619,18 @@ namespace ICSharpCode.SharpDevelop return newContent; } + public static bool AutoCompleteWithCamelHumpsMatch(this string entityName,string entityPartName) + { + string camelHumpsPrefix = new string(entityName.Where( c => Char.IsUpper(c)).Select( c => c ).ToArray()); + return entityName.AutoCompleteMatch(entityPartName) || camelHumpsPrefix.AutoCompleteMatch(entityPartName); + } + + public static bool AutoCompleteMatch(this string entityName,string entityPartName) + { + return (entityName.IndexOf(entityPartName, StringComparison.OrdinalIgnoreCase) >= 0); + } + + #region Dom, AST, Editor, Document public static Location GetStart(this DomRegion region) { diff --git a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj index a13dd8902e..18bdd2d84d 100644 --- a/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj +++ b/src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj @@ -129,6 +129,7 @@ + diff --git a/src/Main/Base/Test/Utils/Tests/CamelHumpsMatchTests.cs b/src/Main/Base/Test/Utils/Tests/CamelHumpsMatchTests.cs new file mode 100644 index 0000000000..ddac50ee0f --- /dev/null +++ b/src/Main/Base/Test/Utils/Tests/CamelHumpsMatchTests.cs @@ -0,0 +1,49 @@ +/* + * Created by SharpDevelop. + * User: Noam + * Date: 26/12/2012 + * Time: 17:52 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Globalization; +using NUnit.Framework; + +namespace ICSharpCode.SharpDevelop.Tests.Utils.Tests +{ + /// + /// Description of CamelHumpsMatchTests. + /// + [TestFixture] + public class CamelHumpsMatchTests + { + [Test] + public void EntityNameStartWithEntityPartName_ShouldReturnTrue() + { + bool result = "abc".AutoCompleteWithCamelHumpsMatch("ab"); + Assert.AreEqual(result,true); + } + + [Test] + public void EntityNameContainEntityPartName_ShouldReturnTrue() + { + bool result = "abc".AutoCompleteWithCamelHumpsMatch("b"); + Assert.AreEqual(result,true); + } + + [Test] + public void EntityNameDoesntContainEntityPartName_ShouldReturnFalse() + { + bool result = "abc".AutoCompleteWithCamelHumpsMatch("de"); + Assert.AreEqual(result,false); + } + + [Test] + public void EntityPartNameIsTheFirstLetterInWordsByCamelHumps_ShouldReturnTrue() + { + bool result = "AbcDefGh".AutoCompleteWithCamelHumpsMatch("AD"); + Assert.AreEqual(result,true); + } + } +} From 0fef7ecc2a134e74f827d548f34c66f97d17ab1c Mon Sep 17 00:00:00 2001 From: Noam Wies Date: Wed, 26 Dec 2012 19:46:14 +0200 Subject: [PATCH 003/172] add support for open files with CamelHumps --- src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs index c0e69a02fa..4e58648ea6 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/GotoDialog.cs @@ -300,7 +300,12 @@ namespace ICSharpCode.SharpDevelop.Gui return MatchType_NoMatch; int indexInsensitive = itemText.IndexOf(searchText, StringComparison.OrdinalIgnoreCase); if (indexInsensitive < 0) + { + if (itemText.AutoCompleteWithCamelHumpsMatch(searchText)) { + return MatchType_ContainsMatch_CaseInsensitive; + } return MatchType_NoMatch; + } // This is a case insensitive match int indexSensitive = itemText.IndexOf(searchText, StringComparison.Ordinal); if (itemText.Length == searchText.Length) { From 59cc3d04f16b91159c43a71bea959c2cc9a36588 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 15 Jun 2013 19:21:13 +0200 Subject: [PATCH 004/172] remove NotImplementedException --- .../ProjectResourcesComponentCodeDomSerializer.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesComponentCodeDomSerializer.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesComponentCodeDomSerializer.cs index a4c7a48faf..02d3ee7881 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesComponentCodeDomSerializer.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesComponentCodeDomSerializer.cs @@ -243,12 +243,11 @@ namespace ICSharpCode.FormsDesigner.Services static string CodeStatementToString(CodeStatement statement) { - throw new NotImplementedException(); -// CodeDomVerboseOutputGenerator outputGenerator = new CodeDomVerboseOutputGenerator(); -// using(StringWriter sw = new StringWriter(System.Globalization.CultureInfo.InvariantCulture)) { -// outputGenerator.PublicGenerateCodeFromStatement(statement, sw, null); -// return sw.ToString().TrimEnd(); -// } + CodeDomVerboseOutputGenerator outputGenerator = new CodeDomVerboseOutputGenerator(); + using(StringWriter sw = new StringWriter(System.Globalization.CultureInfo.InvariantCulture)) { + outputGenerator.PublicGenerateCodeFromStatement(statement, sw, null); + return sw.ToString().TrimEnd(); + } } } } From 89dc15437e19bc12805e8279494da4db0aafd098 Mon Sep 17 00:00:00 2001 From: Gregor Pacnik Date: Mon, 24 Jun 2013 13:26:33 +1000 Subject: [PATCH 005/172] properly handle VB.Net to CS LINQ where and select output --- .../PrettyPrinter/CSharp/CSharpOutputVisitor.cs | 17 +++++++++++++++-- .../Output/CSharp/VBNetToCSharpConverterTest.cs | 7 +++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs index 80cfbbdd33..cbbf324e9d 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs @@ -3187,9 +3187,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); return selectClause.Projection.AcceptVisitor(this, data); } - - public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause whereClause, object data) + + public override object TrackedVisitQueryExpressionSelectVBClause(QueryExpressionSelectVBClause queryExpressionSelectVBClause, object data) + { + outputFormatter.Space(); + outputFormatter.PrintToken(Tokens.Select); + outputFormatter.Space(); + foreach (var v in queryExpressionSelectVBClause.Variables) + { + v.AcceptVisitor(this, data); + } + return null; + } + + public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause whereClause, object data) { + outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Where); outputFormatter.Space(); return whereClause.Condition.AcceptVisitor(this, data); diff --git a/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs b/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs index e73d4fcde0..b63df2ee0a 100644 --- a/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs +++ b/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs @@ -914,6 +914,13 @@ static bool InitStaticVariableHelper(Microsoft.VisualBasic.CompilerServices.Stat @"var xml = new XElement(""A"", ""\"""");"); } + + [Test] + public void LinqQueryWhereSelect() + { + TestStatement(@"Dim value = From value In values Where value = ""someValue"" Select value", + @"var value = from value in values where value == ""someValue"" select value;"); + } [Test] public void SD2_1500a() { From 8a9b312dcf5ee3148fe0e4f043246765c60f3f3d Mon Sep 17 00:00:00 2001 From: Gregor Pacnik Date: Mon, 24 Jun 2013 13:30:16 +1000 Subject: [PATCH 006/172] handle VB.Net Axis LINQ syntax to CS conversion with tests --- .../CSharp/CSharpOutputVisitor.cs | 32 ++++++++++++++++++- .../CSharp/VBNetToCSharpConverterTest.cs | 20 ++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs index cbbf324e9d..cce25f8eb4 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs @@ -2400,7 +2400,37 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.CloseParenthesis); return null; } - + + public override object TrackedVisitXmlMemberAccessExpression(XmlMemberAccessExpression xmlMemberAccessExpression, object data) + { + xmlMemberAccessExpression.TargetObject.AcceptVisitor(this, data); + + switch (xmlMemberAccessExpression.AxisType) + { + case XmlAxisType.Element: + outputFormatter.PrintToken(Tokens.Dot); + outputFormatter.PrintText("Elements(\""); + outputFormatter.PrintText(xmlMemberAccessExpression.Identifier); + outputFormatter.PrintText("\")"); + break; + case XmlAxisType.Attribute: + outputFormatter.PrintToken(Tokens.Dot); + outputFormatter.PrintText("Attribute(\""); + outputFormatter.PrintText(xmlMemberAccessExpression.Identifier); + outputFormatter.PrintText("\").Value"); + break; + case XmlAxisType.Descendents: + outputFormatter.PrintToken(Tokens.Dot); + outputFormatter.PrintText("Descendants(\""); + outputFormatter.PrintText(xmlMemberAccessExpression.Identifier); + outputFormatter.PrintText("\")"); + break; + default: + throw new Exception("Invalid value for XmlAxisType"); + } + return null; + } + public override object TrackedVisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { outputFormatter.PrintIdentifier(identifierExpression.Identifier); diff --git a/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs b/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs index b63df2ee0a..aebb178470 100644 --- a/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs +++ b/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs @@ -915,6 +915,26 @@ static bool InitStaticVariableHelper(Microsoft.VisualBasic.CompilerServices.Stat } + [Test] + public void XmlLINQDescendants() + { + TestStatement(@"Dim element = someXml...", + @"var element = someXml.Descendants(""somename"");"); + } + [Test] + public void XmlLINQElements() + { + TestStatement(@"Dim element = someXml.", + @"var element = someXml.Elements(""somename"");"); + } + + [Test] + public void XmlLINQAttribute() + { + TestStatement(@"Dim value = someXml.@attr", + @"var value = someXml.Attribute(""attr"").Value;"); + } + [Test] public void LinqQueryWhereSelect() { From 8273535734d734bef5af0d12b151cc6242cbf678 Mon Sep 17 00:00:00 2001 From: Gregor Pacnik Date: Mon, 24 Jun 2013 13:31:22 +1000 Subject: [PATCH 007/172] handle VB.Net to CS conversion set attribute Axis syntax; replace assignment with call --- .../CSharp/CSharpOutputVisitor.cs | 24 ++++++++++++++++++- .../CSharp/VBNetToCSharpConverterTest.cs | 16 ++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs index cce25f8eb4..263d979b9b 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs @@ -2403,6 +2403,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public override object TrackedVisitXmlMemberAccessExpression(XmlMemberAccessExpression xmlMemberAccessExpression, object data) { + var parentAsAssignment = xmlMemberAccessExpression.Parent as AssignmentExpression; + var xmlMemberAccessExpressionOnLeftOfAssignment = parentAsAssignment != null && parentAsAssignment.Left == xmlMemberAccessExpression; + + // only output identifier expression if we are not overriding assignment with method call + if(!(xmlMemberAccessExpression.AxisType == XmlAxisType.Attribute && xmlMemberAccessExpressionOnLeftOfAssignment)) xmlMemberAccessExpression.TargetObject.AcceptVisitor(this, data); switch (xmlMemberAccessExpression.AxisType) @@ -2414,10 +2419,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintText("\")"); break; case XmlAxisType.Attribute: + if (!xmlMemberAccessExpressionOnLeftOfAssignment) + { outputFormatter.PrintToken(Tokens.Dot); outputFormatter.PrintText("Attribute(\""); outputFormatter.PrintText(xmlMemberAccessExpression.Identifier); outputFormatter.PrintText("\").Value"); + } + else + { + // we need to convert assignment to method call + return AstBuilder.ExpressionBuilder.Call( + xmlMemberAccessExpression.TargetObject, + "SetAttributeValue", + new PrimitiveExpression(xmlMemberAccessExpression.Identifier), + parentAsAssignment.Right); + } break; case XmlAxisType.Descendents: outputFormatter.PrintToken(Tokens.Dot); @@ -2502,7 +2519,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { - TrackVisit(assignmentExpression.Left, data); + var overrideExpression = TrackVisit(assignmentExpression.Left, data) as InvocationExpression; + if (overrideExpression != null) + { + TrackVisit(overrideExpression, data); + return null; + } if (this.prettyPrintOptions.AroundAssignmentParentheses) { outputFormatter.Space(); } diff --git a/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs b/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs index aebb178470..e33bfc08f7 100644 --- a/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs +++ b/src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs @@ -913,7 +913,6 @@ static bool InitStaticVariableHelper(Microsoft.VisualBasic.CompilerServices.Stat TestStatement(@"Dim xml = "", @"var xml = new XElement(""A"", ""\"""");"); } - [Test] public void XmlLINQDescendants() @@ -935,12 +934,27 @@ static bool InitStaticVariableHelper(Microsoft.VisualBasic.CompilerServices.Stat @"var value = someXml.Attribute(""attr"").Value;"); } + [Test] + public void XmlLINQAttributeSetConstant() + { + TestStatement(@"someElement.@someAttr = 8", + @"someElement.SetAttributeValue(""someAttr"", 8);"); + } + + [Test] + public void XmlLINQAttributeSetExpression() + { + TestStatement(@"someElement.@someAttr = string.Format(""{0}"", 19)", + @"someElement.SetAttributeValue(""someAttr"", string.Format(""{0}"", 19));"); + } + [Test] public void LinqQueryWhereSelect() { TestStatement(@"Dim value = From value In values Where value = ""someValue"" Select value", @"var value = from value in values where value == ""someValue"" select value;"); } + [Test] public void SD2_1500a() { From 5e93aa5f17b73379e92ea4667131dc3a7fa38636 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 7 Jul 2013 16:26:23 +0200 Subject: [PATCH 008/172] AvalonEdit: don't unnecessarily update the mouse cursor. --- .../ICSharpCode.AvalonEdit/Editing/TextArea.cs | 4 ++-- .../ICSharpCode.AvalonEdit/Rendering/TextView.cs | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs index 13a95958f1..34d245573b 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs @@ -966,14 +966,14 @@ namespace ICSharpCode.AvalonEdit.Editing protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - TextView.InvalidateCursor(); + TextView.InvalidateCursorIfMouseWithinTextView(); } /// protected override void OnKeyUp(KeyEventArgs e) { base.OnKeyUp(e); - TextView.InvalidateCursor(); + TextView.InvalidateCursorIfMouseWithinTextView(); } #endregion diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs index fb69a20c0d..a075f30b50 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs @@ -1165,7 +1165,7 @@ namespace ICSharpCode.AvalonEdit.Rendering } } } - InvalidateCursor(); + InvalidateCursorIfMouseWithinTextView(); return finalSize; } @@ -1636,6 +1636,15 @@ namespace ICSharpCode.AvalonEdit.Rendering } } + internal void InvalidateCursorIfMouseWithinTextView() + { + // Don't unnecessarily call Mouse.UpdateCursor() if the mouse is outside the text view. + // Unnecessary updates may cause the mouse pointer to flicker + // (e.g. if it is over a window border, it blinks between Resize and Normal) + if (this.IsMouseOver) + InvalidateCursor(); + } + /// protected override void OnQueryCursor(QueryCursorEventArgs e) { From 3c64d4f59aef3ff82bd66ac170a72aea00092621 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 14 Jul 2013 17:48:53 +0100 Subject: [PATCH 009/172] Fix build. --- .../Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs index 263d979b9b..4aac8c18aa 100644 --- a/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs @@ -3252,9 +3252,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause whereClause, object data) + public override object TrackedVisitQueryExpressionWhereClause(QueryExpressionWhereClause whereClause, object data) { - outputFormatter.Space(); + if (!outputFormatter.LastCharacterIsWhiteSpace) { + outputFormatter.Space(); + } outputFormatter.PrintToken(Tokens.Where); outputFormatter.Space(); return whereClause.Condition.AcceptVisitor(this, data); From 04f9916a3742cfacd241aad4a690087e70ba83a6 Mon Sep 17 00:00:00 2001 From: Satyajit Sarangi Date: Wed, 24 Jul 2013 13:32:01 -0700 Subject: [PATCH 010/172] Make members in LineNumberMargin protected so derived classes can specialize it and still use the same typeface, emSize & maxLineNumberLength --- .../ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs index 9fa87d555c..9d6fc258b1 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs @@ -29,8 +29,8 @@ namespace ICSharpCode.AvalonEdit.Editing TextArea textArea; - Typeface typeface; - double emSize; + protected Typeface typeface; + protected double emSize; /// protected override Size MeasureOverride(Size availableSize) @@ -114,7 +114,7 @@ namespace ICSharpCode.AvalonEdit.Editing return ReceiveWeakEvent(managerType, sender, e); } - int maxLineNumberLength = 1; + protected int maxLineNumberLength = 1; void OnDocumentLineCountChanged() { From 163450c285883494bc0b50382b0ed0e5d3c9b003 Mon Sep 17 00:00:00 2001 From: Linquize Date: Fri, 26 Jul 2013 23:12:47 +0800 Subject: [PATCH 011/172] If the newly created project is prior to .NET 4.5, set Platform to x86 instead of AnyCPU (32-bit preferred) Otherwise the compiled program will not run --- .../Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs b/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs index 148b8d5b4d..a90a60d10d 100644 --- a/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs +++ b/src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs @@ -114,7 +114,7 @@ namespace ICSharpCode.SharpDevelop.Project if (fx != null) UpdateAppConfig(fx); if (Project.OutputType != OutputType.Library) { - if (DotnetDetection.IsDotnet45Installed()) { + if (DotnetDetection.IsDotnet45Installed() && fx.IsBasedOn(TargetFramework.Net45)) { Project.SetProperty(null, Project.ActivePlatform, "Prefer32Bit", "True", PropertyStorageLocations.PlatformSpecific, true); } else { Project.SetProperty(null, Project.ActivePlatform, "PlatformTarget", "x86", PropertyStorageLocations.PlatformSpecific, true); From b1c44ece8733af3f267550fedb1aa829243a3367 Mon Sep 17 00:00:00 2001 From: Linquize Date: Fri, 26 Jul 2013 23:13:56 +0800 Subject: [PATCH 012/172] Show AnyCPU 32-bit preferred only if the opened project targets .NET 4.5 --- .../Dialogs/OptionPanels/ProjectOptions/BuildAdvanced.xaml.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildAdvanced.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildAdvanced.xaml.cs index 4a096b0a9a..675d096d50 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildAdvanced.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildAdvanced.xaml.cs @@ -60,7 +60,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels this.TargetCPU = new List(); supports32BitPreferred = false; if (DotnetDetection.IsDotnet45Installed()) { - supports32BitPreferred = projectOptions.Project.MinimumSolutionVersion >= Solution.SolutionVersionVS2010; + var upgradableProject = projectOptions.Project as IUpgradableProject; + if (upgradableProject != null && upgradableProject.CurrentTargetFramework.IsBasedOn(TargetFramework.Net45)) + supports32BitPreferred = projectOptions.Project.MinimumSolutionVersion >= Solution.SolutionVersionVS2010; // Show 32 vs. 64 options even for library projects; // it's relevant for web applications. } From ef91a5b13e9c3c453cea9b0ad59a340b10c31f31 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Sun, 28 Jul 2013 14:15:35 +0200 Subject: [PATCH 013/172] Support for "Base Types" node in ClassBrowser, but retrieving base types not working right now. --- .../Dom/ClassBrowser/BaseTypesTreeNode.cs | 48 +++++++++++++++++++ .../ClassBrowser/TypeDefinitionTreeNode.cs | 6 +++ .../Base/Project/Dom/ITypeDefinitionModel.cs | 1 + .../Project/ICSharpCode.SharpDevelop.csproj | 1 + .../Dom/ClassBrowser/ClassBrowserPad.cs | 20 ++++---- .../SharpDevelop/Dom/TypeDefinitionModel.cs | 41 ++++++++++++++++ 6 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 src/Main/Base/Project/Dom/ClassBrowser/BaseTypesTreeNode.cs diff --git a/src/Main/Base/Project/Dom/ClassBrowser/BaseTypesTreeNode.cs b/src/Main/Base/Project/Dom/ClassBrowser/BaseTypesTreeNode.cs new file mode 100644 index 0000000000..db675a83f6 --- /dev/null +++ b/src/Main/Base/Project/Dom/ClassBrowser/BaseTypesTreeNode.cs @@ -0,0 +1,48 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.SharpDevelop.Dom.ClassBrowser +{ + /// + /// Description of BaseTypesTreeNode. + /// + public class BaseTypesTreeNode : ModelCollectionTreeNode + { + ITypeDefinitionModel definition; + string text; + + public BaseTypesTreeNode(ITypeDefinitionModel definition) + { + if (definition == null) + throw new ArgumentNullException("definition"); + this.definition = definition; + this.text = SD.ResourceService.GetString("MainWindow.Windows.ClassBrowser.BaseTypes"); + } + + protected override IModelCollection ModelChildren { + get { + return definition.BaseTypes; + } + } + + protected override System.Collections.Generic.IComparer NodeComparer { + get { + return NodeTextComparer; + } + } + + public override object Text { + get { + return text; + } + } + + public override object Icon { + get { + return SD.ResourceService.GetImageSource("Icons.16x16.OpenFolderBitmap"); + } + } + } +} diff --git a/src/Main/Base/Project/Dom/ClassBrowser/TypeDefinitionTreeNode.cs b/src/Main/Base/Project/Dom/ClassBrowser/TypeDefinitionTreeNode.cs index aaab2f62ac..0ceddedf8b 100644 --- a/src/Main/Base/Project/Dom/ClassBrowser/TypeDefinitionTreeNode.cs +++ b/src/Main/Base/Project/Dom/ClassBrowser/TypeDefinitionTreeNode.cs @@ -54,6 +54,12 @@ namespace ICSharpCode.SharpDevelop.Dom.ClassBrowser } } + protected override void LoadChildren() + { + base.LoadChildren(); + Children.Insert(0, new BaseTypesTreeNode(definition)); + } + public override void ActivateItem(System.Windows.RoutedEventArgs e) { var target = definition.Resolve(); diff --git a/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs b/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs index 62934f4576..2f6009fd7f 100644 --- a/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs +++ b/src/Main/Base/Project/Dom/ITypeDefinitionModel.cs @@ -17,6 +17,7 @@ namespace ICSharpCode.SharpDevelop.Dom string Namespace { get; } TypeKind TypeKind { get; } IModelCollection NestedTypes { get; } + IModelCollection BaseTypes { get; } IModelCollection Members { get; } IEnumerable GetPartRegions(); diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 91a1577bd1..f55fdd6cfd 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -86,6 +86,7 @@ + diff --git a/src/Main/SharpDevelop/Dom/ClassBrowser/ClassBrowserPad.cs b/src/Main/SharpDevelop/Dom/ClassBrowser/ClassBrowserPad.cs index 1c536d2306..af585b8603 100644 --- a/src/Main/SharpDevelop/Dom/ClassBrowser/ClassBrowserPad.cs +++ b/src/Main/SharpDevelop/Dom/ClassBrowser/ClassBrowserPad.cs @@ -149,17 +149,21 @@ namespace ICSharpCode.SharpDevelop.Dom.ClassBrowser void AssemblyListCollectionChanged(IReadOnlyCollection removedItems, IReadOnlyCollection addedItems) { - foreach (var assembly in addedItems) { - // Add this assembly to current workspace - if (activeWorkspace != null) { - activeWorkspace.AssemblyFiles.Add(assembly.Context.Location); + if (addedItems != null) { + foreach (var assembly in addedItems) { + // Add this assembly to current workspace + if (activeWorkspace != null) { + activeWorkspace.AssemblyFiles.Add(assembly.Context.Location); + } } } - foreach (var assembly in removedItems) { - // Add this assembly to current workspace - if (activeWorkspace != null) { - activeWorkspace.AssemblyFiles.Remove(assembly.Context.Location); + if (removedItems != null) { + foreach (var assembly in removedItems) { + // Add this assembly to current workspace + if (activeWorkspace != null) { + activeWorkspace.AssemblyFiles.Remove(assembly.Context.Location); + } } } diff --git a/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs b/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs index 20df0cead5..d2aa244ebe 100644 --- a/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs +++ b/src/Main/SharpDevelop/Dom/TypeDefinitionModel.cs @@ -270,6 +270,44 @@ namespace ICSharpCode.SharpDevelop.Dom } #endregion + #region Base Types collection + NestedTypeDefinitionModelCollection baseTypes; + + IList GetBaseTypes(IUnresolvedTypeDefinition definition) + { + var compilation = context.GetCompilation(); + if (compilation != null) { + var typeResolveContext = new SimpleTypeResolveContext(compilation.MainAssembly).WithCurrentTypeDefinition(Resolve()); + var baseTypeList = new List(); + foreach (var baseTypeRef in definition.BaseTypes) { + var resolvedTypeDefinition = baseTypeRef.Resolve(typeResolveContext).GetDefinition(); + if (resolvedTypeDefinition != null) { + baseTypeList.Add(resolvedTypeDefinition.Parts[0]); + } + } + + return baseTypeList; + } + + return null; + } + + public IModelCollection BaseTypes { + get { + if (baseTypes == null) { + baseTypes = new NestedTypeDefinitionModelCollection(context); + foreach (var part in parts) { + var baseTypeList = GetBaseTypes(part); + if (baseTypeList != null) { + baseTypes.Update(null, baseTypeList); + } + } + } + return baseTypes; + } + } + #endregion + #region Update /// /// Updates this type definition model by replacing oldPart with newPart. @@ -311,6 +349,9 @@ namespace ICSharpCode.SharpDevelop.Dom if (nestedTypes != null) { nestedTypes.Update(oldPart != null ? oldPart.NestedTypes : null, newPart != null ? newPart.NestedTypes : null); } + if (baseTypes != null) { + baseTypes.Update(oldPart != null ? GetBaseTypes(oldPart) : null, newPart != null ? GetBaseTypes(newPart) : null); + } } #endregion From a95cbc4a2e2ed89adbc52c75fc8ddfb6f712bd86 Mon Sep 17 00:00:00 2001 From: gumme Date: Mon, 17 Jun 2013 11:49:31 +0200 Subject: [PATCH 014/172] Removing the optional "Extension" suffix from Markup Extension name if present. --- .../WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs index d9cb3b1aa6..2c94500487 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs @@ -353,7 +353,16 @@ namespace ICSharpCode.WpfDesign.XamlDom internal string GetNameForMarkupExtension() { - return XmlElement.Name; + string markupExtensionName = XmlElement.Name; + + // By convention a markup extension class name typically includes an "Extension" suffix. + // When you reference the markup extension in XAML the "Extension" suffix is optional. + // If present remove it to avoid bloating the XAML. + if (markupExtensionName.EndsWith("Extension", StringComparison.Ordinal)) { + markupExtensionName = markupExtensionName.Substring(0, markupExtensionName.Length - 9); + } + + return markupExtensionName; } } From 9f71500fab0d9d6a6e51bfe758c3f3d5cb339419 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 28 Jul 2013 09:24:59 +0200 Subject: [PATCH 015/172] add unit tests for property setters --- .../Tests/Designer/SetPropertyTests.cs | 41 +++++++++++++++++++ .../Tests/WpfDesign.Tests.csproj | 1 + 2 files changed, 42 insertions(+) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs new file mode 100644 index 0000000000..46ec5bc060 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs @@ -0,0 +1,41 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Windows; +using System.Windows.Data; +using System.Windows.Markup; + +using NUnit.Framework; + +namespace ICSharpCode.WpfDesign.Tests.Designer +{ + [TestFixture] + public class SetPropertyTests : ModelTestHelper + { + [Test] + public void SetContentToBinding() + { + DesignItem button = CreateCanvasContext(" public static class XamlConstants { + #region Namespaces + /// /// The namespace used to identify "xmlns". /// Value: "http://www.w3.org/2000/xmlns/" @@ -27,5 +29,17 @@ namespace ICSharpCode.WpfDesign.XamlDom /// Value: "http://schemas.microsoft.com/winfx/2006/xaml/presentation" /// public const string PresentationNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; + + #endregion + + #region Common property names + + /// + /// The name of the Resources property. + /// Value: "Resources" + /// + public const string ResourcesPropertyName = "Resources"; + + #endregion } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs index 3e2a900f07..3f5ce64d05 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs @@ -24,6 +24,7 @@ namespace ICSharpCode.WpfDesign.XamlDom CollectionElementsCollection collectionElements; bool isCollection; + bool isResources; static readonly IList emptyCollectionElementsArray = new XamlPropertyValue[0]; @@ -49,6 +50,11 @@ namespace ICSharpCode.WpfDesign.XamlDom if (propertyInfo.IsCollection) { isCollection = true; collectionElements = new CollectionElementsCollection(this); + + if (propertyInfo.Name.Equals(XamlConstants.ResourcesPropertyName, StringComparison.Ordinal) && + propertyInfo.ReturnType == typeof(ResourceDictionary)) { + isResources = true; + } } } @@ -116,6 +122,13 @@ namespace ICSharpCode.WpfDesign.XamlDom set { SetPropertyValue(value); } } + /// + /// Gets if the property represents the FrameworkElement.Resources property that holds a locally-defined resource dictionary. + /// + public bool IsResources { + get { return isResources; } + } + /// /// Gets if the property is a collection property. /// @@ -287,7 +300,13 @@ namespace ICSharpCode.WpfDesign.XamlDom ParentObject.ElementType.Name + "." + this.PropertyName, parentObject.OwnerDocument.GetNamespaceFor(ParentObject.ElementType) ); - parentObject.XmlElement.AppendChild(_propertyElement); + + if (this.IsResources) { + parentObject.XmlElement.PrependChild(_propertyElement); + } else { + parentObject.XmlElement.AppendChild(_propertyElement); + } + collection = _propertyElement; } else { // this is the default collection From e3a032913f524feb67f6d8b1b84ebffa34001c8c Mon Sep 17 00:00:00 2001 From: Tobias Gummesson Date: Thu, 4 Jul 2013 08:37:12 -0700 Subject: [PATCH 021/172] XML-namespaces for controls outside the default XML-namespace is now declared in the document root. As prefix for the XML-namespaces it primarily uses the value from XmlnsPrefixAttribute if it exists for the XML-namespace, otherwise a "ControlsX" name is generated, where X is the first free value. --- .../WpfDesign.XamlDom/Project/XamlDocument.cs | 56 ++++++++++++++++--- .../Project/XamlTypeFinder.cs | 48 ++++++++++++---- 2 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs index 744617d8e7..925dea9dbe 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs @@ -17,7 +17,9 @@ namespace ICSharpCode.WpfDesign.XamlDom XamlObject _rootElement; IServiceProvider _serviceProvider; - XamlTypeFinder _typeFinder; + XamlTypeFinder _typeFinder; + + int namespacePrefixCounter; internal XmlDocument XmlDocument { get { return _xmlDoc; } @@ -164,11 +166,13 @@ namespace ICSharpCode.WpfDesign.XamlDom bool hasStringConverter = c.CanConvertTo(ctx, typeof(string)) && c.CanConvertFrom(typeof(string)); if (forProperty != null && hasStringConverter) { return new XamlTextValue(this, c.ConvertToInvariantString(ctx, instance)); - } - - - XmlElement xml = _xmlDoc.CreateElement(elementType.Name, GetNamespaceFor(elementType)); - + } + + string ns = GetNamespaceFor(elementType); + string prefix = GetPrefixForNamespace(ns); + + XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns); + if (hasStringConverter && XamlObject.GetContentPropertyName(elementType) != null) { @@ -181,6 +185,44 @@ namespace ICSharpCode.WpfDesign.XamlDom internal string GetNamespaceFor(Type type) { return _typeFinder.GetXmlNamespaceFor(type.Assembly, type.Namespace); - } + } + + internal string GetPrefixForNamespace(string @namespace) + { + if (@namespace == XamlConstants.PresentationNamespace) + { + return null; + } + + string prefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(@namespace); + + if (String.IsNullOrEmpty(prefix)) + { + prefix = _typeFinder.GetPrefixForXmlNamespace(@namespace); + + string existingNamespaceForPrefix = null; + if (!String.IsNullOrEmpty(prefix)) + { + existingNamespaceForPrefix = _xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix); + } + + if (String.IsNullOrEmpty(prefix) || + !String.IsNullOrEmpty(existingNamespaceForPrefix) && + existingNamespaceForPrefix != @namespace) + { + do + { + prefix = "Controls" + namespacePrefixCounter++; + } while (!String.IsNullOrEmpty(_xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix))); + } + + string xmlnsPrefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(XamlConstants.XmlnsNamespace); + System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(xmlnsPrefix)); + + _xmlDoc.DocumentElement.SetAttribute(xmlnsPrefix + ":" + prefix, @namespace); + } + + return prefix; + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs index 0abcbd0afd..9c4c24506d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs @@ -42,11 +42,13 @@ namespace ICSharpCode.WpfDesign.XamlDom } sealed class XamlNamespace - { + { + internal readonly string XmlNamespacePrefix; internal readonly string XmlNamespace; - internal XamlNamespace(string xmlNamespace) - { + internal XamlNamespace(string xmlNamespacePrefix, string xmlNamespace) + { + this.XmlNamespacePrefix = xmlNamespacePrefix; this.XmlNamespace = xmlNamespace; } @@ -54,7 +56,7 @@ namespace ICSharpCode.WpfDesign.XamlDom internal XamlNamespace Clone() { - XamlNamespace copy = new XamlNamespace(this.XmlNamespace); + XamlNamespace copy = new XamlNamespace(this.XmlNamespacePrefix, this.XmlNamespace); // AssemblyNamespaceMapping is immutable copy.ClrNamespaces.AddRange(this.ClrNamespaces); return copy; @@ -107,7 +109,25 @@ namespace ICSharpCode.WpfDesign.XamlDom } else { return "clr-namespace:" + mapping.Namespace + ";assembly=" + mapping.Assembly.GetName().Name; } - } + } + + /// + /// Gets the prefix to use for the specified XML namespace, + /// or null if no suitable prefix could be found. + /// + public string GetPrefixForXmlNamespace(string xmlNamespace) + { + XamlNamespace ns; + + if (namespaces.TryGetValue(xmlNamespace, out ns)) + { + return ns.XmlNamespacePrefix; + } + else + { + return null; + } + } XamlNamespace ParseNamespace(string xmlNamespace) { @@ -127,7 +147,7 @@ namespace ICSharpCode.WpfDesign.XamlDom } assembly = name.Substring("assembly=".Length); } - XamlNamespace ns = new XamlNamespace(xmlNamespace); + XamlNamespace ns = new XamlNamespace(null, xmlNamespace); Assembly asm = LoadAssembly(assembly); if (asm != null) { AddMappingToNamespace(ns, new AssemblyNamespaceMapping(asm, namespaceName)); @@ -154,11 +174,19 @@ namespace ICSharpCode.WpfDesign.XamlDom public void RegisterAssembly(Assembly assembly) { if (assembly == null) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException("assembly"); + + Dictionary namespacePrefixes = new Dictionary(); + foreach (XmlnsPrefixAttribute xmlnsPrefix in assembly.GetCustomAttributes(typeof(XmlnsPrefixAttribute), true)) { + namespacePrefixes.Add(xmlnsPrefix.XmlNamespace, xmlnsPrefix.Prefix); + } + foreach (XmlnsDefinitionAttribute xmlnsDef in assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true)) { - XamlNamespace ns; - if (!namespaces.TryGetValue(xmlnsDef.XmlNamespace, out ns)) { - ns = namespaces[xmlnsDef.XmlNamespace] = new XamlNamespace(xmlnsDef.XmlNamespace); + XamlNamespace ns; + if (!namespaces.TryGetValue(xmlnsDef.XmlNamespace, out ns)) { + string prefix; + namespacePrefixes.TryGetValue(xmlnsDef.XmlNamespace, out prefix); + ns = namespaces[xmlnsDef.XmlNamespace] = new XamlNamespace(prefix, xmlnsDef.XmlNamespace); } if (string.IsNullOrEmpty(xmlnsDef.AssemblyName)) { AddMappingToNamespace(ns, new AssemblyNamespaceMapping(assembly, xmlnsDef.ClrNamespace)); From 4c8a3129e867dbfb2cbe46737ae8c056c081a23b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 28 Jul 2013 10:49:26 +0200 Subject: [PATCH 022/172] adjusted unit test --- .../WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs index 144631b0e7..ac1ee42aa2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs @@ -30,7 +30,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer AssertCanvasDesignerOutput("