Browse Source

Fix conflicts after merge

Merge remote-tracking branch 'upstream/master'

Conflicts:
	src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs
	src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
	src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
pull/52/head
jkuehner 13 years ago
parent
commit
190e56e33a
  1. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs
  2. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  3. 48
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs
  4. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
  5. 111
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  6. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  7. 54
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs

@ -31,12 +31,12 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
} }
Category specialCategory = new Category("Special"); Category specialCategory = new Category("Special");
Category popularCategory = new Category("Popular"); Category popularCategory = new Category("Popular");
Category otherCategory = new Category("Other"); Category otherCategory = new Category("Other");
Category attachedCategory = new Category("Attached"); Category attachedCategory = new Category("Attached");
Dictionary<MemberDescriptor, PropertyNode> nodeFromDescriptor = new Dictionary<MemberDescriptor, PropertyNode>(); Dictionary<MemberDescriptor, PropertyNode> nodeFromDescriptor = new Dictionary<MemberDescriptor, PropertyNode>();
public CategoriesCollection Categories { get; private set; } public CategoriesCollection Categories { get; private set; }
public PropertyNodeCollection Events { get; private set; } public PropertyNodeCollection Events { get; private set; }
@ -126,7 +126,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
try { try {
if (string.IsNullOrEmpty(value)) { if (string.IsNullOrEmpty(value)) {
OldName = null; OldName = null;
SingleItem.Properties["Name"].Reset(); SingleItem.Name = null;
} else { } else {
OldName = SingleItem.Name; OldName = SingleItem.Name;
SingleItem.Name = value; SingleItem.Name = value;
@ -245,7 +245,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
{ {
var designProperties = SelectedItems.Select(item => item.Properties.GetProperty(md)).ToArray(); var designProperties = SelectedItems.Select(item => item.Properties.GetProperty(md)).ToArray();
if (!Metadata.IsBrowsable(designProperties[0])) return; if (!Metadata.IsBrowsable(designProperties[0])) return;
PropertyNode node; PropertyNode node;
if (nodeFromDescriptor.TryGetValue(md, out node)) { if (nodeFromDescriptor.TryGetValue(md, out node)) {
node.Load(designProperties); node.Load(designProperties);

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -49,8 +49,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
} }
public override string Name { public override string Name {
get { return (string)this.Properties["Name"].ValueOnInstance; } get { return _xamlObject.Name; }
set { this.Properties["Name"].SetValue(value); } set { _xamlObject.Name = value; }
} }
public override string Key { public override string Key {
@ -70,13 +70,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
#if EventHandlerDebugging #if EventHandlerDebugging
Debug.WriteLine("Add event handler to " + this.ComponentType.Name + " (handler count=" + (++totalEventHandlerCount) + ")"); Debug.WriteLine("Add event handler to " + this.ComponentType.Name + " (handler count=" + (++totalEventHandlerCount) + ")");
#endif #endif
this.Properties["Name"].ValueChanged += value; _xamlObject.NameChanged += value;
} }
remove { remove {
#if EventHandlerDebugging #if EventHandlerDebugging
Debug.WriteLine("Remove event handler from " + this.ComponentType.Name + " (handler count=" + (--totalEventHandlerCount) + ")"); Debug.WriteLine("Remove event handler from " + this.ComponentType.Name + " (handler count=" + (--totalEventHandlerCount) + ")");
#endif #endif
this.Properties["Name"].ValueChanged -= value; _xamlObject.NameChanged -= value;
} }
} }

48
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.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;
using System.Diagnostics;
using System.Windows;
using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom
{
/// <summary>
/// Static methods to help with <see cref="System.Windows.Markup.INameScope"/> operations on Xaml elements.
/// </summary>
internal static class NameScopeHelper
{
/// <summary>
/// Finds the XAML namescope for the specified object and uses it to unregister the old name and then register the new name.
/// </summary>
/// <param name="namedObject">The object where the name was changed.</param>
/// <param name="oldName">The old name.</param>
/// <param name="newName">The new name.</param>
public static void NameChanged(XamlObject namedObject, string oldName, string newName)
{
var obj = namedObject;
while (obj != null) {
var nameScope = obj.Instance as INameScope;
if (nameScope == null) {
var depObj = obj.Instance as DependencyObject;
if (depObj != null)
nameScope = NameScope.GetNameScope(depObj);
}
if (nameScope != null) {
if (oldName != null) {
try {
nameScope.UnregisterName(oldName);
} catch (Exception x) {
Debug.WriteLine(x.Message);
}
}
if (newName != null) {
nameScope.RegisterName(newName, namedObject.Instance);
}
break;
}
obj = obj.ParentObject;
}
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj

@ -74,6 +74,7 @@
<Compile Include="MarkupCompatibilityProperties.cs" /> <Compile Include="MarkupCompatibilityProperties.cs" />
<Compile Include="MarkupExtensionParser.cs" /> <Compile Include="MarkupExtensionParser.cs" />
<Compile Include="MarkupExtensionPrinter.cs" /> <Compile Include="MarkupExtensionPrinter.cs" />
<Compile Include="NameScopeHelper.cs" />
<Compile Include="PositionXmlDocument.cs" /> <Compile Include="PositionXmlDocument.cs" />
<Compile Include="XamlConstants.cs" /> <Compile Include="XamlConstants.cs" />
<Compile Include="XamlDocument.cs" /> <Compile Include="XamlDocument.cs" />

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

@ -24,7 +24,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
Type elementType; Type elementType;
object instance; object instance;
List<XamlProperty> properties = new List<XamlProperty>(); List<XamlProperty> properties = new List<XamlProperty>();
string contentPropertyName;
XamlProperty nameProperty;
string runtimeNameProperty;
/// <summary>For use by XamlParser only.</summary> /// <summary>For use by XamlParser only.</summary>
internal XamlObject(XamlDocument document, XmlElement element, Type elementType, object instance) internal XamlObject(XamlDocument document, XmlElement element, Type elementType, object instance)
{ {
@ -37,6 +40,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
ServiceProvider = new XamlObjectServiceProvider(this); ServiceProvider = new XamlObjectServiceProvider(this);
CreateWrapper(); CreateWrapper();
var rnpAttrs = elementType.GetCustomAttributes(typeof(RuntimeNamePropertyAttribute), true) as RuntimeNamePropertyAttribute[];
if (rnpAttrs != null && rnpAttrs.Length > 0 && !String.IsNullOrEmpty(rnpAttrs[0].Name)) {
runtimeNameProperty = rnpAttrs[0].Name;
}
} }
/// <summary>For use by XamlParser only.</summary> /// <summary>For use by XamlParser only.</summary>
@ -210,6 +218,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
UpdateMarkupExtensionChain(); UpdateMarkupExtensionChain();
if (property == NameProperty) {
if (NameChanged != null)
NameChanged(this, EventArgs.Empty);
}
} }
void UpdateMarkupExtensionChain() void UpdateMarkupExtensionChain()
@ -290,8 +303,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
string contentPropertyName;
/// <summary> /// <summary>
/// Gets the name of the content property. /// Gets the name of the content property.
/// </summary> /// </summary>
@ -301,6 +312,54 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
/// <summary>
/// Gets which property name of the type maps to the XAML x:Name attribute.
/// </summary>
public string RuntimeNameProperty {
get {
return runtimeNameProperty;
}
}
/// <summary>
/// Gets which property of the type maps to the XAML x:Name attribute.
/// </summary>
public XamlProperty NameProperty {
get {
if(nameProperty == null && runtimeNameProperty != null)
nameProperty = FindOrCreateProperty(runtimeNameProperty);
return nameProperty;
}
}
/// <summary>
/// Gets/Sets the name of this XamlObject.
/// </summary>
public string Name {
get
{
string name = GetXamlAttribute("Name");
if (String.IsNullOrEmpty(name)) {
if (NameProperty != null && NameProperty.IsSet)
name = (string)NameProperty.ValueOnInstance;
}
if (name == String.Empty)
name = null;
return name;
}
set
{
if (String.IsNullOrEmpty(value))
this.SetXamlAttribute("Name", null);
else
this.SetXamlAttribute("Name", value);
}
}
/// <summary> /// <summary>
/// Finds the specified property, or creates it if it doesn't exist. /// Finds the specified property, or creates it if it doesn't exist.
/// </summary> /// </summary>
@ -370,10 +429,51 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary> /// </summary>
public void SetXamlAttribute(string name, string value) public void SetXamlAttribute(string name, string value)
{ {
XamlProperty runtimeNameProperty = null;
bool isNameChange = false;
if (name == "Name") {
isNameChange = true;
string oldName = GetXamlAttribute("Name");
if (String.IsNullOrEmpty(oldName)) {
runtimeNameProperty = this.NameProperty;
if (runtimeNameProperty != null) {
if (runtimeNameProperty.IsSet)
oldName = (string)runtimeNameProperty.ValueOnInstance;
else
runtimeNameProperty = null;
}
}
if (String.IsNullOrEmpty(oldName))
oldName = null;
NameScopeHelper.NameChanged(this, oldName, value);
}
if (value == null) if (value == null)
element.RemoveAttribute(name, XamlConstants.XamlNamespace); element.RemoveAttribute(name, XamlConstants.XamlNamespace);
else else
element.SetAttribute(name, XamlConstants.XamlNamespace, value); element.SetAttribute(name, XamlConstants.XamlNamespace, value);
if (isNameChange) {
bool nameChangedAlreadyRaised = false;
if (runtimeNameProperty != null) {
var handler = new EventHandler((sender, e) => nameChangedAlreadyRaised = true);
this.NameChanged += handler;
try {
runtimeNameProperty.Reset();
}
finally {
this.NameChanged -= handler;
}
}
if (NameChanged != null && !nameChangedAlreadyRaised)
NameChanged(this, EventArgs.Empty);
}
} }
/// <summary> /// <summary>
@ -416,6 +516,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
return markupExtensionName; return markupExtensionName;
} }
/// <summary>
/// Is raised when the name of this XamlObject changes.
/// </summary>
public event EventHandler NameChanged;
} }
abstract class MarkupExtensionWrapper abstract class MarkupExtensionWrapper

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

@ -254,8 +254,17 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (attribute.Name == "xml:space") { if (attribute.Name == "xml:space") {
continue; continue;
} }
if (GetAttributeNamespace(attribute) == XamlConstants.XamlNamespace) if (GetAttributeNamespace(attribute) == XamlConstants.XamlNamespace) {
if (attribute.LocalName == "Name") {
try {
NameScopeHelper.NameChanged(obj, null, attribute.Value);
} catch (Exception x) {
ReportException(x, attribute);
}
}
continue; continue;
}
ParseObjectAttribute(obj, attribute); ParseObjectAttribute(obj, attribute);
} }

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

