From 1355b26e849776587d88acadfc280bb9dc3be11f Mon Sep 17 00:00:00 2001
From: Lastin <maksymsmail@gmail.com>
Date: Sun, 10 Jan 2016 17:11:07 +0000
Subject: [PATCH] Adds flag whether to destroy objects when removing all
 children from a widget

---
 src/dlangui/core/collections.d | 6 ++++--
 src/dlangui/widgets/widget.d   | 6 +++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/dlangui/core/collections.d b/src/dlangui/core/collections.d
index 98ea7661..616affa9 100644
--- a/src/dlangui/core/collections.d
+++ b/src/dlangui/core/collections.d
@@ -324,9 +324,11 @@ struct ObjectList(T) {
         }
     }
     /** remove and destroy all items */
-    void clear() {
+	void clear(bool destroyObj = true) {
         for (int i = 0; i < _count; i++) {
-            destroy(_list[i]);
+			if(destroyObj) {
+				destroy(_list[i]);
+            }
             _list[i] = null;
         }
         _count = 0;
diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d
index 74647d86..ebc906da 100644
--- a/src/dlangui/widgets/widget.d
+++ b/src/dlangui/widgets/widget.d
@@ -1513,7 +1513,7 @@ public:
         _window = window; 
     }
 
-    void removeAllChildren() {
+    void removeAllChildren(bool destroyObj = true) {
         // override
     }
 
@@ -1648,8 +1648,8 @@ class WidgetGroup : Widget {
     /// returns index of widget in child list, -1 if passed widget is not a child of this widget
     override int childIndex(Widget item) { return _children.indexOf(item); }
 
-    override void removeAllChildren() {
-        _children.clear();
+	override void removeAllChildren(bool destroyObj = true) {
+        _children.clear(destroyObj);
     }
 
 }