Re: Updating the TimeLine Limits



Hi all,

On Wed, 2006-05-24 at 14:38 +0200, Stephane Delcroix wrote:
> A new patch to solve also the case of 'Set Date Range'
> http://bugzilla.gnome.org/attachment.cgi?id=66120&action=view
> 

Cool stuff, i like both the "Clear Date Range" context menu and the fact
that the date range is actually visible now.  However you can find a new
patch in attachment that:

* fixes a bug in the sliding of the end limit (it took a month too much
off)
* only shows the Clear Data Range menu item when a range actually has
been set
* removes some of the code duplication you introduced in the TimeAdaptor
class.

> Before going further with the TimeLine, I just wanted to know some
> things:
> - do you use the TimeLine
Yes I do :-)

> - do you plan to use it now, with the ability to set/clear the date
> range directly ?
> - do you use the Directory view ? is it useful ?
I don't use it very much as i copy my photos the the ~/Photos directory

> - I plan to implement a zoom function(on the timeline) and a week (and
> maybe also a day ?) view. what are your views on that ?
> 
Might be interesting, give it a go I would say...

I will attach my patch to the bugzilla soon.

Regards,
Thomas


Index: src/GroupSelector.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/GroupSelector.cs,v
retrieving revision 1.60
diff -u -r1.60 GroupSelector.cs
--- src/GroupSelector.cs	8 Mar 2006 04:42:52 -0000	1.60
+++ src/GroupSelector.cs	27 May 2006 13:10:24 -0000
@@ -75,6 +75,18 @@
 			}
 		}
 
+		public bool HasRange {
+		 	get {
+				if (min_limit.Position != 0)
+			 		return true;
+
+				if (max_limit.Position != (adaptor.Count() - 1))
+				 	return true;
+
+				return false;
+			}
+		}
+
 		private void HandleAdaptorChanged (GroupAdaptor adaptor)
 		{
 			bool size_changed = box_counts.Length != adaptor.Count ();
@@ -521,6 +533,13 @@
 			GtkUtil.MakeCheckMenuItem (order_menu, Mono.Posix.Catalog.GetString ("_Reverse Order"),
 					      MainWindow.Toplevel.HandleReverseOrder, true, adaptor.OrderAscending, false);
 
+			if (adaptor is TimeAdaptor && HasRange) {
+				GtkUtil.MakeMenuSeparator (order_menu);
+
+				GtkUtil.MakeMenuItem (order_menu, Mono.Posix.Catalog.GetString ("_Clear Date Range"), 
+						MainWindow.Toplevel.HandleClearDateRange);
+			}
+			
 			if (args != null)
 				order_menu.Popup (null, null, null, args.Button, args.Time);
 			else
@@ -1056,6 +1075,23 @@
 			this.Offset = this.Offset;
 
 			UpdateButtons ();
+		}
+
+		public void ResetLimits ()
+		{
+			min_limit.SetPosition(0,false);
+			max_limit.SetPosition(adaptor.Count () - 1, false);
+		}
+
+		public void SetLimitsToDates(DateTime start, DateTime stop)
+		{
+			if (((TimeAdaptor)adaptor).OrderAscending) {
+				min_limit.SetPosition(((TimeAdaptor)adaptor).IndexFromDate(start),false);
+				max_limit.SetPosition(((TimeAdaptor)adaptor).IndexFromDate(stop),false);
+			} else {
+				min_limit.SetPosition(((TimeAdaptor)adaptor).IndexFromDate(stop),false);
+				max_limit.SetPosition(((TimeAdaptor)adaptor).IndexFromDate(start),false);
+			}
 		}
 
 		public GroupSelector () : base () 
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.291
diff -u -r1.291 MainWindow.cs
--- src/MainWindow.cs	24 May 2006 06:59:15 -0000	1.291
+++ src/MainWindow.cs	27 May 2006 13:10:33 -0000
@@ -1495,6 +1495,10 @@
 
 		if (sender != month)
 			month.Active = true;
+
+		//update the selection in the Timeline
+		if (query.Range != null)
+			group_selector.SetLimitsToDates(query.Range.Start, query.Range.End);
 	}
 
 	public void HandleArrangeByDirectory (object sender, EventArgs args)
