[gtk/popover-menu-custom-child] Add remove_child too



commit ba4d181ba140b9eed2120f575c0f2fb08df49485
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Oct 21 12:41:53 2020 -0400

    Add remove_child too
    
    If only for completeness.

 docs/reference/gtk/gtk4-sections.txt |  2 ++
 gtk/gtkmenusectionbox.c              | 27 +++++++++++++++++++++++++++
 gtk/gtkmenusectionboxprivate.h       |  3 +++
 gtk/gtkpopovermenu.c                 | 21 +++++++++++++++++++++
 gtk/gtkpopovermenu.h                 |  4 ++++
 gtk/gtkpopovermenubar.c              | 32 ++++++++++++++++++++++++++++++++
 gtk/gtkpopovermenubar.h              |  3 +++
 7 files changed, 92 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index d68f04254a..b6f7cf2d25 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -6178,6 +6178,7 @@ gtk_popover_menu_new_from_model_full
 gtk_popover_menu_set_menu_model
 gtk_popover_menu_get_menu_model
 gtk_popover_menu_add_child
+gtk_popover_menu_remove_child
 
 <SUBSECTION Standard>
 GTK_TYPE_POPOVER_MENU
@@ -6197,6 +6198,7 @@ gtk_popover_menu_bar_new_from_model
 gtk_popover_menu_bar_set_menu_model
 gtk_popover_menu_bar_get_menu_model
 gtk_popover_menu_bar_add_child
+gtk_popover_menu_bar_remove_child
 
 <SUBSECTION Standard>
 GTK_TYPE_POPOVER_MENU_BAR
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index a2ae4bdd03..8924417b99 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -708,3 +708,30 @@ gtk_menu_section_box_add_custom (GtkPopoverMenu *popover,
   gtk_widget_insert_before (child, slot, NULL);
   return TRUE;
 }
+
+gboolean
+gtk_menu_section_box_remove_custom (GtkPopoverMenu *popover,
+                                    GtkWidget      *child)
+{
+  GtkWidget *stack;
+  GtkMenuSectionBox *box;
+  GtkWidget *parent;
+  const char *id;
+  GtkWidget *slot;
+
+  stack = gtk_popover_get_child (GTK_POPOVER (popover));
+  box = GTK_MENU_SECTION_BOX (gtk_stack_get_child_by_name (GTK_STACK (stack), "main"));
+  parent = gtk_widget_get_parent (child);
+
+  id = (const char *) g_object_get_data (G_OBJECT (parent), "slot-id");
+  g_return_val_if_fail (id != NULL, FALSE);
+
+  slot = (GtkWidget *)g_hash_table_lookup (box->custom_slots, id);
+
+  if (slot == NULL)
+    return FALSE;
+
+  gtk_widget_unparent (child);
+
+  return TRUE;
+}
diff --git a/gtk/gtkmenusectionboxprivate.h b/gtk/gtkmenusectionboxprivate.h
index 97743405e1..232d62ee0c 100644
--- a/gtk/gtkmenusectionboxprivate.h
+++ b/gtk/gtkmenusectionboxprivate.h
@@ -49,6 +49,9 @@ gboolean                gtk_menu_section_box_add_custom                 (GtkPopo
                                                                          GtkWidget      *child,
                                                                          const char     *id);
 
+gboolean                gtk_menu_section_box_remove_custom              (GtkPopoverMenu *popover,
+                                                                         GtkWidget      *child);
+
 G_END_DECLS
 
 #endif /* __GTK_MENU_SECTION_BOX_PRIVATE_H__ */
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index d048168e1b..cd54fe600d 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -742,3 +742,24 @@ gtk_popover_menu_add_child (GtkPopoverMenu *popover,
 
   return gtk_menu_section_box_add_custom (popover, child, id);
 }
+
+/**
+ * gtk_popover_menu_remove_child:
+ * @popover: a #GtkPopoverMenu
+ * @child: the #GtkWidget to remove
+ *
+ * Removes a widget that has previously been added with
+ * gtk_popover_menu_add_child().
+ *
+ * Returns: %TRUE if the widget was removed
+ */
+gboolean
+gtk_popover_menu_remove_child (GtkPopoverMenu *popover,
+                               GtkWidget      *child)
+{
+
+  g_return_val_if_fail (GTK_IS_POPOVER_MENU (popover), FALSE);
+  g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
+
+  return gtk_menu_section_box_remove_custom (popover, child);
+}
diff --git a/gtk/gtkpopovermenu.h b/gtk/gtkpopovermenu.h
index f4beddbfc6..2973102be1 100644
--- a/gtk/gtkpopovermenu.h
+++ b/gtk/gtkpopovermenu.h
@@ -66,6 +66,10 @@ gboolean    gtk_popover_menu_add_child (GtkPopoverMenu *popover,
                                         GtkWidget      *child,
                                         const char     *id);
 
+GDK_AVAILABLE_IN_ALL
+gboolean    gtk_popover_menu_remove_child (GtkPopoverMenu *popover,
+                                           GtkWidget      *child);
+
 G_END_DECLS
 
 #endif /* __GTK_POPOVER_MENU_H__ */
diff --git a/gtk/gtkpopovermenubar.c b/gtk/gtkpopovermenubar.c
index 6b9895dd94..cb00bba68a 100644
--- a/gtk/gtkpopovermenubar.c
+++ b/gtk/gtkpopovermenubar.c
@@ -732,3 +732,35 @@ gtk_popover_menu_bar_add_child (GtkPopoverMenuBar *bar,
   return FALSE;
 }
 
+/**
+ * gtk_popover_menu_bar_remove_child:
+ * @bar: a #GtkPopoverMenuBar
+ * @child: the #GtkWidget to remove
+ *
+ * Removes a widget that has previously been added with
+ * gtk_popover_menu_bar_add_child().
+ *
+ * Returns: %TRUE if the widget was removed
+ */
+gboolean
+gtk_popover_menu_bar_remove_child (GtkPopoverMenuBar *bar,
+                                   GtkWidget         *child)
+{
+  GtkWidget *item;
+
+  g_return_val_if_fail (GTK_IS_POPOVER_MENU_BAR (bar), FALSE);
+  g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
+
+  for (item = gtk_widget_get_first_child (GTK_WIDGET (bar));
+       item;
+       item = gtk_widget_get_next_sibling (item))
+    {
+      GtkPopover *popover = GTK_POPOVER_MENU_BAR_ITEM (item)->popover;
+
+      if (gtk_popover_menu_remove_child (GTK_POPOVER_MENU (popover), child))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
diff --git a/gtk/gtkpopovermenubar.h b/gtk/gtkpopovermenubar.h
index 5abf808181..08126f9d63 100644
--- a/gtk/gtkpopovermenubar.h
+++ b/gtk/gtkpopovermenubar.h
@@ -52,6 +52,9 @@ gboolean     gtk_popover_menu_bar_add_child      (GtkPopoverMenuBar *bar,
                                                   GtkWidget         *child,
                                                   const char        *id);
 
+GDK_AVAILABLE_IN_ALL
+gboolean     gtk_popover_menu_bar_remove_child   (GtkPopoverMenuBar *bar,
+                                                  GtkWidget         *child);
 G_END_DECLS
 
 


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