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 18 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. 69
      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 @@
Name="root" Name="root"
Title="Hydralisk"> Title="Hydralisk">
<Window.Resources> <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> <sys:String x:Key="r2">Width</sys:String>
</Window.Resources> </Window.Resources>
<StackPanel> <StackPanel>

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

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

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

@ -1,6 +1,8 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
using System.Windows.Markup; using System.Windows.Markup;
using ICSharpCode.WpfDesign.XamlDom;
using System.IO;
namespace ICSharpCode.WpfDesign.Tests.XamlDom namespace ICSharpCode.WpfDesign.Tests.XamlDom
{ {
@ -65,6 +67,21 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
TestMarkupExtension("Content=\"{x:Static t:MyStaticClass.StaticString}\""); 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) static void TestMarkupExtension(string s)
{ {
TestLoading(@"<Window TestLoading(@"<Window

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

@ -101,7 +101,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
get { return element; } get { return element; }
} }
// exists only for ME root
XmlAttribute xmlAttribute; XmlAttribute xmlAttribute;
internal XmlAttribute XmlAttribute { internal XmlAttribute XmlAttribute {
@ -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) static XmlElement VirualAttachTo(XmlElement e, XmlElement target)
{ {
var prefix = target.GetPrefixOfNamespace(e.NamespaceURI); var prefix = target.GetPrefixOfNamespace(e.NamespaceURI);
@ -139,15 +131,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
newElement.Attributes.Append(ac[0]); newElement.Attributes.Append(ac[0]);
} }
return newElement; return newElement;
} }
internal override void AddNodeTo(XamlProperty property) internal override void AddNodeTo(XamlProperty property)
{ {
if (!UpdateMarkupExtension(true)) { if (!UpdateXmlAttribute(true)) {
property.AddChildNodeToProperty(element); property.AddChildNodeToProperty(element);
} }
UpdateMarkupExtensionChain();
} }
internal override void RemoveNodeFromParent() internal override void RemoveNodeFromParent()
@ -156,36 +148,57 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name); XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name);
xmlAttribute = null; xmlAttribute = null;
} else { } 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) internal void OnPropertyChanged(XamlProperty property)
{ {
UpdateMarkupExtension(false); UpdateXmlAttribute(false);
UpdateMarkupExtensionChain();
} }
bool UpdateMarkupExtension(bool canCreate) void UpdateMarkupExtensionChain()
{ {
if (IsMarkupExtension) { var obj = this;
var obj = this; while (obj != null && obj.IsMarkupExtension) {
while (obj != null && obj.IsMarkupExtension) { obj.ParentProperty.UpdateValueOnInstance();
obj.ParentProperty.UpdateValueOnInstance(); obj = obj.ParentObject;
if (obj.IsMarkupExtensionRoot) break; }
obj = obj.ParentObject; }
}
if (!obj.IsMarkupExtension) obj = null; bool UpdateXmlAttribute(bool force)
if (obj == null && !canCreate) return false; {
var root = obj ?? this; var holder = FindXmlAttributeHolder();
if (MarkupExtensionPrinter.CanPrint(root)) { if (holder == null && force && IsMarkupExtension) {
var s = MarkupExtensionPrinter.Print(root); holder = this;
root.XmlAttribute = root.ParentProperty.SetAttribute(s); }
return root == this; if (holder != null && MarkupExtensionPrinter.CanPrint(holder)) {
} var s = MarkupExtensionPrinter.Print(holder);
holder.XmlAttribute = holder.ParentProperty.SetAttribute(s);
return true;
} }
return false; return false;
} }
XamlObject FindXmlAttributeHolder()
{
var obj = this;
while (obj != null && obj.IsMarkupExtension) {
if (obj.XmlAttribute != null) {
return obj;
}
obj = obj.ParentObject;
}
return null;
}
/// <summary> /// <summary>
/// Gets the XamlDocument where this XamlObject is declared in. /// Gets the XamlDocument where this XamlObject is declared in.
/// </summary> /// </summary>

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

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

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

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

Loading…
Cancel
Save