Author: gonzalo
Date: 2006-09-11 18:57:06 -0400 (Mon, 11 Sep 2006)
New Revision: 65261
Modified:
trunk/mcs/class/System/System.ComponentModel/ChangeLog
trunk/mcs/class/System/System.ComponentModel/Container.cs
trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog
trunk/mcs/class/System/Test/System.ComponentModel/ContainerTest.cs
Log:
2006-09-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Test/System.ComponentModel/ContainerTest.cs:
* System.ComponentModel/Container.cs: 'unsite' the component when
removing it. Fixes bug #79255. Patch by Ivan N. Zlatev.
Modified: trunk/mcs/class/System/System.ComponentModel/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/ChangeLog 2006-09-11
22:56:49 UTC (rev 65260)
+++ trunk/mcs/class/System/System.ComponentModel/ChangeLog 2006-09-11
22:57:06 UTC (rev 65261)
@@ -1,5 +1,10 @@
2006-09-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+ * Container.cs: 'unsite' the component when removing it. Fixes
+ bug #79255. Patch by Ivan N. Zlatev.
+
+2006-09-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
* TypeDescriptor.cs: don't ignore toplevel attributes when they are
overriden.
Modified: trunk/mcs/class/System/System.ComponentModel/Container.cs
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/Container.cs 2006-09-11
22:56:49 UTC (rev 65260)
+++ trunk/mcs/class/System/System.ComponentModel/Container.cs 2006-09-11
22:57:06 UTC (rev 65261)
@@ -4,9 +4,11 @@
// Author:
// Miguel de Icaza ([EMAIL PROTECTED])
// Andreas Nahr ([EMAIL PROTECTED])
+// Ivan N. Zlatev (contact i-nZ.net)
//
// (C) Ximian, Inc. http://www.ximian.com
// (C) 2003 Andreas Nahr
+// (C) 2006 Ivan N. Zlatev
//
//
@@ -58,6 +60,7 @@
// </remarks>
class DefaultSite : ISite {
+
private IComponent component;
private Container container;
private string name;
@@ -81,11 +84,8 @@
}
}
- [MonoTODO]
public bool DesignMode {
get {
- // FIXME: should we provide a way to set
- // this value?
return false;
}
}
@@ -130,19 +130,20 @@
public virtual void Add (IComponent component, string name)
{
- component.Site = CreateSite (component, name);
- c.Add (component);
+ if (component != null) {
+ if (component.Site == null ||
component.Site.Container != this) {
+ if (component.Site != null) {
+ component.Site.Container.Remove
(component);
+ }
+
+ component.Site = this.CreateSite
(component, name);
+ c.Add (component);
+ }
+ }
}
protected virtual ISite CreateSite (IComponent component,
string name)
{
- if (name != null) {
- foreach (IComponent Comp in c) {
- if (Comp.Site != null && Comp.Site.Name
== name)
- throw new ArgumentException
("duplicate component name", "name");
- }
- }
-
return new DefaultSite (name, component, this);
}
@@ -183,8 +184,28 @@
public virtual void Remove (IComponent component)
{
- c.Remove (component);
+ Remove (component, true);
}
+
+ private void Remove (IComponent component, bool unsite)
+ {
+ if (component.Site != null && component.Site.Container
== this) {
+ if (unsite) {
+ component.Site = null;
+ }
+ c.Remove (component);
+ }
+ }
+
+#if NET_2_0
+ protected void RemoveWithoutUnsiting (IComponent component)
+ {
+ if (component.Site != null && component.Site.Container
== this) {
+ Remove (component, false);
+ }
+ }
+#endif
+
}
}
Modified: trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog 2006-09-11
22:56:49 UTC (rev 65260)
+++ trunk/mcs/class/System/Test/System.ComponentModel/ChangeLog 2006-09-11
22:57:06 UTC (rev 65261)
@@ -1,5 +1,9 @@
2006-09-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+ * System.ComponentModel/ContainerTest.cs: new test.
+
+2006-09-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
* TypeDescriptorTests.cs: test for overriden attributes.
Patch by Ivan N. Zlatev.
Modified: trunk/mcs/class/System/Test/System.ComponentModel/ContainerTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.ComponentModel/ContainerTest.cs
2006-09-11 22:56:49 UTC (rev 65260)
+++ trunk/mcs/class/System/Test/System.ComponentModel/ContainerTest.cs
2006-09-11 22:57:06 UTC (rev 65261)
@@ -3,8 +3,10 @@
//
// Authors:
// Gonzalo Paniagua Javier ([EMAIL PROTECTED])
-//
+// Ivan N. Zlatev (contact i-nZ.net)
+
// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006 Ivan N. Zlatev
//
using NUnit.Framework;
@@ -27,6 +29,26 @@
protected override object GetService( Type serviceType ) {
return _services.GetService( serviceType );
}
+
+#if NET_2_0
+ public void Remove_WithoutUnsiting (IComponent component)
+ {
+ base.RemoveWithoutUnsiting (component);
+ }
+#endif
+
+ public bool Contains (IComponent component)
+ {
+ bool found = false;
+
+ foreach (IComponent c in Components) {
+ if (component.Equals (c)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+ }
}
class TestComponent : Component {
@@ -45,12 +67,45 @@
}
[TestFixture]
- public class ContainerTest {
+ public class ContainerTest
+ {
+
+ private TestContainer _container;
+
+ [SetUp]
+ public void Init ()
+ {
+ _container = new TestContainer ();
+ }
+
+
[Test]
+ public void AddRemove ()
+ {
+ bool found = false;
+ TestComponent component = new TestComponent ();
+
+ _container.Add (component);
+ Assert.IsNotNull (component.Site, "#1");
+ Assert.IsTrue (_container.Contains (component), "#2");
+
+ _container.Remove (component);
+ Assert.IsNull (component.Site, "#3");
+ Assert.IsFalse (_container.Contains (component), "#4");
+
+#if NET_2_0
+ _container.Add (component);
+ _container.Remove_WithoutUnsiting (component);
+ Assert.IsNotNull (component.Site, "#5");
+ Assert.IsFalse (_container.Contains (component), "#6");
+#endif
+ }
+
+
+ [Test]
public void GetService1 ()
{
- TestContainer container = new TestContainer ();
- container.Add (new TestComponent ());
+ _container.Add (new TestComponent ());
}
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches