[hyena] Make model's Selection a property



commit 0ce7113a79bd549e67f61e8381823cadc17b36d7
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu May 13 10:48:54 2010 -0700

    Make model's Selection a property
    
    And fix bug where the Selection's MaxIndex was updated by the ListView -
    so models without a ListView didn't have an up to date Selection.

 src/Hyena/Hyena.Data/BaseListModel.cs   |    7 ++++++-
 src/Hyena/Hyena.Data/MemoryListModel.cs |    2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/Hyena/Hyena.Data/BaseListModel.cs b/src/Hyena/Hyena.Data/BaseListModel.cs
index 221ec4e..43f6800 100644
--- a/src/Hyena/Hyena.Data/BaseListModel.cs
+++ b/src/Hyena/Hyena.Data/BaseListModel.cs
@@ -35,7 +35,7 @@ namespace Hyena.Data
 {
     public abstract class BaseListModel<T> : IListModel<T>
     {
-        protected Selection selection;
+        private Selection selection;
 
         public event EventHandler Cleared;
         public event EventHandler Reloaded;
@@ -46,6 +46,8 @@ namespace Hyena.Data
 
         protected virtual void OnCleared ()
         {
+            Selection.MaxIndex = Count - 1;
+
             EventHandler handler = Cleared;
             if(handler != null) {
                 handler(this, EventArgs.Empty);
@@ -54,6 +56,8 @@ namespace Hyena.Data
 
         protected virtual void OnReloaded ()
         {
+            Selection.MaxIndex = Count - 1;
+
             EventHandler handler = Reloaded;
             if(handler != null) {
                 handler(this, EventArgs.Empty);
@@ -80,6 +84,7 @@ namespace Hyena.Data
 
         public virtual Selection Selection {
             get { return selection; }
+            protected set { selection = value; }
         }
 
         protected ModelSelection<T> model_selection;
diff --git a/src/Hyena/Hyena.Data/MemoryListModel.cs b/src/Hyena/Hyena.Data/MemoryListModel.cs
index 27ca87e..cdc2822 100644
--- a/src/Hyena/Hyena.Data/MemoryListModel.cs
+++ b/src/Hyena/Hyena.Data/MemoryListModel.cs
@@ -40,7 +40,7 @@ namespace Hyena.Data
         public MemoryListModel ()
         {
             list = new List<T> ();
-            selection = new Selection ();
+            Selection = new Selection ();
         }
 
         public override void Clear ()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]