@ -361,25 +361,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
name = PropertyTargetType.Name + "." + PropertyName; name = PropertyTargetType.Name + "." + PropertyName;
string ns = ParentObject.OwnerDocument.GetNamespaceFor(PropertyTargetType); string ns = ParentObject.OwnerDocument.GetNamespaceFor(PropertyTargetType);
string prefix = element.GetPrefixOfNamespace(ns); string prefix = element.GetPrefixOfNamespace(ns);
if (String.IsNullOrEmpty(prefix)) if (String.IsNullOrEmpty(prefix)) {
{ prefix = ParentObject.OwnerDocument.GetPrefixForNamespace(ns);
prefix = ParentObject.OwnerDocument.GetPrefixForNamespace(ns); }
}
if (!string.IsNullOrEmpty(prefix)) if (!string.IsNullOrEmpty(prefix)) {
{
element.SetAttribute(name, ns, value); element.SetAttribute(name, ns, value);
return element.GetAttributeNode(name, ns); return element.GetAttributeNode(name, ns);
} }
} } else {
else
{
name = PropertyName; name = PropertyName;
} }
element.SetAttribute(name, value); element.SetAttribute(name, string.Empty, value);
return element.GetAttributeNode(name); return element.GetAttributeNode(name);
} }
@ -395,8 +391,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
return name; return name;
else else
return prefix + ":" + name; return prefix + ":" + name;
} } else
else
return PropertyName; return PropertyName;
} }
@ -456,39 +451,22 @@ namespace ICSharpCode.WpfDesign.XamlDom
void PossiblyNameChanged(XamlPropertyValue oldValue, XamlPropertyValue newValue) void PossiblyNameChanged(XamlPropertyValue oldValue, XamlPropertyValue newValue)
{ {
if (PropertyName == "Name" && ReturnType == typeof(string)) { if (ParentObject.RuntimeNameProperty != null && PropertyName == ParentObject.RuntimeNameProperty) {
if (!String.IsNullOrEmpty(ParentObject.GetXamlAttribute("Name"))) {
throw new XamlLoadException("The property 'Name' is set more than once.");
}
string oldName = null; string oldName = null;
string newName = null; string newName = null;
var oldTextValue = oldValue as XamlTextValue; var oldTextValue = oldValue as XamlTextValue;
if (oldTextValue != null) oldName = oldTextValue.Text; if (oldTextValue != null) oldName = oldTextValue.Text;
var newTextValue = newValue as XamlTextValue; var newTextValue = newValue as XamlTextValue;
if (newTextValue != null) newName = newTextValue.Text; if (newTextValue != null) newName = newTextValue.Text;
var obj = ParentObject; NameScopeHelper.NameChanged(ParentObject, oldName, newName);
while (obj != null) {
var nameScope = obj.Instance as INameScope;
if (nameScope == null) {
if (obj.Instance is DependencyObject)
nameScope = NameScope.GetNameScope((DependencyObject)obj.Instance);
}
if (nameScope != null) {
if (oldName != null) {
try {
nameScope.UnregisterName(oldName);
} catch (Exception x) {
Debug.WriteLine(x.Message);
}
}
if (newName != null) {
nameScope.RegisterName(newName, ParentObject.Instance);
}
break;
}
obj = obj.ParentObject;
}
} }
} }

Loading…
Cancel
Save