[baobab] location-list: Reload recent locations instead of adding new



commit 851b50fbc6c7fbdc81d5513f29a86663bac76956
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Feb 23 17:02:49 2017 +0100

    location-list: Reload recent locations instead of adding new
    
    Each "Scan folder" adds a new location in the list if it is not already
    there. Consequently, the location list may be pretty overfilled. Let's
    reload the recent items after each "Scan folder" instead. As the result,
    max 5 recent locations will be always shown.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695421

 src/baobab-location-list.vala |   27 +++++++++++++++++++--------
 src/baobab-location.vala      |    2 ++
 2 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 56ccc3e..d31eb10 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -187,6 +187,12 @@ namespace Baobab {
                 mount_added (mount);
             }
 
+            populate_recent ();
+
+            update ();
+        }
+
+        void populate_recent () {
             Gtk.RecentManager recent_manager = Gtk.RecentManager.get_default ();
             List<Gtk.RecentInfo> recent_items = recent_manager.get_items ();
 
@@ -213,8 +219,6 @@ namespace Baobab {
             foreach (var info in recent_items) {
                 locations.append (new Location.for_recent_info (info));
             }
-
-            update ();
         }
 
         void update_header (Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
@@ -257,12 +261,6 @@ namespace Baobab {
                 return;
             }
 
-            if (!already_present (location.file)) {
-                locations.append (location);
-            }
-
-            update ();
-
             // Add to recent files
             Gtk.RecentData data = Gtk.RecentData ();
             data.display_name = null;
@@ -275,6 +273,19 @@ namespace Baobab {
             groups[1] = null;
             data.groups = groups;
             Gtk.RecentManager.get_default ().add_full (location.file.get_uri (), data);
+
+            // Reload recent locations
+            unowned List<Location> iter = locations;
+            while (iter != null) {
+                unowned List<Location> next = iter.next;
+                if (iter.data.is_recent) {
+                    locations.remove_link (iter);
+                }
+                iter = next;
+            }
+            populate_recent ();
+
+            update ();
         }
     }
 }
diff --git a/src/baobab-location.vala b/src/baobab-location.vala
index 9eda310..cbed9b8 100644
--- a/src/baobab-location.vala
+++ b/src/baobab-location.vala
@@ -43,6 +43,7 @@ namespace Baobab {
 
         public bool is_main_volume { get; private set; default = false; }
         public bool is_remote { get; private set; default = false; }
+        public bool is_recent { get; private set; default = false; }
 
         public Scanner? scanner { get; private set; }
 
@@ -120,6 +121,7 @@ namespace Baobab {
 
         public Location.for_recent_info (Gtk.RecentInfo recent_info) {
             is_volume = false; // we assume recent locations are just folders
+            is_recent = true;
             file = File.new_for_uri (recent_info.get_uri ());
             name = recent_info.get_display_name ();
             icon = recent_info.get_gicon ();


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