From f614081b832b2923821410b69117b5450fd83b5a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 22 Sep 2019 00:41:01 +0200 Subject: [PATCH] LibCore: Add CObject::remove_from_parent() This is a convenient shorthand for: if (object.parent()) object.parent()->remove_child(object); --- Libraries/LibCore/CObject.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/LibCore/CObject.h b/Libraries/LibCore/CObject.h index dd036ef666..7a5ce63785 100644 --- a/Libraries/LibCore/CObject.h +++ b/Libraries/LibCore/CObject.h @@ -85,6 +85,12 @@ public: void dispatch_event(CEvent&, CObject* stay_within = nullptr); + void remove_from_parent() + { + if (m_parent) + m_parent->remove_child(*this); + } + protected: explicit CObject(CObject* parent = nullptr, bool is_widget = false);