Author: toshok
Date: 2007-12-09 14:22:36 -0500 (Sun, 09 Dec 2007)
New Revision: 91012

Added:
   trunk/olive/class/WindowsBase/System.Collections.ObjectModel/
   
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ObservableCollection.cs
   
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ReadOnlyObservableCollection.cs
   trunk/olive/class/WindowsBase/Test/System.Collections.ObjectModel/
   
trunk/olive/class/WindowsBase/Test/System.Collections.ObjectModel/ObservableCollectionTest.cs
Modified:
   trunk/olive/class/WindowsBase/WindowsBase.dll.sources
   trunk/olive/class/WindowsBase/WindowsBase_test.dll.sources
Log:
add ObservableCollection/ReadOnlyObservableCollection, along with the start of 
unit tests

Added: 
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ObservableCollection.cs
===================================================================
--- 
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ObservableCollection.cs
        2007-12-09 19:22:06 UTC (rev 91011)
+++ 
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ObservableCollection.cs
        2007-12-09 19:22:36 UTC (rev 91012)
@@ -0,0 +1,98 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//     Chris Toshok ([EMAIL PROTECTED])
+//
+
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.ComponentModel;
+
+namespace System.Collections.ObjectModel {
+
+       [Serializable]
+       public class ObservableCollection<T> : Collection<T>, 
INotifyCollectionChanged, INotifyPropertyChanged
+       {
+               public ObservableCollection()
+               {
+               }
+
+               public ObservableCollection(List<T> list)
+                       : base (list)
+               {
+               }
+
+               public virtual event NotifyCollectionChangedEventHandler 
CollectionChanged;
+               protected virtual event PropertyChangedEventHandler 
PropertyChanged;
+
+               event PropertyChangedEventHandler 
INotifyPropertyChanged.PropertyChanged {
+                       add { this.PropertyChanged += value; }
+                       remove { this.PropertyChanged -= value; }
+               }
+
+               protected IDisposable BlockReentrancy ()
+               {
+                       return null;
+               }
+
+               protected void CheckReentrancy ()
+               {
+               }
+
+               protected override void ClearItems ()
+               {
+               }
+
+               protected override void InsertItem (int index, T item)
+               {
+               }
+
+               public void Move (int oldIndex, int newIndex)
+               {
+               }
+
+               protected virtual void MoveItem (int oldIndex, int newIndex)
+               {
+               }
+
+               protected virtual void OnCollectionChanged 
(NotifyCollectionChangedEventArgs e)
+               {
+                       if (CollectionChanged != null)
+                               CollectionChanged (this, e);
+               }
+
+               protected virtual void OnPropertyChanged 
(PropertyChangedEventArgs e)
+               {
+                       if (PropertyChanged != null)
+                               PropertyChanged (this, e);
+               }
+
+               protected override void RemoveItem (int index)
+               {
+               }
+
+               protected override void SetItem (int index, T item)
+               {
+               }
+       }
+}

Added: 
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ReadOnlyObservableCollection.cs
===================================================================
--- 
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ReadOnlyObservableCollection.cs
        2007-12-09 19:22:06 UTC (rev 91011)
+++ 
trunk/olive/class/WindowsBase/System.Collections.ObjectModel/ReadOnlyObservableCollection.cs
        2007-12-09 19:22:36 UTC (rev 91012)
@@ -0,0 +1,65 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//     Chris Toshok ([EMAIL PROTECTED])
+//
+
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.ComponentModel;
+
+namespace System.Collections.ObjectModel {
+
+       public class ReadOnlyObservableCollection<T> : ReadOnlyCollection<T>, 
INotifyCollectionChanged, INotifyPropertyChanged
+       {
+               public ReadOnlyObservableCollection (ObservableCollection<T> 
list)
+                       : base (list)
+               {
+               }
+
+               protected virtual event NotifyCollectionChangedEventHandler 
CollectionChanged;
+               protected virtual event PropertyChangedEventHandler 
PropertyChanged;
+
+               event NotifyCollectionChangedEventHandler 
INotifyCollectionChanged.CollectionChanged {
+                       add { this.CollectionChanged += value; }
+                       remove { this.CollectionChanged -= value; }
+               }
+               event PropertyChangedEventHandler 
INotifyPropertyChanged.PropertyChanged {
+                       add { this.PropertyChanged += value; }
+                       remove { this.PropertyChanged -= value; }
+               }
+
+               protected virtual void OnCollectionChanged 
(NotifyCollectionChangedEventArgs args)
+               {
+                       if (CollectionChanged != null)
+                               CollectionChanged (this, args);
+               }
+
+               protected virtual void OnPropertyChanged 
(PropertyChangedEventArgs args)
+               {
+                       if (PropertyChanged != null)
+                               PropertyChanged (this, args);
+               }
+       }
+
+}

