[baobab] Add the possibility to clear the list of recent locations



commit 8dbb95be666a46c5d8ae20bb9b6bd841e337e5eb
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Wed Jun 10 18:05:46 2020 +0200

    Add the possibility to clear the list of recent locations
    
    Closes: https://gitlab.gnome.org/GNOME/baobab/-/issues/6

 src/baobab-location-list.vala | 17 +++++++++++++++--
 src/baobab-main-window.ui     |  4 ++++
 src/baobab-window.vala        |  5 +++++
 3 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 2eb4658..2752fca 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -320,15 +320,28 @@ namespace Baobab {
             Gtk.RecentManager.get_default ().add_full (location.file.get_uri (), data);
 
             // Reload recent locations
+            clear_recent (false);
+            populate_recent ();
+
+            update ();
+        }
+
+        public void clear_recent (bool remove_from_recent_manager = true) {
             unowned List<Location> iter = locations;
             while (iter != null) {
                 unowned List<Location> next = iter.next;
                 if (iter.data.is_recent) {
-                    locations.remove_link (iter);
+                    try {
+                        if (remove_from_recent_manager) {
+                            Gtk.RecentManager.get_default ().remove_item (iter.data.file.get_uri ());
+                        }
+                        locations.remove_link (iter);
+                    } catch (Error e) {
+                        warning ("Attempting to remove an item from recent locations, but failed: %s", 
e.message);
+                    }
                 }
                 iter = next;
             }
-            populate_recent ();
 
             update ();
         }
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 611c4d5..16b9cd3 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -7,6 +7,10 @@
         <attribute name="label" translatable="yes">Scan Folder…</attribute>
         <attribute name="action">win.scan-folder</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">Clear list of recent locations</attribute>
+        <attribute name="action">win.clear-recent</attribute>
+      </item>
     </section>
     <section>
       <item>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 06ecc22..ab306cb 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -86,6 +86,7 @@ namespace Baobab {
             { "show-home-page", on_show_home_page_activate },
             { "scan-folder", on_scan_folder_activate },
             { "reload", on_reload_activate },
+            { "clear-recent", on_clear_recent },
             { "help", on_help_activate },
             { "about", on_about_activate }
         };
@@ -267,6 +268,10 @@ namespace Baobab {
             }
         }
 
+        void on_clear_recent () {
+            location_list.clear_recent ();
+        }
+
         void on_help_activate () {
             try {
                 Gtk.show_uri (get_screen (), "help:baobab", Gtk.get_current_event_time ());


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