- Ditch the in_close_event parameter, as we can use closing_ for this purpose.

- Add some comments for the functions.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31127 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-08-18 20:48:15 +00:00
parent 49d03a2576
commit b2588a80f3
2 changed files with 28 additions and 27 deletions

View File

@ -547,7 +547,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
// it can happen that this event arrives without selecting the view, // it can happen that this event arrives without selecting the view,
// e.g. when clicking the close button on a background window. // e.g. when clicking the close button on a background window.
setFocus(); setFocus();
if (!closeWorkAreaAll(true)) { if (!closeWorkAreaAll()) {
closing_ = false; closing_ = false;
close_event->ignore(); close_event->ignore();
return; return;
@ -1875,22 +1875,23 @@ bool GuiView::closeBuffer()
} }
bool GuiView::closeBufferAll(bool in_close_event) bool GuiView::closeBufferAll()
{ {
// First close all workareas. This will make // First close all workareas. This will make
// sure that dirty buffers are saved. // sure that dirty buffers are saved.
if (!closeWorkAreaAll(in_close_event)) if (!closeWorkAreaAll())
return false; return false;
// Now close the hidden buffers. We prevent hidden // Now close the hidden buffers. We prevent hidden buffers from being
// buffers from being dirty, so we can just close them. // dirty, so we can just close them.
theBufferList().closeAll(); theBufferList().closeAll();
return true; return true;
} }
bool GuiView::closeWorkAreaAll(bool in_close_event) bool GuiView::closeWorkAreaAll()
{ {
// To write in the session file which workarea was active.
GuiWorkArea * active_wa = currentMainWorkArea(); GuiWorkArea * active_wa = currentMainWorkArea();
setCurrentWorkArea(active_wa); setCurrentWorkArea(active_wa);
@ -1909,7 +1910,7 @@ bool GuiView::closeWorkAreaAll(bool in_close_event)
++empty_twa; ++empty_twa;
else { else {
setCurrentWorkArea(twa->currentWorkArea()); setCurrentWorkArea(twa->currentWorkArea());
if (!closeTabWorkArea(twa, true, active_wa)) if (!closeTabWorkArea(twa, active_wa))
return false; return false;
} }
} }
@ -1918,11 +1919,11 @@ bool GuiView::closeWorkAreaAll(bool in_close_event)
bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer, bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer,
bool in_close_event, bool mark_active) bool is_active)
{ {
Buffer & buf = wa->bufferView().buffer(); Buffer & buf = wa->bufferView().buffer();
if (close_buffer && !in_close_event) { if (close_buffer && !closing_) {
vector<Buffer *> clist = buf.getChildren(); vector<Buffer *> clist = buf.getChildren();
for (vector<Buffer *>::const_iterator it = clist.begin(); for (vector<Buffer *>::const_iterator it = clist.begin();
it != clist.end(); ++it) { it != clist.end(); ++it) {
@ -1949,8 +1950,8 @@ bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer,
// save in sessions if requested // save in sessions if requested
// do not save childs if their master // do not save childs if their master
// is opened as well // is opened as well
if (in_close_event) if (closing_)
theSession().lastOpened().add(buf.fileName(), mark_active); theSession().lastOpened().add(buf.fileName(), is_active);
if (!close_buffer) if (!close_buffer)
removeWorkArea(wa); removeWorkArea(wa);
else else
@ -1961,8 +1962,7 @@ bool GuiView::closeWorkArea(GuiWorkArea * wa, bool close_buffer,
} }
bool GuiView::closeTabWorkArea(TabWorkArea * twa, bool in_close_event, bool GuiView::closeTabWorkArea(TabWorkArea * twa, GuiWorkArea * main_work_area)
GuiWorkArea * main_work_area)
{ {
while (twa == d.currentTabWorkArea()) { while (twa == d.currentTabWorkArea()) {
twa->setCurrentIndex(twa->count()-1); twa->setCurrentIndex(twa->count()-1);
@ -1975,11 +1975,9 @@ bool GuiView::closeTabWorkArea(TabWorkArea * twa, bool in_close_event,
// in another view, and if this is not a child and if we are closing // in another view, and if this is not a child and if we are closing
// a view (not a tabgroup). // a view (not a tabgroup).
bool const close_buffer = bool const close_buffer =
!inMultiViews(wa) && !b.parent() && in_close_event; !inMultiViews(wa) && !b.parent() && closing_;
// closeBuffer() needs buffer workArea still alive and if (!closeWorkArea(wa, close_buffer, is_active_wa))
// set as currrent one, and destroys it
if (!closeWorkArea(wa, close_buffer, true, is_active_wa))
return false; return false;
} }
return true; return true;

View File

@ -89,7 +89,7 @@ public:
Buffer const * buffer() const; Buffer const * buffer() const;
/// set a buffer to the current workarea. /// set a buffer to the current workarea.
void setBuffer(Buffer * b); ///< \c Buffer to set. void setBuffer(Buffer * b); ///< \c Buffer to set.
/// /// closes the current active buffer
bool closeBuffer(); bool closeBuffer();
/// hides the workarea and makes sure it is clean /// hides the workarea and makes sure it is clean
bool hideWorkArea(GuiWorkArea * wa); bool hideWorkArea(GuiWorkArea * wa);
@ -297,20 +297,23 @@ private:
bool renameBuffer(Buffer & b, docstring const & newname); bool renameBuffer(Buffer & b, docstring const & newname);
/// ///
bool saveBuffer(Buffer & b); bool saveBuffer(Buffer & b);
/// /// closes a workarea, if close_buffer is true the buffer will
/// also be released, otherwise the buffer will be hidden.
bool closeWorkArea(GuiWorkArea * wa, bool close_buffer, bool closeWorkArea(GuiWorkArea * wa, bool close_buffer,
bool in_close_event = false, bool mark_active = false); bool is_active = false);
/// closes the tabworkarea and all tabs. /// closes the tabworkarea and all tabs. If we are in a close event,
bool closeTabWorkArea(TabWorkArea * twa, bool in_close_event = false, /// all buffers will be closed, otherwise they will be hidden.
/// main_work_area is the workarea marked in the session file as active.
bool closeTabWorkArea(TabWorkArea * twa,
GuiWorkArea * main_work_area = 0); GuiWorkArea * main_work_area = 0);
/// gives the user the possibility to save his work /// gives the user the possibility to save his work
/// or to discard the changes. If hiding is true, the /// or to discard the changes. If hiding is true, the
/// document will be reloaded. /// document will be reloaded.
bool saveBufferIfNeeded(Buffer & buf, bool hiding); bool saveBufferIfNeeded(Buffer & buf, bool hiding);
/// /// closes all workareas and all hidden buffers
bool closeBufferAll(bool in_close_event = false); bool closeBufferAll();
/// /// closes all workareas
bool closeWorkAreaAll(bool in_close_event = false); bool closeWorkAreaAll();
/// is the buffer in this workarea also shown in another tab ? /// is the buffer in this workarea also shown in another tab ?
/// This tab can either be in the same view or in another one. /// This tab can either be in the same view or in another one.
bool inMultiTabs(GuiWorkArea * wa); bool inMultiTabs(GuiWorkArea * wa);