[libadwaita] Log a critical error when trying to remove a non-child
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita] Log a critical error when trying to remove a non-child
- Date: Fri, 21 May 2021 07:54:40 +0000 (UTC)
commit 5e10ed20dea78a8ef8f420fe9aa2b4e2dac1d4a1
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu May 20 09:14:50 2021 +0200
Log a critical error when trying to remove a non-child
This better warns users they messed up.
src/adw-action-row.c | 4 ++++
src/adw-expander-row.c | 3 +++
src/adw-header-bar.c | 3 +++
src/adw-macros-private.h | 27 +++++++++++++++++++++++++++
src/adw-preferences-group.c | 3 +++
src/adw-preferences-page.c | 3 +++
src/adw-preferences-window.c | 3 +++
7 files changed, 46 insertions(+)
---
diff --git a/src/adw-action-row.c b/src/adw-action-row.c
index 7b4279cb..f4822b0f 100644
--- a/src/adw-action-row.c
+++ b/src/adw-action-row.c
@@ -7,6 +7,8 @@
#include "config.h"
#include "adw-action-row.h"
+#include "adw-macros-private.h"
+
/**
* AdwActionRow:
*
@@ -862,6 +864,8 @@ adw_action_row_remove (AdwActionRow *self,
gtk_box_remove (priv->prefixes, child);
else if (parent == GTK_WIDGET (priv->suffixes))
gtk_box_remove (priv->suffixes, child);
+ else
+ ADW_CRITICAL_CANNOT_REMOVE_CHILD (self, child);
}
/**
diff --git a/src/adw-expander-row.c b/src/adw-expander-row.c
index 485de3ce..74b2ce5a 100644
--- a/src/adw-expander-row.c
+++ b/src/adw-expander-row.c
@@ -8,6 +8,7 @@
#include "adw-expander-row.h"
#include "adw-action-row.h"
+#include "adw-macros-private.h"
/**
* AdwExpanderRow:
@@ -752,4 +753,6 @@ adw_expander_row_remove (AdwExpanderRow *self,
if (!gtk_widget_get_first_child (GTK_WIDGET (priv->list)))
gtk_widget_add_css_class (GTK_WIDGET (self), "empty");
}
+ else
+ ADW_CRITICAL_CANNOT_REMOVE_CHILD (self, child);
}
diff --git a/src/adw-header-bar.c b/src/adw-header-bar.c
index a217231a..ddbdae5e 100644
--- a/src/adw-header-bar.c
+++ b/src/adw-header-bar.c
@@ -26,6 +26,7 @@
#include "adw-enums.h"
#include "adw-focus-private.h"
#include "adw-gizmo-private.h"
+#include "adw-macros-private.h"
/**
* AdwHeaderBar:
@@ -732,6 +733,8 @@ adw_header_bar_remove (AdwHeaderBar *self,
gtk_box_remove (GTK_BOX (self->end_box), child);
else if (parent == self->center_box)
gtk_center_box_set_center_widget (GTK_CENTER_BOX (self->center_box), NULL);
+ else
+ ADW_CRITICAL_CANNOT_REMOVE_CHILD (self, child);
}
/**
diff --git a/src/adw-macros-private.h b/src/adw-macros-private.h
new file mode 100644
index 00000000..93e53e05
--- /dev/null
+++ b/src/adw-macros-private.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2021 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+#pragma once
+
+#if !defined(_ADWAITA_INSIDE) && !defined(ADWAITA_COMPILATION)
+#error "Only <adwaita.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define ADW_CRITICAL_CANNOT_REMOVE_CHILD(parent, child) \
+G_STMT_START { \
+ g_critical ("%s:%d: tried to remove non-child %p of type '%s' from %p of type '%s'", \
+ __FILE__, __LINE__, \
+ (child), \
+ G_OBJECT_TYPE_NAME ((GObject*) (child)), \
+ (parent), \
+ G_OBJECT_TYPE_NAME ((GObject*) (parent))); \
+} G_STMT_END
+
+G_END_DECLS
diff --git a/src/adw-preferences-group.c b/src/adw-preferences-group.c
index b06e5ad7..28d61080 100644
--- a/src/adw-preferences-group.c
+++ b/src/adw-preferences-group.c
@@ -8,6 +8,7 @@
#include "adw-preferences-group-private.h"
+#include "adw-macros-private.h"
#include "adw-preferences-row.h"
/**
@@ -466,4 +467,6 @@ adw_preferences_group_remove (AdwPreferencesGroup *self,
gtk_list_box_remove (priv->listbox, child);
else if (parent == GTK_WIDGET (priv->listbox_box))
gtk_box_remove (priv->listbox_box, child);
+ else
+ ADW_CRITICAL_CANNOT_REMOVE_CHILD (self, child);
}
diff --git a/src/adw-preferences-page.c b/src/adw-preferences-page.c
index 25be2fd1..363133d0 100644
--- a/src/adw-preferences-page.c
+++ b/src/adw-preferences-page.c
@@ -8,6 +8,7 @@
#include "adw-preferences-page-private.h"
+#include "adw-macros-private.h"
#include "adw-preferences-group-private.h"
/**
@@ -462,4 +463,6 @@ adw_preferences_page_remove (AdwPreferencesPage *self,
if (gtk_widget_get_parent (GTK_WIDGET (group)) == GTK_WIDGET (priv->box))
gtk_box_remove (priv->box, GTK_WIDGET (group));
+ else
+ ADW_CRITICAL_CANNOT_REMOVE_CHILD (self, group);
}
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index 3d682699..e65a0ed8 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -12,6 +12,7 @@
#include "adw-animation.h"
#include "adw-action-row.h"
#include "adw-leaflet.h"
+#include "adw-macros-private.h"
#include "adw-preferences-group-private.h"
#include "adw-preferences-page-private.h"
#include "adw-view-switcher.h"
@@ -827,4 +828,6 @@ adw_preferences_window_remove (AdwPreferencesWindow *self,
if (gtk_widget_get_parent (GTK_WIDGET (page)) == GTK_WIDGET (priv->pages_stack))
gtk_stack_remove (priv->pages_stack, GTK_WIDGET (page));
+ else
+ ADW_CRITICAL_CANNOT_REMOVE_CHILD (self, page);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]