Jürgen Spitzmüller wrote:
> Attached is a patch that fixes it.

This patch also works for grandchildren (a problem outlined by Jean-Marc on 
bugzilla).

Jürgen
Index: src/Buffer.h
===================================================================
--- src/Buffer.h	(Revision 28709)
+++ src/Buffer.h	(Arbeitskopie)
@@ -281,6 +281,9 @@
 
 	/// \return true if \p child is a child of this \c Buffer.
 	bool isChild(Buffer * child) const;
+	
+	/// return a vector with all children and grandchildren
+	std::vector<Buffer *> getChildren() const;
 
 	/// Is buffer read-only?
 	bool isReadonly() const;
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp	(Revision 28709)
+++ src/frontends/qt4/GuiView.cpp	(Arbeitskopie)
@@ -525,16 +525,30 @@
 
 	while (Buffer * b = buffer()) {
 		if (b->parent()) {
-			// This is a child document, just close the tab after saving
-			// but keep the file loaded.
-			if (!saveBuffer(*b)) {
+			// This is a child document, just close the tab
+			// after saving but keep the file loaded.
+			if (!closeBuffer(*b, false)) {
 				closing_ = false;
 				close_event->ignore();
 				return;
 			}
-			removeWorkArea(d.current_work_area_);
 			continue;
 		}
+		
+		vector<Buffer *> clist = b->getChildren();
+		for (vector<Buffer *>::const_iterator it = clist.begin();
+		     it != clist.end(); ++it) {
+			if ((*it)->isClean())
+				continue;
+			Buffer * c = *it;
+			// If a child is dirty, do not close
+			// without user intervention
+			if (!closeBuffer(*c, false)) {
+				closing_ = false;
+				close_event->ignore();
+				return;
+			}
+		}
 
 		QList<int> const ids = guiApp->viewIds();
 		for (int i = 0; i != ids.size(); ++i) {
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 28709)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -290,7 +290,7 @@
 		Buffer * child = const_cast<Buffer *>(it->first);
 		// The child buffer might have been closed already.
 		if (theBufferList().isLoaded(child))
-			theBufferList().releaseChild(this, child);	
+			theBufferList().releaseChild(this, child);
 	}
 
 	// clear references to children in macro tables
@@ -1719,6 +1719,25 @@
 }
 
 
+std::vector<Buffer *> Buffer::getChildren() const
+{
+	std::vector<Buffer *> clist;
+	// loop over children
+	Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+	Impl::BufferPositionMap::iterator end = d->children_positions.end();
+	for (; it != end; ++it) {
+		Buffer * child = const_cast<Buffer *>(it->first);
+		clist.push_back(child);
+		// there might be grandchildren
+		std::vector<Buffer *> glist = child->getChildren();
+		for (vector<Buffer *>::const_iterator git = glist.begin();
+		     git != glist.end(); ++git)
+			clist.push_back(*git);
+	}
+	return clist;
+}
+
+
 template<typename M>
 typename M::iterator greatest_below(M & m, typename M::key_type const & x)
 {

Reply via email to