[gnome-control-center] background: add remove button overlay to recent section



commit 2e1dc3da00d86779f4a3d11244d2bb1cc8e75304
Author: Julian Sparber <julian sparber net>
Date:   Fri Feb 14 15:53:08 2020 +0100

    background: add remove button overlay to recent section

 panels/background/cc-background-chooser.c | 60 ++++++++++++++++++++++---------
 panels/background/preview.css             |  8 +++++
 2 files changed, 51 insertions(+), 17 deletions(-)
---
diff --git a/panels/background/cc-background-chooser.c b/panels/background/cc-background-chooser.c
index 0ddc0fcb1..1c171cf6b 100644
--- a/panels/background/cc-background-chooser.c
+++ b/panels/background/cc-background-chooser.c
@@ -68,8 +68,21 @@ emit_background_chosen (CcBackgroundChooser *self)
   item = g_object_get_data (list->data, "item");
 
   g_signal_emit (self, signals[BACKGROUND_CHOSEN], 0, item);
+}
+
+static void
+on_delete_background_clicked_cb (GtkButton *button,
+                                 BgRecentSource  *source)
+{
+  GtkWidget *parent;
+  CcBackgroundItem *item;
+
+  parent = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (button)));
+  g_assert (GTK_IS_FLOW_BOX_CHILD (parent));
 
-  gtk_flow_box_unselect_all (flowbox);
+  item = g_object_get_data (G_OBJECT (parent), "item");
+
+  bg_recent_source_remove_item (source, item);
 }
 
 static GtkWidget*
@@ -82,6 +95,8 @@ create_widget_func (gpointer model_item,
   GtkWidget *child;
   GtkWidget *image;
   GtkWidget *icon;
+  GtkWidget *button_image;
+  GtkWidget *button = NULL;
   BgSource *source;
 
   source = BG_SOURCE (user_data);
@@ -104,9 +119,32 @@ create_widget_func (gpointer model_item,
                        NULL);
   gtk_style_context_add_class (gtk_widget_get_style_context (icon), "slideshow-emblem");
 
+
+  if (BG_IS_RECENT_SOURCE (source))
+    {
+      button_image = gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_BUTTON);
+      button =  g_object_new (GTK_TYPE_BUTTON,
+                              "image", button_image,
+                              "halign", GTK_ALIGN_END,
+                              "valign", GTK_ALIGN_START,
+                              "margin", 6,
+                              "visible", TRUE,
+                              NULL);
+
+      gtk_style_context_add_class (gtk_widget_get_style_context (button), "osd");
+      gtk_style_context_add_class (gtk_widget_get_style_context (button), "remove-button");
+
+      g_signal_connect (button,
+                        "clicked",
+                        G_CALLBACK (on_delete_background_clicked_cb),
+                        source);
+    }
+
   overlay = gtk_overlay_new ();
   gtk_container_add (GTK_CONTAINER (overlay), image);
   gtk_overlay_add_overlay (GTK_OVERLAY (overlay), icon);
+  if (button)
+    gtk_overlay_add_overlay (GTK_OVERLAY (overlay), button);
   gtk_widget_show (overlay);
 
   child = g_object_new (GTK_TYPE_FLOW_BOX_CHILD,
@@ -162,27 +200,16 @@ setup_flowbox (CcBackgroundChooser *self)
                            G_CONNECT_SWAPPED);
 }
 
-static void
-on_delete_background_clicked_cb (GtkButton           *button,
-                                 CcBackgroundChooser *self)
-{
-  g_autoptr(GList) list = NULL;
-  CcBackgroundItem *item;
-
-  list = gtk_flow_box_get_selected_children (self->recent_flowbox);
-  g_assert (g_list_length (list) == 1);
-
-  item = g_object_get_data (list->data, "item");
-
-  bg_recent_source_remove_item (self->recent_source, item);
-}
-
 static void
 on_item_activated_cb (GtkFlowBox          *flowbox,
                       GtkFlowBoxChild     *child,
                       CcBackgroundChooser *self)
 {
   self->recent_selected = flowbox == self->recent_flowbox;
+  if (self->recent_selected)
+    gtk_flow_box_unselect_all (self->flowbox);
+  else
+    gtk_flow_box_unselect_all (self->recent_flowbox);
   emit_background_chosen (self);
 }
 
@@ -285,7 +312,6 @@ cc_background_chooser_class_init (CcBackgroundChooserClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundChooser, recent_box);
   gtk_widget_class_bind_template_child (widget_class, CcBackgroundChooser, recent_flowbox);
 
-  gtk_widget_class_bind_template_callback (widget_class, on_delete_background_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_item_activated_cb);
 }
 
diff --git a/panels/background/preview.css b/panels/background/preview.css
index e0ee7d01a..c7416597f 100644
--- a/panels/background/preview.css
+++ b/panels/background/preview.css
@@ -30,3 +30,11 @@ image.slideshow-icon {
   color: white;
   -gtk-icon-shadow: 0 1px 2px rgba(0, 0, 0, 0.33);
 }
+
+button.remove-button {
+  border-radius: 9999px;
+  -gtk-outline-radius: 9999px;
+  padding: 1px 0px; /* circles instead of ellipses */
+  background-origin: padding-box, border-box;
+  background-clip: padding-box, border-box;
+}


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