Browse Source

- Update code related to XamlObject.XmlAttribute (ME support)

- XamlParser throws an exception on error if error sink not available

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3529 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Ivan Shumilin 17 years ago
parent
commit
6812aa497e
  1. 2
      samples/XamlDesigner/TestFiles/4.xaml
  2. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
  3. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs
  4. 75
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  5. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  6. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

2
samples/XamlDesigner/TestFiles/4.xaml

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
Name="root"
Title="Hydralisk">
<Window.Resources>
<sys:String1 x:Key="r1">Title</sys:String>
<sys:String x:Key="r1">Title</sys:String>
<sys:String x:Key="r2">Width</sys:String>
</Window.Resources>
<StackPanel>

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -16,6 +16,9 @@ @@ -16,6 +16,9 @@
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
using System;
using NUnit.Framework;
using System.Windows.Markup;
using ICSharpCode.WpfDesign.XamlDom;
using System.IO;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
@ -65,6 +67,21 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -65,6 +67,21 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
TestMarkupExtension("Content=\"{x:Static t:MyStaticClass.StaticString}\"");
}
// [Test]
// public void Test10()
// {
// var s =
//@"<Window
// xmlns='http://schemas.microsoft.com/netfx/2007/xaml/presentation'
// xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
// Content='{Binding}'";
// var doc = XamlParser.Parse(new StringReader(s));
// var binding = doc.RootElement.FindOrCreateProperty("Content").PropertyValue as XamlObject;
// binding.FindOrCreateProperty("ElementName").PropertyValue = doc.CreatePropertyValue("name1", null);
// Assert.AreEqual(binding.XmlAttribute.Value, "{Binding ElementName=name1}");
// }
static void TestMarkupExtension(string s)
{
TestLoading(@"<Window

75
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -101,7 +101,6 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -101,7 +101,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
get { return element; }
}
// exists only for ME root
XmlAttribute xmlAttribute;
internal XmlAttribute XmlAttribute {
@ -112,13 +111,6 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -112,13 +111,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
/// <summary>
/// Gets whether this XamlObject represents a markup extension in short form ("{Binding}" syntax)
/// </summary>
public bool IsMarkupExtensionRoot {
get { return XmlAttribute != null; }
}
static XmlElement VirualAttachTo(XmlElement e, XmlElement target)
{
var prefix = target.GetPrefixOfNamespace(e.NamespaceURI);
@ -138,53 +130,74 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -138,53 +130,74 @@ namespace ICSharpCode.WpfDesign.XamlDom
while (ac.Count > 0) {
newElement.Attributes.Append(ac[0]);
}
return newElement;
}
internal override void AddNodeTo(XamlProperty property)
{
if (!UpdateMarkupExtension(true)) {
{
if (!UpdateXmlAttribute(true)) {
property.AddChildNodeToProperty(element);
}
UpdateMarkupExtensionChain();
}
internal override void RemoveNodeFromParent()
{
{
if (XmlAttribute != null) {
XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name);
xmlAttribute = null;
} else {
element.ParentNode.RemoveChild(element);
}
if (!UpdateXmlAttribute(false)) {
element.ParentNode.RemoveChild(element);
}
}
//TODO: PropertyValue still there
//UpdateMarkupExtensionChain();
}
//TODO: reseting path property for binding doesn't work in XamlProperty
//use CanResetValue()
internal void OnPropertyChanged(XamlProperty property)
{
UpdateXmlAttribute(false);
UpdateMarkupExtensionChain();
}
void UpdateMarkupExtensionChain()
{
UpdateMarkupExtension(false);
var obj = this;
while (obj != null && obj.IsMarkupExtension) {
obj.ParentProperty.UpdateValueOnInstance();
obj = obj.ParentObject;
}
}
bool UpdateMarkupExtension(bool canCreate)
bool UpdateXmlAttribute(bool force)
{
if (IsMarkupExtension) {
var obj = this;
while (obj != null && obj.IsMarkupExtension) {
obj.ParentProperty.UpdateValueOnInstance();
if (obj.IsMarkupExtensionRoot) break;
obj = obj.ParentObject;
}
if (!obj.IsMarkupExtension) obj = null;
if (obj == null && !canCreate) return false;
var root = obj ?? this;
if (MarkupExtensionPrinter.CanPrint(root)) {
var s = MarkupExtensionPrinter.Print(root);
root.XmlAttribute = root.ParentProperty.SetAttribute(s);
return root == this;
}
var holder = FindXmlAttributeHolder();
if (holder == null && force && IsMarkupExtension) {
holder = this;
}
if (holder != null && MarkupExtensionPrinter.CanPrint(holder)) {
var s = MarkupExtensionPrinter.Print(holder);
holder.XmlAttribute = holder.ParentProperty.SetAttribute(s);
return true;
}
return false;
}
XamlObject FindXmlAttributeHolder()
{
var obj = this;
while (obj != null && obj.IsMarkupExtension) {
if (obj.XmlAttribute != null) {
return obj;
}
obj = obj.ParentObject;
}
return null;
}
/// <summary>
/// Gets the XamlDocument where this XamlObject is declared in.

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -83,8 +83,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -83,8 +83,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
doc.Load(reader);
return Parse(doc, settings);
} catch (XmlException x) {
if (errorSink != null)
if (errorSink != null) {
errorSink.ReportError(x.Message, x.LineNumber, x.LinePosition);
} else {
throw;
}
}
return null;
@ -155,8 +158,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -155,8 +158,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (currentXamlObject != null) {
currentXamlObject.HasErrors = true;
}
} else {
throw x;
}
// TODO: what when there's no error sink? I think we should throw exception
}
XamlObject ParseObject(XmlElement element)

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -42,7 +42,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
propertyValue.ParentProperty = this;
}
ValueOnInstance = PropertyValue.GetValueFor(propertyInfo);
UpdateValueOnInstance();
}
internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo)

Loading…
Cancel
Save