[libadwaita] Harden remove() methods
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita] Harden remove() methods
- Date: Fri, 21 May 2021 07:54:40 +0000 (UTC)
commit 8933b82491582d9dece1e0d4f6f9653f3a1d6e0a
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu May 20 09:14:50 2021 +0200
Harden remove() methods
This either simplifies them where possible or ensure we don't try
removing children in the wrong widget.
src/adw-action-row.c | 7 +++++--
src/adw-expander-row.c | 10 +++++++---
src/adw-preferences-group.c | 7 +++++--
src/adw-preferences-page.c | 3 ++-
src/adw-preferences-window.c | 3 ++-
5 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/adw-action-row.c b/src/adw-action-row.c
index 81756268..7b4279cb 100644
--- a/src/adw-action-row.c
+++ b/src/adw-action-row.c
@@ -849,15 +849,18 @@ adw_action_row_remove (AdwActionRow *self,
GtkWidget *child)
{
AdwActionRowPrivate *priv;
+ GtkWidget *parent;
g_return_if_fail (ADW_IS_ACTION_ROW (self));
g_return_if_fail (GTK_IS_WIDGET (child));
priv = adw_action_row_get_instance_private (self);
- if (gtk_widget_get_parent (child) == GTK_WIDGET (priv->prefixes))
+ parent = gtk_widget_get_parent (child);
+
+ if (parent == GTK_WIDGET (priv->prefixes))
gtk_box_remove (priv->prefixes, child);
- else
+ else if (parent == GTK_WIDGET (priv->suffixes))
gtk_box_remove (priv->suffixes, child);
}
diff --git a/src/adw-expander-row.c b/src/adw-expander-row.c
index 82e02dc6..485de3ce 100644
--- a/src/adw-expander-row.c
+++ b/src/adw-expander-row.c
@@ -732,17 +732,21 @@ adw_expander_row_remove (AdwExpanderRow *self,
GtkWidget *child)
{
AdwExpanderRowPrivate *priv;
+ GtkWidget *parent;
g_return_if_fail (ADW_IS_EXPANDER_ROW (self));
g_return_if_fail (GTK_IS_WIDGET (child));
priv = adw_expander_row_get_instance_private (self);
- if (gtk_widget_get_parent (child) == GTK_WIDGET (priv->actions))
+ parent = gtk_widget_get_parent (child);
+
+ if (parent == GTK_WIDGET (priv->actions))
gtk_box_remove (priv->actions, child);
- else if (gtk_widget_get_parent (child) == GTK_WIDGET (priv->prefixes))
+ else if (parent == GTK_WIDGET (priv->prefixes))
gtk_box_remove (priv->prefixes, child);
- else {
+ else if (parent == GTK_WIDGET (priv->list) ||
+ (GTK_IS_WIDGET (parent) && (gtk_widget_get_parent (parent) == GTK_WIDGET (priv->list)))) {
gtk_list_box_remove (priv->list, child);
if (!gtk_widget_get_first_child (GTK_WIDGET (priv->list)))
diff --git a/src/adw-preferences-group.c b/src/adw-preferences-group.c
index 9c051b02..b06e5ad7 100644
--- a/src/adw-preferences-group.c
+++ b/src/adw-preferences-group.c
@@ -453,14 +453,17 @@ adw_preferences_group_remove (AdwPreferencesGroup *self,
GtkWidget *child)
{
AdwPreferencesGroupPrivate *priv;
+ GtkWidget *parent;
g_return_if_fail (ADW_IS_PREFERENCES_GROUP (self));
g_return_if_fail (GTK_IS_WIDGET (child));
priv = adw_preferences_group_get_instance_private (self);
- if (ADW_IS_PREFERENCES_ROW (child))
+ parent = gtk_widget_get_parent (child);
+
+ if (parent == GTK_WIDGET (priv->listbox))
gtk_list_box_remove (priv->listbox, child);
- else if (child != GTK_WIDGET (priv->listbox))
+ else if (parent == GTK_WIDGET (priv->listbox_box))
gtk_box_remove (priv->listbox_box, child);
}
diff --git a/src/adw-preferences-page.c b/src/adw-preferences-page.c
index 672a60c0..25be2fd1 100644
--- a/src/adw-preferences-page.c
+++ b/src/adw-preferences-page.c
@@ -460,5 +460,6 @@ adw_preferences_page_remove (AdwPreferencesPage *self,
priv = adw_preferences_page_get_instance_private (self);
- gtk_box_remove (priv->box, GTK_WIDGET (group));
+ if (gtk_widget_get_parent (GTK_WIDGET (group)) == GTK_WIDGET (priv->box))
+ gtk_box_remove (priv->box, GTK_WIDGET (group));
}
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index 9a1ac995..3d682699 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -825,5 +825,6 @@ adw_preferences_window_remove (AdwPreferencesWindow *self,
priv = adw_preferences_window_get_instance_private (self);
- gtk_stack_remove (priv->pages_stack, GTK_WIDGET (page));
+ if (gtk_widget_get_parent (GTK_WIDGET (page)) == GTK_WIDGET (priv->pages_stack))
+ gtk_stack_remove (priv->pages_stack, GTK_WIDGET (page));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]