[tasque] Eliminate ShowCompletedTasks property on TaskGroupModel



commit 9d9b4b3e48ef45a2aa6c3848b09356789fa0c1a1
Author: Antonius Riha <antoniusriha gmail com>
Date:   Thu Jan 10 15:07:42 2013 +0100

    Eliminate ShowCompletedTasks property on TaskGroupModel

 src/Gtk.Tasque/CompletedTaskGroup.cs |   39 +++++++++++++++++++--------------
 src/Gtk.Tasque/TaskGroup.cs          |   24 +-------------------
 src/libtasque/TaskGroupModel.cs      |    9 -------
 3 files changed, 24 insertions(+), 48 deletions(-)
---
diff --git a/src/Gtk.Tasque/CompletedTaskGroup.cs b/src/Gtk.Tasque/CompletedTaskGroup.cs
index ed968f5..f44e31b 100644
--- a/src/Gtk.Tasque/CompletedTaskGroup.cs
+++ b/src/Gtk.Tasque/CompletedTaskGroup.cs
@@ -34,13 +34,29 @@ namespace Tasque
 		                           DateTime rangeEnd, ICollection<ITask> tasks, INativeApplication application)
 			: base (groupName, rangeStart, rangeEnd, new CompletedTasksSortModel(tasks), application)
 		{
-			// 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
-			// range.
-			this.HideWhenEmpty = false;
+			var preferences = application.Preferences;
+			// Only hide this group, when ShowCompletedTasks is unset in prefs.
+			// If it's set, 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 range.
+			HideWhenEmpty = !preferences.GetBool (PreferencesKeys.ShowCompletedTasksKey);
 			
-			selectedCategory = GetSelectedCategory ();
-			application.Preferences.SettingChanged += OnSelectedCategorySettingChanged;
+			// track changes in prefs for ShowCompletedTasks setting
+			preferences.SettingChanged += (prefs, key) => {
+				switch (key) {
+				case PreferencesKeys.ShowCompletedTasksKey:
+					HideWhenEmpty = !prefs.GetBool (PreferencesKeys.ShowCompletedTasksKey);
+					
+					// refresh ui
+					var cat = GetSelectedCategory ();
+					if (cat != null)
+						Refilter (cat);
+					break;
+				case PreferencesKeys.SelectedCategoryKey:
+					selectedCategory = GetSelectedCategory ();
+					Refilter (selectedCategory);
+					break;
+				}
+			};
 			
 			CreateRangeSlider ();
 			UpdateDateRanges ();
@@ -87,17 +103,6 @@ namespace Tasque
 			return new TreeModelListAdapter<ITask> (Model);
 		}
 		
-		protected void OnSelectedCategorySettingChanged (
-								IPreferences preferences,
-								string settingKey)
-		{
-			if (settingKey.CompareTo (PreferencesKeys.SelectedCategoryKey) != 0)
-				return;
-			
-			selectedCategory = GetSelectedCategory ();
-			Refilter (selectedCategory);
-		}
-		
 		protected ICategory GetSelectedCategory ()
 		{
 			ICategory foundCategory = null;
diff --git a/src/Gtk.Tasque/TaskGroup.cs b/src/Gtk.Tasque/TaskGroup.cs
index 3685d66..378bb8a 100644
--- a/src/Gtk.Tasque/TaskGroup.cs
+++ b/src/Gtk.Tasque/TaskGroup.cs
@@ -43,8 +43,6 @@ namespace Tasque
 
 			treeModel = CreateModel (rangeStart, rangeEnd, tasks);
 			
-			Application.Preferences.SettingChanged += OnSettingChanged;
-			
 			// TODO: Add something to watch events so that the group will
 			// automatically refilter and display/hide itself accordingly.
 			
@@ -330,7 +328,7 @@ namespace Tasque
 		{
 			base.OnRealized ();
 			
-			if (!Model.Any () && (!Model.ShowCompletedTasks || hideWhenEmpty))
+			if (!Model.Any () && hideWhenEmpty)
 				Hide ();
 			else
 				Show ();
@@ -415,7 +413,7 @@ namespace Tasque
 		{
 			//Logger.Debug ("TaskGroup (\"{0}\").OnNumberOfTasksChanged ()", DisplayName);
 			// Check to see whether this group should be hidden or shown.
-			if (!Model.Any () && (!Model.ShowCompletedTasks || hideWhenEmpty))
+			if (!Model.Any () && hideWhenEmpty)
 				Hide ();
 			else
 				Show ();
@@ -435,24 +433,6 @@ namespace Tasque
 			if (ButtonPressed != null)
 				ButtonPressed (sender, args);
 		}
-		
-		protected void OnSettingChanged (IPreferences preferences,
-										 string settingKey)
-		{
-			if (settingKey.CompareTo (PreferencesKeys.ShowCompletedTasksKey) != 0)
-				return;
-			
-			bool newValue =
-				preferences.GetBool (PreferencesKeys.ShowCompletedTasksKey);
-			if (Model.ShowCompletedTasks == newValue)
-				return; // don't do anything if nothing has changed
-			
-			Model.ShowCompletedTasks = newValue;
-			
-			ICategory cat = GetSelectedCategory ();
-			if (cat != null)
-				Refilter (cat);
-		}
 
 		#endregion // Event Handlers
 	}
diff --git a/src/libtasque/TaskGroupModel.cs b/src/libtasque/TaskGroupModel.cs
index 770ce7e..196d565 100644
--- a/src/libtasque/TaskGroupModel.cs
+++ b/src/libtasque/TaskGroupModel.cs
@@ -14,15 +14,6 @@ namespace Tasque
 	public class TaskGroupModel
 		: IEnumerable<ITask>, INotifyCollectionChanged, INotifyPropertyChanged, IDisposable
 	{
-		public bool ShowCompletedTasks
-		{
-			get { return showCompletedTasks; }
-			set {
-				showCompletedTasks = value;
-				OnPropertyChanged ("ShowCompletedTasks");
-			}
-		}
-
 		public DateTime TimeRangeStart
 		{
 			get { return timeRangeStart; }



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