[tasque/transition: 65/213] Transition to CollectionView and TreeModelListAdapter
- From: Antonius Riha <antoniusri src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tasque/transition: 65/213] Transition to CollectionView and TreeModelListAdapter
- Date: Wed, 29 Aug 2012 18:39:29 +0000 (UTC)
commit 28da7c66c9baa0ae4bb37c236d4526f758e4da47
Author: Antonius Riha <antoniusriha gmail com>
Date: Sun Jul 8 21:39:56 2012 +0200
Transition to CollectionView and TreeModelListAdapter
* IBackend.cs: SortedTasks is now IEnumerable, so it can be assigned from CollectionView.
* ITask.cs:
- ITask needs to be an INotifyPropertyChanged for the CollectionView to work properly.
- There is no need for the CompareTo method anymore. This is already defined in IComparable<T>.
* AbstractTask.cs: Provide a OnNotifyPropertyChanged method for children to call.
* Application.cs:
- Hook up tooltip change handler with CollectionView's CollectionChanged event.
- Use CollectionView.Count to retrieve the number of items in the View.
* DummyBackend.cs: Apply CollectionView for SortedTasks implementation. Use the default comparer (which is used by the default SortDescription).
* DummyTask.cs: Fire OnPropertyChanged events instead of calling IBackend.UpdateTask (ITask).
* CompletedTaskGroup.cs:
- Add static helper method for creating the completed tasks' CollectionView.
- Remove CompletedTasksComparer, which is obsolete since the introduction of CollectionView.
* CompletedTaskGroupModel.cs:
- Adjust FilterTasks method to meet the requirements of CollectionView.Filter predicate.
- Adjust to changes of base class.
* TaskGroup.cs:
- Adjust for the use of CollectionView
- Use TreeModelListAdapter<ITask> to hook up the underlying CollectionView with the TreeView.
- Use CollectionView.Refresh method to reflect changes in the filter.
* TaskGroupModel.cs:
- Change base class from TreeModelFilter to CollectionView<ITask> and adjust resp. members appropriately
- Rearrange some members to better meet oo design concepts
- Shorten IsToday method.
* TaskGroupModelFactory.cs: Adjust to new TaskGroupModel class.
src/libtasque/IBackend.cs | 3 +-
src/libtasque/ITask.cs | 15 +----
src/tasque/AbstractTask.cs | 9 +++
src/tasque/Application.cs | 20 ++----
src/tasque/Backends/Dummy/DummyBackend.cs | 17 +++--
src/tasque/Backends/Dummy/DummyTask.cs | 59 +++++++++-------
src/tasque/CompletedTaskGroup.cs | 35 +++++-----
src/tasque/CompletedTaskGroupModel.cs | 39 ++++++++---
src/tasque/TaskGroup.cs | 43 +++++++++---
src/tasque/TaskGroupModel.cs | 107 +++++++++++++++++------------
src/tasque/TaskGroupModelFactory.cs | 37 ++++++++--
11 files changed, 236 insertions(+), 148 deletions(-)
---
diff --git a/src/libtasque/IBackend.cs b/src/libtasque/IBackend.cs
index e41b885..8bfaf4a 100644
--- a/src/libtasque/IBackend.cs
+++ b/src/libtasque/IBackend.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
+using System.Collections;
namespace Tasque.Backends
{
@@ -38,7 +39,7 @@ namespace Tasque.Backends
get;
}
- IEnumerable<ITask> SortedTasks {
+ IEnumerable SortedTasks {
get;
}
diff --git a/src/libtasque/ITask.cs b/src/libtasque/ITask.cs
index 852c263..18dba53 100644
--- a/src/libtasque/ITask.cs
+++ b/src/libtasque/ITask.cs
@@ -3,10 +3,11 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
namespace Tasque
{
- public interface ITask : IComparable<ITask>
+ public interface ITask : IComparable<ITask>, INotifyPropertyChanged
{
#region Properties
/// <value>
@@ -144,18 +145,6 @@ namespace Tasque
void SaveNote (INote note);
/// <summary>
- /// This is used for sorting tasks in the TaskWindow and should compare
- /// based on due date.
- /// </summary>
- /// <param name="task">
- /// A <see cref="ITask"/>
- /// </param>
- /// <returns>
- /// A <see cref="System.Int32"/>
- /// </returns>
- int CompareTo (ITask task);
-
- /// <summary>
/// This is the same as CompareTo above but should use completion date
/// instead of due date. This is used to sort items in the
/// CompletedTaskGroup.
diff --git a/src/tasque/AbstractTask.cs b/src/tasque/AbstractTask.cs
index 3aa5a2d..32be7ef 100644
--- a/src/tasque/AbstractTask.cs
+++ b/src/tasque/AbstractTask.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
namespace Tasque
{
@@ -150,6 +151,14 @@ namespace Tasque
return CompareByPriorityAndName (task);
}
#endregion // Methods
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ protected void OnPropertyChanged (string propertyName)
+ {
+ if (PropertyChanged != null)
+ PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
+ }
#region Private Methods
diff --git a/src/tasque/Application.cs b/src/tasque/Application.cs
index 652c560..fe570eb 100644
--- a/src/tasque/Application.cs
+++ b/src/tasque/Application.cs
@@ -453,13 +453,10 @@ namespace Tasque
{
foreach (TaskGroupModel model in new TaskGroupModel[] { overdue_tasks, today_tasks, tomorrow_tasks })
{
- if (model == null) {
+ if (model == null)
continue;
- }
- model.RowInserted -= OnTooltipModelChanged;
- model.RowChanged -= OnTooltipModelChanged;
- model.RowDeleted -= OnTooltipModelChanged;
+ model.CollectionChanged -= OnTooltipModelChanged;
}
}
@@ -484,13 +481,10 @@ namespace Tasque
foreach (TaskGroupModel model in new TaskGroupModel[] { overdue_tasks, today_tasks, tomorrow_tasks })
{
- if (model == null) {
+ if (model == null)
continue;
- }
- model.RowInserted += OnTooltipModelChanged;
- model.RowChanged += OnTooltipModelChanged;
- model.RowDeleted += OnTooltipModelChanged;
+ model.CollectionChanged += OnTooltipModelChanged;
}
}
@@ -502,7 +496,7 @@ namespace Tasque
StringBuilder sb = new StringBuilder ();
if (overdue_tasks != null) {
- int count = overdue_tasks.IterNChildren ();
+ int count = overdue_tasks.Count;
if (count > 0) {
sb.Append (String.Format (Catalog.GetPluralString ("{0} task is Overdue\n", "{0} tasks are Overdue\n", count), count));
@@ -510,7 +504,7 @@ namespace Tasque
}
if (today_tasks != null) {
- int count = today_tasks.IterNChildren ();
+ int count = today_tasks.Count;
if (count > 0) {
sb.Append (String.Format (Catalog.GetPluralString ("{0} task for Today\n", "{0} tasks for Today\n", count), count));
@@ -518,7 +512,7 @@ namespace Tasque
}
if (tomorrow_tasks != null) {
- int count = tomorrow_tasks.IterNChildren ();
+ int count = tomorrow_tasks.Count;
if (count > 0) {
sb.Append (String.Format (Catalog.GetPluralString ("{0} task for Tomorrow\n", "{0} tasks for Tomorrow\n", count), count));
diff --git a/src/tasque/Backends/Dummy/DummyBackend.cs b/src/tasque/Backends/Dummy/DummyBackend.cs
index 49e0fbe..be9eb9d 100644
--- a/src/tasque/Backends/Dummy/DummyBackend.cs
+++ b/src/tasque/Backends/Dummy/DummyBackend.cs
@@ -2,11 +2,11 @@
// User: boyd at 7:10 AMÂ2/11/2008
using System;
-using System.Collections.Generic;
-using Mono.Unix;
using Tasque.Backends;
using System.Collections.ObjectModel;
-using System.Linq;
+using CollectionTransforms;
+using System.ComponentModel;
+using System.Collections;
namespace Tasque.Backends.Dummy
{
@@ -39,6 +39,13 @@ namespace Tasque.Backends.Dummy
initialized = false;
newTaskId = 0;
Tasks = new ObservableCollection<ITask> ();
+ var cv = new CollectionView<ITask> (Tasks);
+ /*
+ * this invokes the default comparer, which in turn
+ * will use the IComparable implmentation of Task
+ */
+ cv.SortDescriptions.Add (new SortDescription ());
+ SortedTasks = cv;
categoryListStore = new Gtk.ListStore (typeof(ICategory));
@@ -55,9 +62,7 @@ namespace Tasque.Backends.Dummy
/// <value>
/// All the tasks including ITaskDivider items.
/// </value>
- public IEnumerable<ITask> SortedTasks {
- get { return Tasks.OrderBy (t => t, Comparer<ITask>.Default); }
- }
+ public IEnumerable SortedTasks { get; private set; }
public ObservableCollection<ITask> Tasks { get; private set; }
diff --git a/src/tasque/Backends/Dummy/DummyTask.cs b/src/tasque/Backends/Dummy/DummyTask.cs
index e8e86e3..1033d83 100644
--- a/src/tasque/Backends/Dummy/DummyTask.cs
+++ b/src/tasque/Backends/Dummy/DummyTask.cs
@@ -47,13 +47,14 @@ namespace Tasque.Backends.Dummy
{
get { return name; }
set {
-Logger.Debug ("Setting new task name");
- if (value == null)
- name = string.Empty;
+ if (value != name) {
+ Logger.Debug ("Setting new task name");
+ if (value == null)
+ name = string.Empty;
- name = value.Trim ();
-
- backend.UpdateTask (this);
+ name = value.Trim ();
+ OnPropertyChanged ("Name");
+ }
}
}
@@ -61,10 +62,11 @@ Logger.Debug ("Setting new task name");
{
get { return dueDate; }
set {
-Logger.Debug ("Setting new task due date");
- dueDate = value;
-
- backend.UpdateTask (this);
+ if (value != dueDate) {
+ Logger.Debug ("Setting new task due date");
+ dueDate = value;
+ OnPropertyChanged ("DueDate");
+ }
}
}
@@ -72,10 +74,11 @@ Logger.Debug ("Setting new task due date");
{
get { return completionDate; }
set {
-Logger.Debug ("Setting new task completion date");
- completionDate = value;
-
- backend.UpdateTask (this);
+ if (value != completionDate) {
+ Logger.Debug ("Setting new task completion date");
+ completionDate = value;
+ OnPropertyChanged ("CompletionDate");
+ }
}
}
@@ -88,10 +91,11 @@ Logger.Debug ("Setting new task completion date");
{
get { return priority; }
set {
-Logger.Debug ("Setting new task priority");
- priority = value;
-
- backend.UpdateTask (this);
+ if (value != priority) {
+ Logger.Debug ("Setting new task priority");
+ priority = value;
+ OnPropertyChanged ("Priority");
+ }
}
}
@@ -114,7 +118,10 @@ Logger.Debug ("Setting new task priority");
{
get { return category; }
set {
- category = value as DummyCategory;
+ if (value != category) {
+ category = value as DummyCategory;
+ OnPropertyChanged ("Category");
+ }
}
}
@@ -128,18 +135,18 @@ Logger.Debug ("Setting new task priority");
#region Public Methods
public override void Activate ()
{
-Logger.Debug ("DummyTask.Activate ()");
+ Logger.Debug ("DummyTask.Activate ()");
completionDate = DateTime.MinValue;
state = TaskState.Active;
- backend.UpdateTask (this);
+ OnPropertyChanged ("State");
}
public override void Inactivate ()
{
-Logger.Debug ("DummyTask.Inactivate ()");
+ Logger.Debug ("DummyTask.Inactivate ()");
completionDate = DateTime.Now;
state = TaskState.Inactive;
- backend.UpdateTask (this);
+ OnPropertyChanged ("State");
}
public override void Complete ()
@@ -147,14 +154,14 @@ Logger.Debug ("DummyTask.Inactivate ()");
Logger.Debug ("DummyTask.Complete ()");
CompletionDate = DateTime.Now;
state = TaskState.Completed;
- backend.UpdateTask (this);
+ OnPropertyChanged ("State");
}
public override void Delete ()
{
-Logger.Debug ("DummyTask.Delete ()");
+ Logger.Debug ("DummyTask.Delete ()");
state = TaskState.Deleted;
- backend.UpdateTask (this);
+ OnPropertyChanged ("State");
}
public override INote CreateNote(string text)
diff --git a/src/tasque/CompletedTaskGroup.cs b/src/tasque/CompletedTaskGroup.cs
index c663f29..43e5c0b 100644
--- a/src/tasque/CompletedTaskGroup.cs
+++ b/src/tasque/CompletedTaskGroup.cs
@@ -10,6 +10,9 @@ using Mono.Unix;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
+using System.Collections;
+using CollectionTransforms;
+using System.ComponentModel;
namespace Tasque
{
@@ -24,14 +27,25 @@ namespace Tasque
public class CompletedTaskGroup : TaskGroup
{
+ /// <summary>
+ /// The purpose of this method is to allow the CompletedTaskGroup to show
+ /// completed tasks in reverse order (i.e., most recently completed tasks
+ /// at the top of the list).
+ /// </summary>
+ static IEnumerable GetSortedTasks (IEnumerable tasks)
+ {
+ var cv = new CollectionView<ITask> (tasks);
+ cv.SortDescriptions.Add (new SortDescription ("CompletionDate", ListSortDirection.Descending));
+ return cv;
+ }
+
ICategory selectedCategory;
HScale rangeSlider;
ShowCompletedRange currentRange;
public CompletedTaskGroup (string groupName, DateTime rangeStart,
- DateTime rangeEnd, IEnumerable<ITask> tasks)
- : base (groupName, rangeStart, rangeEnd,
- tasks.OrderBy (f => f, new CompletedTasksComparer ()))
+ DateTime rangeEnd, IEnumerable tasks)
+ : base (groupName, rangeStart, rangeEnd, GetSortedTasks (tasks))
{
// Don't hide this group when it's empty because then the range
// slider won't appear and the user won't be able to customize the
@@ -80,7 +94,7 @@ namespace Tasque
protected override TaskGroupModel CreateModel (DateTime rangeStart,
DateTime rangeEnd,
- IEnumerable<ITask> tasks)
+ IEnumerable tasks)
{
return new CompletedTaskGroupModel (rangeStart, rangeEnd, tasks);
}
@@ -208,17 +222,4 @@ namespace Tasque
this.TimeRangeStart = date;
}
}
-
- /// <summary>
- /// The purpose of this class is to allow the CompletedTaskGroup to show
- /// completed tasks in reverse order (i.e., most recently completed tasks
- /// at the top of the list).
- /// </summary>
- class CompletedTasksComparer : Comparer<ITask>
- {
- public override int Compare (ITask x, ITask y)
- {
- return x.CompareToByCompletionDate (y);
- }
- }
}
diff --git a/src/tasque/CompletedTaskGroupModel.cs b/src/tasque/CompletedTaskGroupModel.cs
index 3ecbf3a..53e7ac7 100644
--- a/src/tasque/CompletedTaskGroupModel.cs
+++ b/src/tasque/CompletedTaskGroupModel.cs
@@ -1,14 +1,36 @@
-
+//
+// CompletedTaskGroupModel.cs
+//
+// Author:
+// Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 Antonius Riha
+//
+// 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.
using System;
-using Gtk;
-using System.Collections.ObjectModel;
-using System.Collections.Generic;
+using System.Collections;
namespace Tasque
{
public class CompletedTaskGroupModel : TaskGroupModel
{
- public CompletedTaskGroupModel (DateTime rangeStart, DateTime rangeEnd, IEnumerable<ITask> tasks)
+ public CompletedTaskGroupModel (DateTime rangeStart, DateTime rangeEnd, IEnumerable tasks)
: base (rangeStart, rangeEnd, tasks)
{
}
@@ -26,19 +48,18 @@ namespace Tasque
/// <returns>
/// A <see cref="System.Boolean"/>
/// </returns>
- protected override bool FilterTasks (TreeModel model, TreeIter iter)
+ protected override bool FilterTasks (ITask task)
{
// Don't show any task here if showCompletedTasks is false
- if (!showCompletedTasks)
+ if (!ShowCompletedTasks)
return false;
- ITask task = model.GetValue (iter, 0) as ITask;
if (task == null || task.State != TaskState.Completed)
return false;
// Make sure that the task fits into the specified range depending
// on what the user has set the range slider to be.
- if (task.CompletionDate < this.timeRangeStart)
+ if (task.CompletionDate < TimeRangeStart)
return false;
if (task.CompletionDate == DateTime.MinValue)
diff --git a/src/tasque/TaskGroup.cs b/src/tasque/TaskGroup.cs
index 4228a5b..0e4d29f 100644
--- a/src/tasque/TaskGroup.cs
+++ b/src/tasque/TaskGroup.cs
@@ -1,11 +1,33 @@
// TaskGroup.cs created with MonoDevelop
// User: boyd at 7:50 PMÂ2/11/2008
-
+//
+// TaskGroup.cs
+//
+// Author:
+// Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 Antonius Riha
+//
+// 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.
using System;
-using Gdk;
using Gtk;
-using System.Collections.ObjectModel;
-using System.Collections.Generic;
+using System.Collections;
namespace Tasque
{
@@ -26,7 +48,7 @@ namespace Tasque
#region Constructor
public TaskGroup (string groupName, DateTime rangeStart,
- DateTime rangeEnd, IEnumerable<ITask> tasks)
+ DateTime rangeEnd, IEnumerable tasks)
{
hideWhenEmpty = true;
@@ -86,7 +108,8 @@ namespace Tasque
//
// Group TreeView
//
- treeView = new TaskTreeView (filteredTasks);
+ var adapter = new TreeModelListAdapter<ITask> (filteredTasks);
+ treeView = new TaskTreeView (adapter);
treeView.Show ();
PackStart (treeView, true, true, 0);
@@ -187,7 +210,7 @@ namespace Tasque
#region Public Methods
public void Refilter (ICategory selectedCategory)
{
- filteredTasks.Refilter ();
+ filteredTasks.Refresh ();
treeView.Refilter (selectedCategory);
}
@@ -327,13 +350,13 @@ namespace Tasque
header.Markup = GetHeaderMarkup (DisplayName);
}
- protected virtual TaskGroupModel CreateModel (DateTime rangeStart,
+ protected virtual TaskGroupModel CreateModel (DateTime rangeStart,
DateTime rangeEnd,
- IEnumerable<ITask> tasks)
+ IEnumerable tasks)
{
return new TaskGroupModel (rangeStart, rangeEnd, tasks);
}
-
+
/// <summary>
/// Refilter the hard way by discovering the category to filter on
/// </summary>
diff --git a/src/tasque/TaskGroupModel.cs b/src/tasque/TaskGroupModel.cs
index 4da66c1..5ee4e95 100644
--- a/src/tasque/TaskGroupModel.cs
+++ b/src/tasque/TaskGroupModel.cs
@@ -1,69 +1,92 @@
-
+//
+// TaskGroupModel.cs
+//
+// Author:
+// Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 Antonius Riha
+//
+// 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.
using System;
-using System.Collections.ObjectModel;
-using Gtk;
-using System.Collections.Generic;
+using System.Collections;
+using CollectionTransforms;
namespace Tasque
{
- public class TaskGroupModel : TreeModelFilter
+ public class TaskGroupModel : CollectionView<ITask>
{
public bool ShowCompletedTasks {
get { return showCompletedTasks; }
set {
+ if (showCompletedTasks == value)
+ return;
+
showCompletedTasks = value;
- base.Refilter ();
+ Refresh ();
}
}
-
- public DateTime TimeRangeStart {
- get { return timeRangeStart; }
- }
-
- public DateTime TimeRangeEnd {
- get { return timeRangeEnd; }
- }
- public TaskGroupModel (DateTime rangeStart, DateTime rangeEnd,
- IEnumerable<ITask> tasks)
- : base (new TreeModelAdapter (new TreeViewModelImplementor<ITask> (tasks)), null)
+ public DateTime TimeRangeStart { get; private set; }
+
+ public DateTime TimeRangeEnd { get; private set; }
+
+ public TaskGroupModel (DateTime rangeStart, DateTime rangeEnd, IEnumerable tasks)
+ : base (tasks)
{
- this.timeRangeStart = rangeStart;
- this.timeRangeEnd = rangeEnd;
+ TimeRangeStart = rangeStart;
+ TimeRangeEnd = rangeEnd;
- base.VisibleFunc = FilterTasks;
+ Filter = FilterTasks;
+ int i = 5;
}
-
+
public void SetRange (DateTime rangeStart, DateTime rangeEnd)
{
- this.timeRangeStart = rangeStart;
- this.timeRangeEnd = rangeEnd;
- base.Refilter ();
+ if (rangeStart == TimeRangeStart && rangeEnd == TimeRangeEnd)
+ return;
+
+ TimeRangeStart = rangeStart;
+ TimeRangeEnd = rangeEnd;
+ Refresh ();
}
-
+
/// <summary>
/// Filter out tasks that don't fit within the group's date range
/// </summary>
- protected virtual bool FilterTasks (Gtk.TreeModel model, Gtk.TreeIter iter)
+ protected virtual bool FilterTasks (ITask task)
{
- ITask task = model.GetValue (iter, 0) as ITask;
if (task == null || task.State == TaskState.Deleted)
return false;
// Do something special when task.DueDate == DateTime.MinValue since
// these tasks should always be in the very last category.
if (task.DueDate == DateTime.MinValue) {
- if (timeRangeEnd == DateTime.MaxValue) {
+ if (TimeRangeEnd == DateTime.MaxValue) {
if (!ShowCompletedTask (task))
return false;
return true;
- } else {
+ } else
return false;
- }
}
- if (task.DueDate < timeRangeStart || task.DueDate > timeRangeEnd)
+ if (task.DueDate < TimeRangeStart || task.DueDate > TimeRangeEnd)
return false;
if (!ShowCompletedTask (task))
@@ -72,11 +95,13 @@ namespace Tasque
return true;
}
- protected DateTime timeRangeStart;
- protected DateTime timeRangeEnd;
- protected bool showCompletedTasks = false;
-
- private bool ShowCompletedTask (ITask task)
+ bool IsToday (DateTime date)
+ {
+ DateTime today = DateTime.Now;
+ return today.Year == date.Year && today.DayOfYear == date.DayOfYear;
+ }
+
+ bool ShowCompletedTask (ITask task)
{
if (task.State == TaskState.Completed) {
if (!showCompletedTasks)
@@ -95,14 +120,6 @@ namespace Tasque
return true;
}
- private bool IsToday (DateTime testDate)
- {
- DateTime today = DateTime.Now;
- if (today.Year != testDate.Year
- || today.DayOfYear != testDate.DayOfYear)
- return false;
-
- return true;
- }
+ bool showCompletedTasks;
}
}
diff --git a/src/tasque/TaskGroupModelFactory.cs b/src/tasque/TaskGroupModelFactory.cs
index c0f4cec..e67e857 100644
--- a/src/tasque/TaskGroupModelFactory.cs
+++ b/src/tasque/TaskGroupModelFactory.cs
@@ -1,15 +1,36 @@
-
+//
+// TaskGroupModelFactory.cs
+//
+// Author:
+// Antonius Riha <antoniusriha gmail com>
+//
+// Copyright (c) 2012 Antonius Riha
+//
+// 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.
using System;
-
-using Gtk;
-using System.Collections.ObjectModel;
-using System.Collections.Generic;
+using System.Collections;
namespace Tasque
{
public static class TaskGroupModelFactory
{
- public static TaskGroupModel CreateTodayModel (IEnumerable<ITask> tasks)
+ public static TaskGroupModel CreateTodayModel (IEnumerable tasks)
{
DateTime rangeStart = DateTime.Now;
rangeStart = new DateTime (rangeStart.Year, rangeStart.Month,
@@ -20,7 +41,7 @@ namespace Tasque
return new TaskGroupModel (rangeStart, rangeEnd, tasks);
}
- public static TaskGroupModel CreateOverdueModel (IEnumerable<ITask> tasks)
+ public static TaskGroupModel CreateOverdueModel (IEnumerable tasks)
{
DateTime rangeStart = DateTime.MinValue;
DateTime rangeEnd = DateTime.Now.AddDays (-1);
@@ -30,7 +51,7 @@ namespace Tasque
return new TaskGroupModel (rangeStart, rangeEnd, tasks);
}
- public static TaskGroupModel CreateTomorrowModel (IEnumerable<ITask> tasks)
+ public static TaskGroupModel CreateTomorrowModel (IEnumerable tasks)
{
DateTime rangeStart = DateTime.Now.AddDays (1);
rangeStart = new DateTime (rangeStart.Year, rangeStart.Month,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]