@@ -1527,6 +1531,13 @@
 		// FIXME this is blah...we need UIManager love here
 		if (item != reverse_order)
 			reverse_order.Active = item.Active;
+		
+		//update the selection in the timeline
+		if ( query.Range != null && group_selector.Adaptor is TimeAdaptor) {
+			group_selector.SetLimitsToDates(query.Range.Start, query.Range.End);
+			
+		}
+
 	}
 
 	// Called when the user clicks the X button	
@@ -2280,9 +2291,15 @@
 	void HandleSetDateRange (object sender, EventArgs args) {
 		DateCommands.Set set_command = new DateCommands.Set (query, main_window);
 		set_command.Execute ();
+		//update the TimeLine
+		if (group_selector.Adaptor is TimeAdaptor) 
+			group_selector.SetLimitsToDates(query.Range.Start, query.Range.End);
 	}
 
-	void HandleClearDateRange (object sender, EventArgs args) {
+	public void HandleClearDateRange (object sender, EventArgs args) {
+		if (group_selector.Adaptor is FSpot.TimeAdaptor) {
+			group_selector.ResetLimits();
+		}
 		query.Range = null;
 	}
 	
Index: src/TimeAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/TimeAdaptor.cs,v
retrieving revision 1.27
diff -u -r1.27 TimeAdaptor.cs
--- src/TimeAdaptor.cs	20 Feb 2006 17:46:48 -0000	1.27
+++ src/TimeAdaptor.cs	27 May 2006 13:10:47 -0000
@@ -65,7 +65,13 @@
 		{
 			Console.WriteLine ("min {0} max {1}", min, max);
 			DateTime start = DateFromIndex (min);
-			DateTime end = DateFromIndex (max).AddMonths (1);
+
+			DateTime end = DateFromIndex(max);
+
+			if (order_ascending)
+				end = end.AddMonths (1);
+			else
+			 	end = end.AddMonths(-1);
 
 			SetLimits (start, end);
 		}
@@ -138,34 +144,42 @@
 		public override int IndexFromPhoto (FSpot.IBrowsableItem photo) 
 		{
 			if (order_ascending)
-			       return IndexFromPhotoAscending (photo);
+			       return IndexFromDateAscending (photo.Time);
+
+			return IndexFromDateDescending (photo.Time);	
+		}
+
+		public int IndexFromDate (DateTime date)
+		{
+			if (order_ascending)
+				return IndexFromDateAscending(date);
 
-			return IndexFromPhotoDescending (photo);	
+			return IndexFromDateDescending(date);
 		}
 
-		private int IndexFromPhotoAscending (FSpot.IBrowsableItem photo)
+		private int IndexFromDateAscending(DateTime date)
 		{
-			int year = photo.Time.Year;
+			int year = date.Year;
 			int max_year = ((YearData)years [years.Count - 1]).Year;
 			int min_year = ((YearData)years [0]).Year;
 
 			if (year < min_year || year > max_year) {
-				Console.WriteLine("TimeAdaptor.IndexFromPhoto year out of range[{1},{2}]: {0}", year, min_year, max_year);
+				Console.WriteLine("TimeAdaptor.IndexFromDate year out of range[{1},2{}]: {0}", year, min_year, max_year);
 				return 0;
 			}
 
-			int index = photo.Time.Month - 1;
+			int index = date.Month - 1;
 
 			for (int i = 0 ; i < years.Count; i++)
 				if (year > ((YearData)years[i]).Year)
 					index += 12;
-			
-			return index;						
+
+			return index;	
 		}
 
-		private int IndexFromPhotoDescending (FSpot.IBrowsableItem photo)
+		private int IndexFromDateDescending(DateTime date)
 		{
-			int year = photo.Time.Year;
+			int year = date.Year;
 			int max_year = ((YearData)years [0]).Year;
 			int min_year = ((YearData)years [years.Count - 1]).Year;
 		
@@ -174,13 +188,11 @@
 				return 0;
 			}
 
-			int index = 12 - photo.Time.Month;
+			int index = 12 - date.Month;
 
 			for (int i = 0; i < years.Count; i++)
 				if (year < ((YearData)years[i]).Year)
 					index += 12;
-
-			//Console.WriteLine("IndexFromPhoto " + photo.Name + " is " + index);
 
 			return index;
 		}


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