summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-22 00:41:01 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-22 00:41:01 +0200
commitf614081b832b2923821410b69117b5450fd83b5a (patch)
treeeb6a25bde8771b6a715c1bbd80882c6576a365e9
parentd6abfbdc5a7838fdc8e20e43a5146968a8dbcd81 (diff)
downloadserenity-f614081b832b2923821410b69117b5450fd83b5a.zip
LibCore: Add CObject::remove_from_parent()
This is a convenient shorthand for: if (object.parent()) object.parent()->remove_child(object);
-rw-r--r--Libraries/LibCore/CObject.h6
1 files changed, 6 insertions, 0 deletions
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);