[baobab/wip/remove-button] Add a button to remove a location from the recent list



commit 772ec795fe48a8de0dec2f62916949543b0e3f6a
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Mon Nov 12 13:57:40 2018 +0100

    Add a button to remove a location from the recent list
    
    Closes: https://gitlab.gnome.org/GNOME/baobab/-/issues/6

 po/POTFILES.in                |  1 +
 src/baobab-location-list.vala | 32 +++++++++++++++++++++++++++++---
 src/baobab-location-row.ui    | 23 +++++++++++++++++++++++
 3 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ed9dd44..b78512d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@ src/baobab-application.vala
 src/baobab-cellrenderers.vala
 src/baobab-location-list.ui
 src/baobab-location-list.vala
+src/baobab-location-row.ui
 src/baobab-location.vala
 src/baobab-main-window.ui
 src/baobab-window.vala
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 89cac3c..3209835 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -34,9 +34,13 @@ namespace Baobab {
         private Gtk.Label total_size_label;
         [GtkChild]
         private Gtk.LevelBar usage_bar;
+        [GtkChild]
+        private Gtk.Button remove_button;
 
         public Location? location { get; private set; }
 
+        public signal void remove_recent ();
+
         public LocationRow (Location l) {
             location = l;
 
@@ -56,6 +60,13 @@ namespace Baobab {
             // more important
             path_label.ellipsize = location.is_remote ? Pango.EllipsizeMode.END : Pango.EllipsizeMode.START;
 
+            if (location.is_recent) {
+                remove_button.show ();
+                remove_button.clicked.connect (() => {
+                    remove_recent ();
+                });
+            }
+
             update_fs_usage_info ();
             location.changed.connect (() => { update_fs_usage_info (); });
         }
@@ -259,11 +270,23 @@ namespace Baobab {
             remote_box.visible = false;
 
             foreach (var location in locations) {
+                var location_row = new LocationRow (location);
+                if (location.is_recent) {
+                    location_row.remove_recent.connect (() => {
+                        try {
+                            Gtk.RecentManager.get_default ().remove_item (location.file.get_uri ());
+                            rebuild_recent_list ();
+                        } catch (Error e) {
+                            warning ("Could not remove recent item: %s".printf(e.message));
+                        }
+                    });
+                }
+
                 if (location.is_remote) {
-                    remote_list_box.add (new LocationRow (location));
+                    remote_list_box.add (location_row);
                     remote_box.visible = true;
                 } else {
-                    local_list_box.add (new LocationRow (location));
+                    local_list_box.add (location_row);
                 }
             }
         }
@@ -286,7 +309,10 @@ namespace Baobab {
             data.groups = groups;
             Gtk.RecentManager.get_default ().add_full (location.file.get_uri (), data);
 
-            // Reload recent locations
+            rebuild_recent_list ();
+        }
+
+        void rebuild_recent_list () {
             unowned List<Location> iter = locations;
             while (iter != null) {
                 unowned List<Location> next = iter.next;
diff --git a/src/baobab-location-row.ui b/src/baobab-location-row.ui
index e74cf98..371cf8c 100644
--- a/src/baobab-location-row.ui
+++ b/src/baobab-location-row.ui
@@ -106,6 +106,29 @@
             <property name="height">1</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkButton" id="remove_button">
+            <property name="valign">center</property>
+            <property name="tooltip_text" translatable="yes">Remove from the list of recent 
locations</property>
+            <style>
+              <class name="image-button"/>
+              <class name="flat"/>
+              <class name="circular"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">edit-delete-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">3</property>
+            <property name="top_attach">0</property>
+            <property name="height">2</property>
+          </packing>
+        </child>
       </object>
     </child>
   </template>


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