Re: view sorted chronologically, ascending
- From: Thomas <thomas vanmachelen gmail com>
- To: Michael Knepher <mknepher bluethingy com>, f-spot-list <f-spot-list gnome org>
- Cc:
- Subject: Re: view sorted chronologically, ascending
- Date: Sat, 07 Jan 2006 01:09:15 +0100
Hi all,
Since quite some people requested this on the mailing list, i put
together a patch that allows you to reverse the sort order, both when
viewing ordered by month and viewing ordered by directory.
The sorting can be altered by right-clicking the timeline/directory line
and selecting one of two (ascending/descending) sort orders.
Currently the setting isn't stored by the preferences, but this should
be quite straightforward.
On Tue, 2005-12-27 at 09:15 -0800, Michael Knepher wrote:
> (resending to the list)
> So I'd suggest user-configurable ordering. Would
> http://bugzilla.gnome.org/show_bug.cgi?id=321260
> be the bug to add a comment to?
>
I guess that's the right place, so that's where i added a comment and
attached the patch.
Comments are, as always, welcome.
Regards,
Thomas
Index: src/DirectoryAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/DirectoryAdaptor.cs,v
retrieving revision 1.14
diff -u -w -r1.14 DirectoryAdaptor.cs
--- src/DirectoryAdaptor.cs 24 Oct 2005 22:11:27 -0000 1.14
+++ src/DirectoryAdaptor.cs 6 Jan 2006 23:44:39 -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;
@@ -97,6 +110,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);
Index: src/GroupAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/GroupAdaptor.cs,v
retrieving revision 1.8
diff -u -w -r1.8 GroupAdaptor.cs
--- src/GroupAdaptor.cs 24 Oct 2005 22:11:27 -0000 1.8
+++ src/GroupAdaptor.cs 6 Jan 2006 23:44:39 -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);
Index: src/GroupSelector.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/GroupSelector.cs,v
retrieving revision 1.57
diff -u -w -r1.57 GroupSelector.cs
--- src/GroupSelector.cs 19 Dec 2005 04:44:49 -0000 1.57
+++ src/GroupSelector.cs 6 Jan 2006 23:44:40 -0000
@@ -274,6 +274,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 +487,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.MakeMenuItem (order_menu, Mono.Posix.Catalog.GetString ("Order Ascending"),
+ new EventHandler (HandleSetAscending), true);
+
+ GtkUtil.MakeMenuItem (order_menu, Mono.Posix.Catalog.GetString ("Order Descending"),
+ new EventHandler (HandleSetDescending), true);
+
+ 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.260
diff -u -w -r1.260 MainWindow.cs
--- src/MainWindow.cs 20 Dec 2005 16:28:35 -0000 1.260
+++ src/MainWindow.cs 6 Jan 2006 23:44:43 -0000
@@ -319,6 +319,7 @@
view_notebook.SwitchPage += HandleViewNotebookSwitchPage;
adaptor.GlassSet += HandleAdaptorGlassSet;
+ adaptor.Changed += HandleAdaptorChanged;
this.selection = new MainSelection (this);
this.selection.Changed += HandleSelectionChanged;
@@ -836,6 +837,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
*/
@@ -846,7 +852,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;
@@ -1386,19 +1392,23 @@
void HandleArrangeByTime (object sender, EventArgs args)
{
group_selector.Adaptor.GlassSet -= HandleAdaptorGlassSet;
+ group_selector.Adaptor.Changed -= HandleAdaptorChanged;
FSpot.GroupAdaptor adaptor = new FSpot.TimeAdaptor (query);
group_selector.Adaptor = adaptor;
group_selector.Mode = FSpot.GroupSelector.RangeType.Min;
adaptor.GlassSet += HandleAdaptorGlassSet;
+ adaptor.Changed += HandleAdaptorChanged;
}
void HandleArrangeByDirectory (object sender, EventArgs args)
{
group_selector.Adaptor.GlassSet -= HandleAdaptorGlassSet;
+ group_selector.Adaptor.Changed -= HandleAdaptorChanged;
FSpot.GroupAdaptor adaptor = new FSpot.DirectoryAdaptor (query);
group_selector.Adaptor = adaptor;
group_selector.Mode = FSpot.GroupSelector.RangeType.Min;
adaptor.GlassSet += HandleAdaptorGlassSet;
+ adaptor.Changed += HandleAdaptorChanged;
}
// Called when the user clicks the X button
Index: src/TimeAdaptor.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/TimeAdaptor.cs,v
retrieving revision 1.26
diff -u -w -r1.26 TimeAdaptor.cs
--- src/TimeAdaptor.cs 19 Dec 2005 04:35:17 -0000 1.26
+++ src/TimeAdaptor.cs 6 Jan 2006 23:44:43 -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;
@@ -123,8 +199,12 @@
Photo [] photos = query.Store.Query (null, null);
Array.Sort (query.Photos);
+ Array.Sort (photos);
+
+ if (!order_ascending) {
Array.Reverse (query.Photos);
Array.Reverse (photos);
+ }
if (photos.Length > 0) {
YearData data = new YearData ();
@@ -139,6 +219,9 @@
years.Add (data);
//Console.WriteLine ("Found Year {0}", current);
}
+ if (order_ascending)
+ data.Months [photo.Time.Month - 1] += 1;
+ else
data.Months [12 - photo.Time.Month] += 1;
}
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]