From d7601a684b3b68d4a19715f944ebc4d384eb832a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 7 Mar 2009 16:33:03 +0000 Subject: [PATCH] fix bug 5833 * Buffer.{cpp, h}: - new method getChildren() that returns included (and sub-included) files * GuiView.cpp (closeEvent): - do not just close dirty child documents. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28712 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 19 +++++++++++++++++++ src/Buffer.h | 3 +++ src/frontends/qt4/GuiView.cpp | 22 ++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d977e2c211..ec99566dba 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1765,6 +1765,25 @@ DocIterator Buffer::firstChildPosition(Buffer const * child) } +std::vector Buffer::getChildren() const +{ + std::vector 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(it->first); + clist.push_back(child); + // there might be grandchildren + std::vector glist = child->getChildren(); + for (vector::const_iterator git = glist.begin(); + git != glist.end(); ++git) + clist.push_back(*git); + } + return clist; +} + + template typename M::iterator greatest_below(M & m, typename M::key_type const & x) { diff --git a/src/Buffer.h b/src/Buffer.h index c62d5e702f..02635d97e7 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -282,6 +282,9 @@ public: /// \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 getChildren() const; /// Is buffer read-only? bool isReadonly() const; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 47ee33b940..0d32400d77 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -533,17 +533,31 @@ void GuiView::closeEvent(QCloseEvent * close_event) while (GuiWorkArea * wa = currentMainWorkArea()) { Buffer * b = &wa->bufferView().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(wa); continue; } + vector clist = b->getChildren(); + for (vector::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 const ids = guiApp->viewIds(); for (int i = 0; i != ids.size(); ++i) { if (id_ == ids[i])