// it can happen that this event arrives without selecting the view,
// e.g. when clicking the close button on a background window.
setFocus();
- if (!closeBufferAll(true)) {
+ if (!closeWorkAreaAll(true)) {
closing_ = false;
close_event->ignore();
return;
}
-bool GuiView::closeBufferAll(bool in_close_event)
-{
- GuiWorkArea * active_wa = currentMainWorkArea();
- setCurrentWorkArea(active_wa);
-
- // We might be in a situation that there is still a tabWorkArea, but
- // there are no tabs anymore. This can happen when we get here after a
- // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
- // many TabWorkArea's have no documents anymore.
- int empty_twa = 0;
-
- // We have to call count() each time, because it can happen that
- // more than one splitter will disappear in one iteration (bug 5998).
- for (; d.splitter_->count() > empty_twa; ) {
- TabWorkArea * twa = d.tabWorkArea(empty_twa);
-
- int twa_count = twa->count();
- if (twa->count() == 0)
- ++empty_twa;
-
- for (; twa == d.tabWorkArea(empty_twa) && twa_count; --twa_count) {
- twa->setCurrentIndex(twa_count-1);
-
- GuiWorkArea * wa = twa->currentWorkArea();
- bool const is_active_wa = active_wa == wa;
- Buffer & b = wa->bufferView().buffer();
-
- // We only want to close the buffer if the same buffer is not in
- // another view.
- bool const close_buffer = !(inMultiViews(wa) || b.parent());
-
- // closeBuffer() needs buffer workArea still alive and
- // set as currrent one, and destroys it
- if (!closeWorkArea(wa, close_buffer, in_close_event, is_active_wa))
- return false;
- }
- }
- return true;
-}
-
-
void GuiView::dragEnterEvent(QDragEnterEvent * event)
{
if (event->mimeData()->hasUrls())
bool GuiView::closeWorkArea(GuiWorkArea * wa)
{
- return closeWorkArea(wa, true);
+ Buffer & buf = wa->bufferView().buffer();
+ return closeWorkArea(wa, !buf.parent());
}
}
+bool GuiView::closeBufferAll(bool in_close_event)
+{
+ // First close all workareas. This will make
+ // sure that dirty buffers are saved.
+ if (!closeWorkAreaAll(in_close_event))
+ return false;
+
+ // Now close the hidden buffers. We prevent hidden
+ // buffers from being dirty, so we can just close them.
+ theBufferList().closeAll();
+ return true;
+}
+
+
+bool GuiView::closeWorkAreaAll(bool in_close_event)
+{
+ GuiWorkArea * active_wa = currentMainWorkArea();
+ setCurrentWorkArea(active_wa);
+
+ // We might be in a situation that there is still a tabWorkArea, but
+ // there are no tabs anymore. This can happen when we get here after a
+ // TabWorkArea::lastWorkAreaRemoved() signal. Therefore we count how
+ // many TabWorkArea's have no documents anymore.
+ int empty_twa = 0;
+
+ // We have to call count() each time, because it can happen that
+ // more than one splitter will disappear in one iteration (bug 5998).
+ for (; d.splitter_->count() > empty_twa; ) {
+ TabWorkArea * twa = d.tabWorkArea(empty_twa);
+
+ if (twa->count() == 0)
+ ++empty_twa;
+ else {
+ setCurrentWorkArea(twa->currentWorkArea());
+ if (!closeTabWorkArea(twa, true, active_wa))
+ return false;
+ }
+ }
+ return true;
+}
+
+
bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer,
bool in_close_event, bool mark_active)
{
}
+bool GuiView::closeTabWorkArea(TabWorkArea * twa, bool in_close_event,
+ GuiWorkArea * main_work_area)
+{
+ while (twa == d.currentTabWorkArea()) {
+ twa->setCurrentIndex(twa->count()-1);
+
+ GuiWorkArea * wa = twa->currentWorkArea();
+ bool const is_active_wa = main_work_area == wa;
+ Buffer & b = wa->bufferView().buffer();
+
+ // We only want to close the buffer if the same buffer is not visible
+ // in another view, and if this is not a child and if we are closing
+ // a view (not a tabgroup).
+ bool const close_buffer =
+ !inMultiViews(wa) && !b.parent() && in_close_event;
+
+ // closeBuffer() needs buffer workArea still alive and
+ // set as currrent one, and destroys it
+ if (!closeWorkArea(wa, close_buffer, true, is_active_wa))
+ return false;
+ }
+ return true;
+}
+
+
bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
{
if (buf.isClean() || buf.paragraphs().empty())
case LFUN_CLOSE_TAB_GROUP:
if (TabWorkArea * twa = d.currentTabWorkArea()) {
- delete twa;
+ closeTabWorkArea(twa, false);
d.current_work_area_ = 0;
twa = d.currentTabWorkArea();
// Switch to the next GuiWorkArea in the found TabWorkArea.