[tasque/viewmodel: 3/78] ModelReVamp 5000



commit fbe0137c409cfb1e723ca0fb3bc6ef4b9309c6a4
Author: Antonius Riha <antoniusriha gmail com>
Date:   Fri Jul 13 14:57:12 2012 +0200

    ModelReVamp 5000
    
    *awesome commit name*

 src/libtasque/Backend.cs                           |   12 ++--
 src/libtasque/Category.cs                          |    2 +-
 src/{tasque => libtasque}/Logger.cs                |    0
 ...ection.cs => ReadOnlySortedNotifyCollection.cs} |    6 +-
 ...tifyCollection.cs => SortedNotifyCollection.cs} |    4 +-
 src/libtasque/Task.cs                              |   94 +++++++++++++++++---
 src/libtasque/libtasque.csproj                     |   13 +--
 src/tasque/Backends/Dummy/DummyTask.cs             |   86 +-----------------
 src/tasque/tasque.csproj                           |    1 -
 9 files changed, 97 insertions(+), 121 deletions(-)
---
diff --git a/src/libtasque/Backend.cs b/src/libtasque/Backend.cs
index d23eeba..e5320b3 100644
--- a/src/libtasque/Backend.cs
+++ b/src/libtasque/Backend.cs
@@ -44,11 +44,11 @@ namespace Tasque
 
 			Name = name;
 
-			tasks = new NotifyCollection<Task> ();
-			Tasks = new ReadOnlyNotifyCollection<Task> (tasks);
+			tasks = new SortedNotifyCollection<Task> ();
+			Tasks = new ReadOnlySortedNotifyCollection<Task> (tasks);
 
 			categoriesChangedSources = new List<INotifyCollectionChanged> ();
-			Categories = new NotifyCollection<Category> ();
+			Categories = new SortedNotifyCollection<Category> ();
 			Categories.CollectionChanged += HandleCategoriesChanged;
 		}
 
@@ -56,7 +56,7 @@ namespace Tasque
 		/// <value>
 		/// This returns all the ICategory items from the backend.
 		/// </value>
-		public NotifyCollection<Category> Categories { get; private set; }
+		public SortedNotifyCollection<Category> Categories { get; private set; }
 
 		/// <value>
 		/// Indication that the backend has enough information
@@ -88,7 +88,7 @@ namespace Tasque
 		/// <value>
 		/// All the tasks provided by the backend.
 		/// </value>
-		public ReadOnlyNotifyCollection<Task> Tasks { get; private set; }
+		public ReadOnlySortedNotifyCollection<Task> Tasks { get; private set; }
 		#endregion
 		
 		#region Methods
@@ -237,6 +237,6 @@ namespace Tasque
 		}
 
 		List<INotifyCollectionChanged> categoriesChangedSources;
-		NotifyCollection<Task> tasks;
+		SortedNotifyCollection<Task> tasks;
 	}
 }
