diff --git a/DevTools/Playground/main.cpp b/DevTools/Playground/main.cpp index 33e58e22c74..cb40a80909a 100644 --- a/DevTools/Playground/main.cpp +++ b/DevTools/Playground/main.cpp @@ -46,10 +46,7 @@ int main(int argc, char** argv) editor.set_automatic_indentation_enabled(true); editor.on_change = [&] { - // FIXME: This is not a very expressive way to remove all children.. - while (!preview.children().is_empty()) - preview.children().first().remove_from_parent(); - + preview.remove_all_children(); preview.load_from_gml(editor.text()); }; diff --git a/Libraries/LibCore/Object.cpp b/Libraries/LibCore/Object.cpp index df2359e0019..7db8548073a 100644 --- a/Libraries/LibCore/Object.cpp +++ b/Libraries/LibCore/Object.cpp @@ -130,6 +130,12 @@ void Object::remove_child(Object& object) ASSERT_NOT_REACHED(); } +void Object::remove_all_children() +{ + while (!m_children.is_empty()) + m_children.first().remove_from_parent(); +} + void Object::timer_event(Core::TimerEvent&) { } diff --git a/Libraries/LibCore/Object.h b/Libraries/LibCore/Object.h index ce3355e88ce..1bed1110b4b 100644 --- a/Libraries/LibCore/Object.h +++ b/Libraries/LibCore/Object.h @@ -105,6 +105,7 @@ public: void add_child(Object&); void insert_child_before(Object& new_child, Object& before_child); void remove_child(Object&); + void remove_all_children(); void dump_tree(int indent = 0);