Browse Source

LibCore: Add CObject::remove_from_parent()

This is a convenient shorthand for:

    if (object.parent())
        object.parent()->remove_child(object);
Andreas Kling 5 years ago
parent
commit
f614081b83
1 changed files with 6 additions and 0 deletions
  1. 6 0
      Libraries/LibCore/CObject.h

+ 6 - 0
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);