[baobab] Sort recent info by MRU



commit 6b1d976a47054b7a15c725355b7c21b51dbe3bc2
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Mon Oct 1 22:52:15 2012 +0200

    Sort recent info by MRU
    
    Otherwise they show up in creation order
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685252

 src/baobab-location-list.vala |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index a033a64..469e080 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -142,17 +142,24 @@ namespace Baobab {
             Gtk.RecentManager recent_manager = Gtk.RecentManager.get_default ();
             List<Gtk.RecentInfo> recent_items = recent_manager.get_items ();
 
-            int n_recents = 0;
-            foreach (var info in recent_items) {
-                if (n_recents >= MAX_RECENT_LOCATIONS) {
-                    break;
-                }
-                if (info.has_group ("baobab") && info.exists ()) {
-                    if (!already_present (File.new_for_uri (info.get_uri ()))) {
-                        locations.append (new Location.for_recent_info (info));
-                        n_recents++;
-                    }
+            unowned List<Gtk.RecentInfo> iter = recent_items;
+            while (iter != null) {
+                unowned List<Gtk.RecentInfo> next = iter.next;
+                if (!iter.data.has_group ("baobab") || !iter.data.exists () || already_present (File.new_for_uri (iter.data.get_uri ()))) {
+                    recent_items.remove_link (iter);
                 }
+                iter = next;
+            }
+
+            recent_items.sort ((a, b) => {
+                return (int)(b.get_modified () - a.get_modified ());
+            });
+
+            recent_items.nth (MAX_RECENT_LOCATIONS - 1).next = null;
+            recent_items.reverse ();
+
+            foreach (var info in recent_items) {
+                locations.append (new Location.for_recent_info (info));
             }
 
             update ();



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