Re: view sorted chronologically, ascending



Yet antother version of the patch, fixing some last things.

Best Regards,
Thomas
Index: src/DirectoryAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/DirectoryAdaptor.cs,v
retrieving revision 1.14
diff -u -r1.14 DirectoryAdaptor.cs
--- src/DirectoryAdaptor.cs	24 Oct 2005 22:11:27 -0000	1.14
+++ src/DirectoryAdaptor.cs	24 Jan 2006 22:11:13 -0000
@@ -6,6 +6,19 @@
 		public PhotoQuery query;
 		System.Collections.DictionaryEntry [] dirs;
 
+		private bool order_ascending = true;
+		public override bool OrderAscending {
+			get {
+				return order_ascending;
+			}
+			set {
+				if (order_ascending != value) {
+					order_ascending = value;
+					Reload();
+				}
+			}
+		}
+
 		// FIXME store the Photo.Id list here not just the count
 		private class Group : IComparer {
 			public int Count = 1;
@@ -37,15 +50,7 @@
 
 			Console.WriteLine ("Selected Path {0}", dirs [group].Key);
 	
-			int item = 0;
-			int i = 0;
-			while (i < query.Count) {
-				if (((Photo)(query [i])).DirectoryPath == (string)dirs [group].Key) {
-					item = i;
-					break;
-				}
-				i++;
-			}
+			int item = LookupItem (group);
 
 			if (GlassSet != null)
 				GlassSet (this, item);
@@ -98,6 +103,11 @@
 			Array.Sort (dirs, new DirectoryAdaptor.Group ());
 			Array.Sort (query.Photos, new Photo.CompareDirectory ());
 			
+			if (!order_ascending) {
+				Array.Reverse (dirs);
+				Array.Reverse (query.Photos);
+			}
+			
 			if (Changed != null)
 				Changed (this);
 		}
@@ -114,6 +124,23 @@
 			}
 			
 			// FIXME not truly implemented
+			return 0;
+		}
+
+		public override FSpot.IBrowsableItem PhotoFromIndex (int item) 
+		{
+			return query.Items [LookupItem (item)];
+		}
+
+		private int LookupItem (int group)
+		{
+			int i = 0;
+			while (i < query.Count) {
+				if (((Photo)(query [i])).DirectoryPath == (string)dirs [group].Key) {
+					return i;
+				}
+				i++;
+			}
 			return 0;
 		}
 
Index: src/GroupAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/GroupAdaptor.cs,v
retrieving revision 1.8
diff -u -r1.8 GroupAdaptor.cs
--- src/GroupAdaptor.cs	24 Oct 2005 22:11:27 -0000	1.8
+++ src/GroupAdaptor.cs	24 Jan 2006 22:11:13 -0000
@@ -6,6 +6,8 @@
 	}
 	
 	public abstract class GroupAdaptor {
+		public abstract bool OrderAscending {get; set;}
+		
 		public abstract int Value (int item) ;
 		public abstract int Count ();
 		public abstract string TickLabel (int item);
@@ -15,6 +17,7 @@
 
 		public abstract void SetGlass (int item);
 		public abstract int IndexFromPhoto (FSpot.IBrowsableItem photo);
+		public abstract FSpot.IBrowsableItem PhotoFromIndex (int item);
 
 		public delegate void GlassSetHandler (GroupAdaptor adaptor, int index);
 		public virtual event GlassSetHandler GlassSet;
Index: src/GroupSelector.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/GroupSelector.cs,v
retrieving revision 1.57
diff -u -r1.57 GroupSelector.cs
--- src/GroupSelector.cs	19 Dec 2005 04:44:49 -0000	1.57
+++ src/GroupSelector.cs	24 Jan 2006 22:11:14 -0000
@@ -69,6 +69,12 @@
 			}
 		}
 
