]> git.lyx.org Git - features.git/commitdiff
fix bug 5833
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 7 Mar 2009 16:33:03 +0000 (16:33 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 7 Mar 2009 16:33:03 +0000 (16:33 +0000)
* 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
src/Buffer.h
src/frontends/qt4/GuiView.cpp

index d977e2c2112e45a8dade542c17cafbcfebdd3a78..ec99566dba047b792de12f9193fde2785fb43a9a 100644 (file)
@@ -1765,6 +1765,25 @@ DocIterator Buffer::firstChildPosition(Buffer const * child)
 }
 
 
+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)
 {
index c62d5e702f1b114f8ebb0e2870877904234d33d2..02635d97e7524f5ad3b35248c0c0ab737bc248c0 100644 (file)
@@ -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<Buffer *> getChildren() const;
 
        /// Is buffer read-only?
        bool isReadonly() const;
index 47ee33b9405f3e2fe62fd1528eedec2b77214170..0d32400d777acdeadba5b84347b67e0a4370e575 100644 (file)
@@ -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<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) {
                        if (id_ == ids[i])