diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 6b88760a1a..9517b18450 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -526,58 +526,68 @@ void GuiView::closeEvent(QCloseEvent * close_event) // e.g. when clicking the close button on a background window. setFocus(); - while (Buffer * b = buffer()) { - if (b->parent()) { - // This is a child document, just close the tab - // after saving but keep the file loaded. - if (!closeBuffer(*b, true)) { + int splitter_count = d.splitter_->count(); + for (; splitter_count > 0; --splitter_count) { + TabWorkArea * twa = d.tabWorkArea(0); + + int twa_count = twa->count(); + for (; twa_count > 0; --twa_count) { + twa->setCurrentIndex(0); + + GuiWorkArea * wa = twa->currentWorkArea(); + 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 (!closeBuffer(*b, true)) { + closing_ = false; + close_event->ignore(); + return; + } + 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]) + continue; + if (guiApp->view(ids[i]).workArea(*b)) { + // FIXME 1: should we put an alert box here that the buffer + // is viewed elsewhere? + // FIXME 2: should we try to save this buffer in any case? + //saveBuffer(b); + + // This buffer is also opened in another view, so + // close the associated work area... + removeWorkArea(d.current_work_area_); + // ... but don't close the buffer. + b = 0; + break; + } + } + if (b && !closeBuffer(*b, true)) { closing_ = false; close_event->ignore(); return; } - 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]) - continue; - if (guiApp->view(ids[i]).workArea(*b)) { - // FIXME 1: should we put an alert box here that the buffer - // is viewed elsewhere? - // FIXME 2: should we try to save this buffer in any case? - //saveBuffer(b); - - // This buffer is also opened in another view, so - // close the associated work area... - removeWorkArea(d.current_work_area_); - // ... but don't close the buffer. - b = 0; - break; - } - } - if (b && !closeBuffer(*b, true)) { - closing_ = false; - close_event->ignore(); - return; } } - // Make sure that nothing will use this close to be closed View. guiApp->unregisterView(this);