+		public int GlassPosition {
+			get {
+				return glass.Position;
+			}
+		}
+
 		private void HandleAdaptorChanged (GroupAdaptor adaptor)
 		{
 			bool size_changed = box_counts.Length != adaptor.Count ();
@@ -274,6 +280,9 @@
 
 		protected override bool OnButtonPressEvent (Gdk.EventButton args)
 		{
+			if (args.Button == 3)
+				return DrawOrderMenu (args); 
+
 			double x = args.X + action.X;
 			double y = args.Y + action.Y;
 
@@ -484,6 +493,31 @@
 			if (tick.Intersect (area, out area)) {
 				GdkWindow.DrawRectangle (Style.ForegroundGC (State), true, area);
 			}
+		}
+
+		private bool DrawOrderMenu (Gdk.EventButton args)
+		{
+			Gtk.Menu order_menu = new Gtk.Menu();
+
+			GtkUtil.MakeCheckMenuItem (order_menu, Mono.Posix.Catalog.GetString ("Order Ascending"),
+					      new EventHandler (HandleSetAscending), true, adaptor.OrderAscending);
+
+			GtkUtil.MakeCheckMenuItem (order_menu, Mono.Posix.Catalog.GetString ("Order Descending"),
+					      new EventHandler (HandleSetDescending), true, !adaptor.OrderAscending);
+
+			order_menu.Popup (null, null, null, args.Button, args.Time);
+
+			return base.OnButtonPressEvent (args);
+		}
+
+		private void HandleSetAscending (object sender, EventArgs args)
+		{
+			adaptor.OrderAscending = true;
+		}
+
+		private void HandleSetDescending (object sender, EventArgs args)
+		{
+			adaptor.OrderAscending = false;
 		}
 
 		public abstract class Manipulator {
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.265
diff -u -r1.265 MainWindow.cs
--- src/MainWindow.cs	17 Jan 2006 03:13:06 -0000	1.265
+++ src/MainWindow.cs	24 Jan 2006 22:11:18 -0000
@@ -76,6 +76,9 @@
 	[Glade.Widget] MenuItem zoom_in;
 	[Glade.Widget] MenuItem zoom_out;
 
+	[Glade.Widget] RadioMenuItem month;
+	[Glade.Widget] RadioMenuItem directory;
+
 	// Find
 	[Glade.Widget] MenuItem find_tag;
 	[Glade.Widget] CheckMenuItem find_untagged;
@@ -252,9 +255,8 @@
 #endif
 
 		group_selector = new FSpot.GroupSelector ();
-		FSpot.GroupAdaptor adaptor = new FSpot.TimeAdaptor (query);
+		group_selector.Adaptor = new FSpot.TimeAdaptor (query);
 
-		group_selector.Adaptor  = adaptor;
 		group_selector.ShowAll ();
 		
 		if (zoom_scale != null) {
@@ -332,7 +334,10 @@
 		photo_view.DragDataReceived += HandlePhotoViewDragDataReceived;
 
 		view_notebook.SwitchPage += HandleViewNotebookSwitchPage;
-		adaptor.GlassSet += HandleAdaptorGlassSet;
+		group_selector.Adaptor.GlassSet += HandleAdaptorGlassSet;
+		group_selector.Adaptor.Changed += HandleAdaptorChanged;
+		LoadPreference (Preferences.GROUP_ADAPTOR);
+		LoadPreference (Preferences.GROUP_ADAPTOR_ORDER_ASC);
 
 		this.selection = new MainSelection (this);
 		this.selection.Changed += HandleSelectionChanged;
@@ -862,6 +867,11 @@
 		JumpTo (index);
 	}
 
+	void HandleAdaptorChanged (FSpot.GroupAdaptor sender)
+	{
+		UpdateGlass ();
+	}
+
 	/*
 	 * Keep the glass temporal slider in sync with the user's scrolling in the icon_view
 	 */
@@ -872,7 +882,7 @@
 			return;
 
 		int cell_num = icon_view.TopLeftVisibleCell();
-		if (cell_num == -1 || cell_num == lastTopLeftCell)
+		if (cell_num == -1 /*|| cell_num == lastTopLeftCell*/)
 			return;
 
 		lastTopLeftCell = cell_num;
@@ -898,7 +908,7 @@
 
 	void HandleIconViewReady (object sender, EventArgs args)
 	{
-		LoadPreference (Preferences.ICON_VIEW_POSITION);
+		LoadPreference (Preferences.GLASS_POSITION);
 
 		// We only want to set the position the first time
 		// the icon_view is ready (eg on startup)
@@ -1412,19 +1422,23 @@
 	void HandleArrangeByTime (object sender, EventArgs args)
 	{
 		group_selector.Adaptor.GlassSet -= HandleAdaptorGlassSet;
-		FSpot.GroupAdaptor adaptor = new FSpot.TimeAdaptor (query);
-		group_selector.Adaptor = adaptor;
+		group_selector.Adaptor.Changed -= HandleAdaptorChanged;
+		group_selector.Adaptor = new FSpot.TimeAdaptor (query);
+
 		group_selector.Mode = FSpot.GroupSelector.RangeType.Min;
-		adaptor.GlassSet += HandleAdaptorGlassSet;
+		group_selector.Adaptor.GlassSet += HandleAdaptorGlassSet;
+		group_selector.Adaptor.Changed += HandleAdaptorChanged;
 	}
 
 	void HandleArrangeByDirectory (object sender, EventArgs args)
 	{
 		group_selector.Adaptor.GlassSet -= HandleAdaptorGlassSet;
-		FSpot.GroupAdaptor adaptor = new FSpot.DirectoryAdaptor (query);		
-		group_selector.Adaptor = adaptor;
+		group_selector.Adaptor.Changed -= HandleAdaptorChanged;
+		group_selector.Adaptor = new FSpot.DirectoryAdaptor (query); 	
+
 		group_selector.Mode = FSpot.GroupSelector.RangeType.Min;
-		adaptor.GlassSet += HandleAdaptorGlassSet;
+		group_selector.Adaptor.GlassSet += HandleAdaptorGlassSet;
+		group_selector.Adaptor.Changed += HandleAdaptorChanged;
 	}
 
 	// Called when the user clicks the X button	
@@ -1461,11 +1475,13 @@
 		Preferences.Set (Preferences.SHOW_TAGS,			icon_view.DisplayTags);
 		Preferences.Set (Preferences.SHOW_DATES,		icon_view.DisplayDates);
 
+		Preferences.Set (Preferences.GROUP_ADAPTOR,		(group_selector.Adaptor is DirectoryAdaptor) ? 1 : 0);
+		Preferences.Set (Preferences.GROUP_ADAPTOR_ORDER_ASC,   group_selector.Adaptor.OrderAscending);
+		Preferences.Set (Preferences.GLASS_POSITION,		group_selector.GlassPosition);
+		
 		Preferences.Set (Preferences.SIDEBAR_POSITION,		main_hpaned.Position);
 		Preferences.Set (Preferences.ZOOM,			icon_view.Zoom);
 	
-		Preferences.Set (Preferences.ICON_VIEW_POSITION, icon_view.TopLeftVisibleCell ());
-		
 		tag_selection_widget.SaveExpandDefaults ();
 
 		this.Window.Destroy ();
@@ -2229,6 +2245,20 @@
 				//display_dates_menu_item.Toggle ();
 			break;
 		
+		case Preferences.GROUP_ADAPTOR:
+			if ((int) val == 1) 
+				directory.Active = true;
+			break;
+
+		case Preferences.GROUP_ADAPTOR_ORDER_ASC:
+			group_selector.Adaptor.OrderAscending = (bool) val;
+			break;
+
+		case Preferences.GLASS_POSITION:
+			IBrowsableItem photo = group_selector.Adaptor.PhotoFromIndex ((int) val);
+			JumpTo (query.IndexOf (photo));
+			break;
+			
 		case Preferences.SIDEBAR_POSITION:
 			if (main_hpaned.Position != (int) val)
 				main_hpaned.Position = (int) val;
@@ -2238,13 +2268,6 @@
 			icon_view.Zoom = (double) val;
 			break;
 		
-		case Preferences.ICON_VIEW_POSITION:
-			if (icon_view.TopLeftVisibleCell () != (int) val) {
-				icon_view.FocusCell = (int) val;
-				photo_view.Item.Index = (int) val;
-				icon_view.ScrollTo ((int) val, false);
-			}
-			break;
 		case Preferences.METADATA_EMBED_IN_IMAGE:
 			write_metadata = (bool) val;
 			break;
Index: src/Preferences.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/Preferences.cs,v
retrieving revision 1.5
diff -u -r1.5 Preferences.cs
--- src/Preferences.cs	19 Jan 2006 01:06:27 -0000	1.5
+++ src/Preferences.cs	24 Jan 2006 22:11:18 -0000
@@ -25,9 +25,12 @@
 		public const string SHOW_DATES = "/apps/f-spot/ui/show_dates";
 		public const string EXPANDED_TAGS = "/apps/f-spot/ui/expanded_tags";
 		
+		public const string GLASS_POSITION = "/apps/f-spot/ui/glass_position";
+		public const string GROUP_ADAPTOR = "/apps/f-spot/ui/group_adaptor";
+		public const string GROUP_ADAPTOR_ORDER_ASC = "/apps/f-spot/ui/group_adaptor_sort_asc";
+		
 		public const string SIDEBAR_POSITION = "/apps/f-spot/ui/sidebar_size";
 		public const string ZOOM = "/apps/f-spot/ui/zoom";
-		public const string ICON_VIEW_POSITION = "/apps/f-spot/ui/icon_view_position";
 
 		public const string EXPORT_FLICKR_SCALE = "/apps/f-spot/export/flickr/scale";
 		public const string EXPORT_FLICKR_SIZE = "/apps/f-spot/export/flickr/size";
@@ -73,6 +76,11 @@
 			case MAIN_WINDOW_MAXIMIZED:
 				return false;
 
+			case GROUP_ADAPTOR:
+			case GLASS_POSITION:
+			case GROUP_ADAPTOR_ORDER_ASC:
+				return null;
+
 			case SHOW_TOOLBAR:
 			case SHOW_SIDEBAR:
 			case SHOW_TIMELINE:
@@ -82,7 +90,6 @@
 		
 			case SIDEBAR_POSITION:
 			case ZOOM:
-			case ICON_VIEW_POSITION:
 				return null;
 			}
 
Index: src/TimeAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/TimeAdaptor.cs,v
retrieving revision 1.26
diff -u -r1.26 TimeAdaptor.cs
--- src/TimeAdaptor.cs	19 Dec 2005 04:35:17 -0000	1.26
+++ src/TimeAdaptor.cs	24 Jan 2006 22:11:18 -0000
@@ -4,6 +4,19 @@
 namespace FSpot {
 	public class TimeAdaptor : GroupAdaptor, FSpot.ILimitable {
 		public PhotoQuery query;
+		private bool order_ascending = false;
+		public override bool OrderAscending {
+			get {
+				return order_ascending;
+			}
+			set {
+				if (value != order_ascending) {
+					order_ascending = value;
+					Reload();
+				}
+			}
+		
+		}
 
 		ArrayList years = new ArrayList ();
 		struct YearData {
@@ -22,7 +35,26 @@
 
 		public int LookupItem (System.DateTime date)
 		{
+			if (order_ascending) 
+				return LookUpItemAscending (date);
+			
+			return LookUpItemDescending (date);
+		}
+
+		private int LookUpItemAscending (System.DateTime date)
+		{
+			int i = 0;
+
+			while (i < query.Count && query [i].Time < date)
+				i++;
+
+			return i;
+		}
+
+		private int LookUpItemDescending (System.DateTime date)
+		{
 			int i = 0;
+
 			while (i < query.Count && query [i].Time > date)
 				i++;
 
@@ -63,7 +95,7 @@
 		{
 			DateTime start = DateFromIndex (item);
 			
-			if (start.Month == 12)
+			if ((start.Month == 12 && !order_ascending) || (start.Month == 1 && order_ascending))
 				return start.Year.ToString ();
 			else 
 				return null;
@@ -81,6 +113,22 @@
 			item = Math.Max (item, 0);
 			item = Math.Min (years.Count * 12 - 1, item);
 			
+			if (order_ascending)
+				return DateFromIndexAscending (item);
+
+			return DateFromIndexDescending (item);
+		}
+
+		private DateTime DateFromIndexAscending (int item)
+		{
+			int year = (int)((YearData)years [item / 12]).Year;
+			int month = 1 + (item % 12);
+
+			return new DateTime(year, month, 1);
+		}
+
+		private DateTime DateFromIndexDescending (int item)
+		{
 			int year =  (int)((YearData)years [item / 12]).Year;
 			int month = 12 - (item % 12);
 			
@@ -89,6 +137,34 @@
 		
 		public override int IndexFromPhoto (FSpot.IBrowsableItem photo) 
 		{
+			if (order_ascending)
+			       return IndexFromPhotoAscending (photo);
+
+			return IndexFromPhotoDescending (photo);	
+		}
+
+		private int IndexFromPhotoAscending (FSpot.IBrowsableItem photo)
+		{
+			int year = photo.Time.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);
+				return 0;
+			}
+
+			int index = photo.Time.Month - 1;
+
+			for (int i = 0 ; i < years.Count; i++)
+				if (year > ((YearData)years[i]).Year)
+					index += 12;
+			
+			return index;						
+		}
+
+		private int IndexFromPhotoDescending (FSpot.IBrowsableItem photo)
+		{
 			int year = photo.Time.Year;
 			int max_year = ((YearData)years [0]).Year;
 			int min_year = ((YearData)years [years.Count - 1]).Year;
@@ -109,6 +185,13 @@
 			return index;
 		}
 
+		public override FSpot.IBrowsableItem PhotoFromIndex (int item)
+	       	{
+			DateTime start = DateFromIndex (item);
+			return query.Items [LookupItem (start)];
+		
+		}
+
 		private void HandleChanged (IBrowsableCollection sender)
 		{
 			Console.WriteLine ("Reloading");
@@ -123,8 +206,12 @@
 
 			Photo [] photos = query.Store.Query (null, null);
 			Array.Sort (query.Photos);
-			Array.Reverse (query.Photos);
-			Array.Reverse (photos);
+			Array.Sort (photos);
+
+			if (!order_ascending) {				
+				Array.Reverse (query.Photos);
+				Array.Reverse (photos);
+			}
 
 			if (photos.Length > 0) {
 				YearData data = new YearData ();
@@ -139,7 +226,10 @@
 						years.Add (data);
 						//Console.WriteLine ("Found Year {0}", current);
 					}
-					data.Months [12 - photo.Time.Month] += 1;
+					if (order_ascending)
+						data.Months [photo.Time.Month - 1] += 1;
+					else
+						data.Months [12 - photo.Time.Month] += 1;
 				}
 			} else {
 				YearData data = new YearData ();
Index: src/Util.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/Util.cs,v
retrieving revision 1.20
diff -u -r1.20 Util.cs
--- src/Util.cs	4 Dec 2005 19:03:53 -0000	1.20
+++ src/Util.cs	24 Jan 2006 22:11:19 -0000
@@ -217,6 +217,18 @@
 		i.Show ();
 	}
 
+	public static void MakeCheckMenuItem (Gtk.Menu menu, string label, EventHandler e, bool enabled, bool active)
+	{
+		Gtk.CheckMenuItem i = new Gtk.CheckMenuItem (label);
+		i.Activated += e;
+		i.Sensitive = enabled;
+		i.DrawAsRadio = true;
+		i.Active = active;
+
+		menu.Append(i);
+		i.Show ();
+	}
+
 	public static void MakeMenuSeparator (Gtk.Menu menu)
 	{
 		Gtk.SeparatorMenuItem i = new Gtk.SeparatorMenuItem ();
Index: src/f-spot.glade
===================================================================
RCS file: /cvs/gnome/f-spot/src/f-spot.glade,v
retrieving revision 1.143
diff -u -r1.143 f-spot.glade
--- src/f-spot.glade	20 Jan 2006 07:29:59 -0000	1.143
+++ src/f-spot.glade	24 Jan 2006 22:11:40 -0000
@@ -7438,7 +7438,7 @@
 			      <property name="visible">True</property>
 			      <property name="label" translatable="yes">_Month</property>
 			      <property name="use_underline">True</property>
-			      <property name="active">False</property>
+			      <property name="active">True</property>
 			      <signal name="activate" handler="HandleArrangeByTime" last_modification_time="Fri, 20 Aug 2004 22:26:32 GMT"/>
 			    </widget>
 			  </child>
@@ -7448,7 +7448,7 @@
 			      <property name="visible">True</property>
 			      <property name="label" translatable="yes">_Directory</property>
 			      <property name="use_underline">True</property>
-			      <property name="active">True</property>
+			      <property name="active">False</property>
 			      <property name="group">month</property>
 			      <signal name="activate" handler="HandleArrangeByDirectory" last_modification_time="Fri, 20 Aug 2004 22:26:32 GMT"/>
 			    </widget>


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