Added: 
trunk/olive/class/WindowsBase/Test/System.Collections.ObjectModel/ObservableCollectionTest.cs
===================================================================
--- 
trunk/olive/class/WindowsBase/Test/System.Collections.ObjectModel/ObservableCollectionTest.cs
       2007-12-09 19:22:06 UTC (rev 91011)
+++ 
trunk/olive/class/WindowsBase/Test/System.Collections.ObjectModel/ObservableCollectionTest.cs
       2007-12-09 19:22:36 UTC (rev 91012)
@@ -0,0 +1,96 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+//     Chris Toshok ([EMAIL PROTECTED])
+//
+
+using System;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using NUnit.Framework;
+
+namespace MonoTests.System.Collections.ObjectModel {
+
+       [TestFixture]
+       public class ObservableCollectionTest {
+               [Test]
+               public void InsertItem ()
+               {
+                       bool reached = false;
+                       ObservableCollection<int> col = new 
ObservableCollection<int>();
+                       col.CollectionChanged += delegate (object sender, 
NotifyCollectionChangedEventArgs e) {
+                               reached = true;
+                               Assert.AreEqual 
(NotifyCollectionChangedAction.Add, e.Action);
+                               Assert.AreEqual (0, e.NewStartingIndex);
+                               Assert.AreEqual (-1, e.OldStartingIndex);
+                               Assert.AreEqual (1, e.NewItems.Count);
+                               Assert.AreEqual (5, (int)e.NewItems[0]);
+                               Assert.AreEqual (null, e.OldItems);
+                       };
+                       col.Insert (0, 5);
+                       Assert.IsTrue (reached);
+               }
+
+               [Test]
+               public void Remove ()
+               {
+                       bool reached = false;
+                       ObservableCollection<int> col = new 
ObservableCollection<int>();
+                       col.Insert (0, 5);
+                       col.CollectionChanged += delegate (object sender, 
NotifyCollectionChangedEventArgs e) {
+                               reached = true;
+                               Assert.AreEqual 
(NotifyCollectionChangedAction.Remove, e.Action);
+                               Assert.AreEqual (-1, e.NewStartingIndex);
+                               Assert.AreEqual (0, e.OldStartingIndex);
+                               Assert.AreEqual (null, e.NewItems);
+                               Assert.AreEqual (1, e.OldItems.Count);
+                               Assert.AreEqual (5, (int)e.OldItems[0]);
+                       };
+                       col.RemoveAt (0);
+                       Assert.IsTrue (reached, "reached");
+               }
+
+               [Test]
+               public void Move ()
+               {
+                       bool reached = false;
+                       ObservableCollection<int> col = new 
ObservableCollection<int>();
+                       col.Insert (0, 0);
+                       col.Insert (1, 1);
+                       col.Insert (2, 2);
+                       col.Insert (3, 3);
+                       col.CollectionChanged += delegate (object sender, 
NotifyCollectionChangedEventArgs e) {
+                               reached = true;
+                               Assert.AreEqual 
(NotifyCollectionChangedAction.Move, e.Action, "1");
+                               Assert.AreEqual (3, e.NewStartingIndex, "2");
+                               Assert.AreEqual (1, e.OldStartingIndex, "3");
+                               Assert.AreEqual (1, e.NewItems.Count, "4");
+                               Assert.AreEqual (1, e.NewItems[0], "5");
+                               Assert.AreEqual (1, e.OldItems.Count, "6");
+                               Assert.AreEqual (1, e.OldItems[0], "7");
+                       };
+                       col.Move (1, 3);
+                       Assert.IsTrue (reached, "8");
+               }
+       }
+
+}

Modified: trunk/olive/class/WindowsBase/WindowsBase.dll.sources
===================================================================
--- trunk/olive/class/WindowsBase/WindowsBase.dll.sources       2007-12-09 
19:22:06 UTC (rev 91011)
+++ trunk/olive/class/WindowsBase/WindowsBase.dll.sources       2007-12-09 
19:22:36 UTC (rev 91012)
@@ -1,3 +1,5 @@
+System.Collections.ObjectModel/ObservableCollection.cs
+System.Collections.ObjectModel/ReadOnlyObservableCollection.cs
 System.Collections.Specialized/CollectionChangedEventManager.cs
 System.Collections.Specialized/INotifyCollectionChanged.cs
 System.Collections.Specialized/NotifyCollectionChangedAction.cs

Modified: trunk/olive/class/WindowsBase/WindowsBase_test.dll.sources
===================================================================
--- trunk/olive/class/WindowsBase/WindowsBase_test.dll.sources  2007-12-09 
19:22:06 UTC (rev 91011)
+++ trunk/olive/class/WindowsBase/WindowsBase_test.dll.sources  2007-12-09 
19:22:36 UTC (rev 91012)
@@ -1,3 +1,4 @@
+System.Collections.ObjectModel/ObservableCollectionTest.cs
 System.Windows/DependencyObjectTest.cs
 System.Windows/DependencyObjectTypeTest.cs
 System.Windows/DependencyPropertyTest.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to