diff --git a/src/libtasque/Category.cs b/src/libtasque/Category.cs
index 49d3355..0b2037b 100644
--- a/src/libtasque/Category.cs
+++ b/src/libtasque/Category.cs
@@ -28,7 +28,7 @@ using System.ComponentModel;
 
 namespace Tasque
 {
-	public class Category : NotifyCollection<Task>, IComparable<Category>, INotifyPropertyChanged
+	public class Category : SortedNotifyCollection<Task>, IComparable<Category>, INotifyPropertyChanged
 	{
 		public Category (string name)
 		{
diff --git a/src/tasque/Logger.cs b/src/libtasque/Logger.cs
similarity index 100%
rename from src/tasque/Logger.cs
rename to src/libtasque/Logger.cs
diff --git a/src/libtasque/ReadOnlyNotifyCollection.cs b/src/libtasque/ReadOnlySortedNotifyCollection.cs
similarity index 92%
rename from src/libtasque/ReadOnlyNotifyCollection.cs
rename to src/libtasque/ReadOnlySortedNotifyCollection.cs
index a6185e2..cf977d8 100644
--- a/src/libtasque/ReadOnlyNotifyCollection.cs
+++ b/src/libtasque/ReadOnlySortedNotifyCollection.cs
@@ -31,10 +31,10 @@ using System.ComponentModel;
 
 namespace Tasque
 {
-	public class ReadOnlyNotifyCollection<T> : ICollection<T>, INotifyCollectionChanged
+	public class ReadOnlySortedNotifyCollection<T> : ICollection<T>, INotifyCollectionChanged
 		where T : INotifyPropertyChanged, IComparable<T>
 	{
-		public ReadOnlyNotifyCollection (NotifyCollection<T> source)
+		public ReadOnlySortedNotifyCollection (SortedNotifyCollection<T> source)
 		{
 			if (source == null)
 				throw new ArgumentNullException ("source");
@@ -92,6 +92,6 @@ namespace Tasque
 		}
 		#endregion
 
-		NotifyCollection<T> items;
+		SortedNotifyCollection<T> items;
 	}
 }
diff --git a/src/libtasque/NotifyCollection.cs b/src/libtasque/SortedNotifyCollection.cs
similarity index 96%
rename from src/libtasque/NotifyCollection.cs
rename to src/libtasque/SortedNotifyCollection.cs
index 50d2964..bc146e3 100644
--- a/src/libtasque/NotifyCollection.cs
+++ b/src/libtasque/SortedNotifyCollection.cs
@@ -32,10 +32,10 @@ using System.ComponentModel;
 
 namespace Tasque
 {
-	public class NotifyCollection<T> : ICollection<T>, INotifyCollectionChanged
+	public class SortedNotifyCollection<T> : ICollection<T>, INotifyCollectionChanged
 		where T : INotifyPropertyChanged, IComparable<T>
 	{
-		public NotifyCollection ()
+		public SortedNotifyCollection ()
 		{
 			items = new ObservableCollection<T> ();
 		}
diff --git a/src/libtasque/Task.cs b/src/libtasque/Task.cs
index 3c35927..f0a918a 100644
--- a/src/libtasque/Task.cs
+++ b/src/libtasque/Task.cs
@@ -24,16 +24,20 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 using System;
-using System.Collections.ObjectModel;
 using System.ComponentModel;
+using System.Collections.ObjectModel;
 
 namespace Tasque
 {
 	public abstract class Task : IComparable<Task>, INotifyPropertyChanged
 	{
-		protected Task (string name)
+		protected Task (string name, TaskNoteSupport noteSupport)
 		{
 			Name = name;
+			notes = new ObservableCollection<TaskNote> ();
+			Notes = new ReadOnlyObservableCollection<TaskNote> (notes);
+
+			NoteSupport = noteSupport;
 		}
 		
 		#region Properties
@@ -51,9 +55,31 @@ namespace Tasque
 			}
 		}
 		
-		public abstract DateTime DueDate { get; set; }
+		public DateTime DueDate
+		{
+			get { return dueDate; }
+			set {
+				if (value != dueDate) {
+					Logger.Debug ("Setting new task due date");
+					dueDate = value;
+					OnDueDateChanged ();
+					OnPropertyChanged ("DueDate");
+				}
+			}
+		}
 		
-		public abstract DateTime CompletionDate { get; set; }
+		public DateTime CompletionDate
+		{
+			get { return completionDate; }
+			protected set {
+				if (value != completionDate) {
+					Logger.Debug ("Setting new task completion date");
+					completionDate = value;
+					OnCompletionDateChanged ();
+					OnPropertyChanged ("CompletionDate");
+				}
+			}
+		}
 
 		public bool HasNotes { get { return Notes.Count > 0; } }
 
@@ -63,13 +89,33 @@ namespace Tasque
 
 		public bool IsDueDateSet { get { return DueDate != DateTime.MinValue; } }
 
-		public abstract ReadOnlyObservableCollection<TaskNote> Notes { get; }
+		public ReadOnlyObservableCollection<TaskNote> Notes { get; private set; }
 
-		public abstract TaskPriority Priority { get; set; }
+		public TaskPriority Priority
+		{
+			get { return priority; }
+			set {
+				if (value != priority) {
+					Logger.Debug ("Setting new task priority");
+					priority = value;
+					OnPriorityChanged ();
+					OnPropertyChanged ("Priority");
+				}
+			}
+		}
 
-		public abstract TaskState State { get; }
+		public TaskState State {
+			get { return state; }
+			protected set {
+				if (state != value) {
+					state = value;
+					OnStateChanged ();
+					OnPropertyChanged ("State");
+				}
+			}
+		}
 
-		public abstract TaskNoteSupport TaskNoteSupport { get; }
+		public TaskNoteSupport NoteSupport { get; private set; }
 		#endregion
 		
 		#region Methods
@@ -80,10 +126,11 @@ namespace Tasque
 			if (note == null)
 				throw new ArgumentNullException ("note");
 
-			if (Notes.Contains (note))
+			if (notes.Contains (note))
 				return;
 
-			OnAddNote ();
+			OnAddNote (note);
+			notes.Add (note);
 		}
 
 		public int CompareTo (Task task)
@@ -118,21 +165,35 @@ namespace Tasque
 
 		public abstract void Complete ();
 
-		public abstract TaskNote CreateNote(string text);
-
 		public abstract void Delete ();
 
-		public abstract bool DeleteNote(TaskNote note);
+		public bool RemoveNote (TaskNote note)
+		{
+			if (notes.Contains (note))
+				OnRemoveNote (note);
+
+			return notes.Remove (note);
+		}
+
+		protected virtual void OnAddNote (TaskNote note) {}
+
+		protected virtual void OnCompletionDateChanged () {}
 
-		protected abstract void OnAddNote ();
+		protected virtual void OnDueDateChanged () {}
 
 		protected virtual void OnNameChanged () {}
 
+		protected virtual void OnPriorityChanged () {}
+
 		protected void OnPropertyChanged (string propertyName)
 		{
 			if (PropertyChanged != null)
 				PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
 		}
+
+		protected virtual void OnRemoveNote (TaskNote note) {}
+
+		protected virtual void OnStateChanged () {}
 		#endregion
 
 		public event PropertyChangedEventHandler PropertyChanged;
@@ -163,6 +224,11 @@ namespace Tasque
 			return Name.CompareTo (task.Name);
 		}
 
+		DateTime completionDate;
+		DateTime dueDate;
 		string name;
+		ObservableCollection<TaskNote> notes;
+		TaskPriority priority;
+		TaskState state;
 	}
 }
diff --git a/src/libtasque/libtasque.csproj b/src/libtasque/libtasque.csproj
index 8ea27c5..99d620c 100644
--- a/src/libtasque/libtasque.csproj
+++ b/src/libtasque/libtasque.csproj
@@ -164,14 +164,13 @@
     <Compile Include="TaskNote.cs" />
     <Compile Include="TaskNoteSupport.cs" />
     <Compile Include="TaskCompletionDateComparer.cs" />
-    <Compile Include="NotifyCollection.cs" />
-    <Compile Include="ReadOnlyNotifyCollection.cs" />
+    <Compile Include="SortedNotifyCollection.cs" />
+    <Compile Include="ReadOnlySortedNotifyCollection.cs" />
+    <Compile Include="Logger.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
-    <Reference Include="System.Core" />
     <Reference Include="Mono.Posix" />
-    <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="DateFormatters\" />
@@ -208,10 +207,4 @@
   <Target Name="AfterBuild">
     <Copy SourceFiles="@(DocsSourcesFile)" DestinationFolder="$(OutputPath)" />
   </Target>
-  <ItemGroup>
-    <ProjectReference Include="..\ObservableTransformCollections\CollectionView\CollectionView.csproj">
-      <Project>{A5AAD70F-F4E8-4CAE-A000-01C2D0A10B92}</Project>
-      <Name>CollectionView</Name>
-    </ProjectReference>
-  </ItemGroup>
 </Project>
diff --git a/src/tasque/Backends/Dummy/DummyTask.cs b/src/tasque/Backends/Dummy/DummyTask.cs
index ead14a9..3f7f5f0 100644
--- a/src/tasque/Backends/Dummy/DummyTask.cs
+++ b/src/tasque/Backends/Dummy/DummyTask.cs
@@ -26,77 +26,19 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 using System;
-using System.Collections.Generic;
 using Tasque;
-using System.Collections.ObjectModel;
 
 namespace Tasque.Backends.Dummy
 {
 	public class DummyTask : Task
 	{
-		public DummyTask(string name) : base (name)
-		{
-			notes = new ObservableCollection<TaskNote> ();
-			Notes = new ReadOnlyObservableCollection<TaskNote> (notes);
-		}
-		
-		#region Public Properties
-		public override DateTime CompletionDate
-		{
-			get { return completionDate; }
-			set {
-				if (value != completionDate) {
-					Logger.Debug ("Setting new task completion date");
-					completionDate = value;
-					OnPropertyChanged ("CompletionDate");
-				}
-			}
-		}
-
-		public override DateTime DueDate
-		{
-			get { return dueDate; }
-			set {
-				if (value != dueDate) {
-					Logger.Debug ("Setting new task due date");
-					dueDate = value;
-					OnPropertyChanged ("DueDate");
-				}
-			}
-		}
-
-		public override ReadOnlyObservableCollection<TaskNote> Notes { get; private set; }
-
-		public override TaskPriority Priority
-		{
-			get { return priority; }
-			set {
-				if (value != priority) {
-					Logger.Debug ("Setting new task priority");
-					priority = value;
-					OnPropertyChanged ("Priority");
-				}
-			}
-		}
-
-		public override TaskState State {
-			get { return state; }
-			set {
-				if (state != value) {
-					state = value;
-					OnPropertyChanged ("State");
-				}
-			}
-		}
-
-		public override TaskNoteSupport TaskNoteSupport { get { return TaskNoteSupport.Multiple; } }
-		#endregion
+		public DummyTask(string name) : base (name, TaskNoteSupport.Multiple) {}
 		
 		#region Public Methods
 		public override void Activate ()
 		{
 			Logger.Debug ("DummyTask.Activate ()");
-			completionDate = DateTime.MinValue;
+			CompletionDate = DateTime.MinValue;
 			State = TaskState.Active;
 		}
 		
@@ -112,30 +54,6 @@ namespace Tasque.Backends.Dummy
 			Logger.Debug ("DummyTask.Delete ()");
 			State = TaskState.Deleted;
 		}
-		
-		public override TaskNote CreateNote(string text)
-		{
-			if (text == null)
-				throw new ArgumentNullException ("text");
-
-			var note = new TaskNote (text);
-			notes.Add (note);
-			return note;
-		}
-		
-		public override void DeleteNote(TaskNote note)
-		{
-		}
-
-		public override void SaveNote(TaskNote note)
-		{
-		}
 		#endregion
-
-		DateTime completionDate;
-		DateTime dueDate;
-		ObservableCollection<TaskNote> notes;
-		TaskPriority priority;
-		TaskState state;
 	}
 }
diff --git a/src/tasque/tasque.csproj b/src/tasque/tasque.csproj
index 01a332c..4a986b3 100644
--- a/src/tasque/tasque.csproj
+++ b/src/tasque/tasque.csproj
@@ -216,7 +216,6 @@
     <Compile Include="CompletedTaskGroup.cs" />
     <Compile Include="CompletedTaskGroupModel.cs" />
     <Compile Include="DateButton.cs" />
-    <Compile Include="Logger.cs" />
     <Compile Include="NoteDialog.cs" />
     <Compile Include="NoteWidget.cs" />
     <Compile Include="Preferences.cs" />



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