Bo Peng wrote:
What I meant is something like follows. The patch does not work
correctly yet, but shows my point.
1. src/bufferlist.C: remove quitWriteBuffer and quitWriteAll.
This part is good. The BufferList should not care about quitting and
asking for user interaction.
2. LFUN_LYX_QUIT triggers LFUN_WINDOW_CLOSE
Good in theory but you have to make sure that it works equally well on
the three supported platform.
3. LFUN_WINDOW_CLOSE triggers LFUN_BUFFER_CLOSE one by one
Be careful here, we should do that only if it is the last window.
4. closeEvent triggers LFUN_LYX_QUIT.
Only if it is the last window.
That is to say, no one takes the shortcut quitWriteAll. lyx-close
experts (Peter, Enrico, Abdel), what do you think? Anything seriously
wrong here?
See above. More comments below:
Index: src/bufferlist.C
===================================================================
--- src/bufferlist.C (revision 16658)
+++ src/bufferlist.C (working copy)
@@ -96,76 +96,6 @@
}
-bool BufferList::quitWriteBuffer(Buffer * buf)
-{
- BOOST_ASSERT(buf);
-
- docstring file;
- if (buf->isUnnamed())
- file = from_utf8(onlyFilename(buf->fileName()));
- else
- file = makeDisplayPath(buf->fileName(), 30);
-
- docstring const text =
- bformat(_("The document %1$s has unsaved changes.\n\n"
- "Do you want to save the document or discard the
changes?"),
- file);
- int const ret = Alert::prompt(_("Save changed document?"),
- text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
I agree this has nothing to do here but we have to ask this question to
the user nevertheless, don't we? So where is this part of the code
transferred?
[...]
-bool BufferList::quitWriteAll()
-{
- BufferStorage::iterator it = bstore.begin();
- BufferStorage::iterator end = bstore.end();
- for (; it != end; ++it) {
- if ((*it)->isClean())
- continue;
-
- if (!quitWriteBuffer(*it))
- return false;
- }
- // now, all buffers have been written sucessfully
- // save file names to .lyx/session
- it = bstore.begin();
- for (; it != end; ++it) {
- // if master/slave are both open, do not save slave since it
- // will be automatically loaded when the master is loaded
- if ((*it)->getMasterBuffer() == (*it))
Same question here. Where is that transferred? I am probably missing
something.
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C (revision 16658)
+++ src/lyxfunc.C (working copy)
@@ -1074,7 +1074,8 @@
case LFUN_LYX_QUIT:
// quitting is triggered by the gui code
// (leaving the event loop).
- if (theBufferList().quitWriteAll())
+ dispatch(FuncRequest(LFUN_WINDOW_CLOSE));
Here you have to call LFUN_WINDOW_CLOSE for every window. The list is
given to you by the Gui class.
+ if (theBufferList().empty())
theApp()->gui().closeAllViews();
This Gui::closeAllViews() is redundant here if you have already closed
all the windows (view == window).
break;
@@ -1703,13 +1704,19 @@
case LFUN_WINDOW_CLOSE:
BOOST_ASSERT(lyx_view_);
BOOST_ASSERT(theApp());
- // update bookmark pit of the current buffer before window
close
- for (size_t i = 0; i <
LyX::ref().session().bookmarks().size(); ++i)
- gotoBookmark(i+1, false, false);
- // ask the user for saving changes or cancel quit
- if (!theBufferList().quitWriteAll())
- break;
- lyx_view_->close();
+ // close buffer one by one
Be careful here, only if it is the last window.
+ while (true) {
+ string const file = lyx_view_->buffer()->fileName();
+ dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
+ // all files closed
+ if (theBufferList().empty()) {
+ lyx_view_->close();
+ break;
+ // buffer close failed
+ if (file == lyx_view_->buffer()->fileName())
+ break;
+ }
+ }
return;
case LFUN_BOOKMARK_GOTO:
Index: src/frontends/qt4/GuiView.C
===================================================================
--- src/frontends/qt4/GuiView.C (revision 16658)
+++ src/frontends/qt4/GuiView.C (working copy)
@@ -237,7 +237,8 @@
// we may have been called through the close window button
// which bypasses the LFUN machinery.
if (!quitting_by_menu_) {
- if (!theBufferList().quitWriteAll()) {
+ dispatch(FuncRequest(LFUN_LYX_QUIT));
Good in theory but you have to make sure that it works equally well on
the three supported platform.
+ if (!theBufferList().empty()) {
So this means that the user clicked [Cancel] here... But I fail to see
where is the code for that.
close_event->ignore();
return;
}
Abdel.