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. > > 2. LFUN_LYX_QUIT triggers LFUN_WINDOW_CLOSE > > 3. LFUN_WINDOW_CLOSE triggers LFUN_BUFFER_CLOSE one by one > > 4. closeEvent triggers LFUN_LYX_QUIT. > > That is to say, no one takes the shortcut quitWriteAll. lyx-close > experts (Peter, Enrico, Abdel), what do you think? Anything seriously > wrong here?
I think, the most important thing when quitting is that there is one place where all prepare-to-quit code is located. Does you patch support this? How many ways of quitting exit? 1. menu exit -> LFUN_LYX_QUIT 2. last window closed -> LFUN_WINDOW_CLOSE -> LFUN_LYX_QUIT two only? have I forgotten one? > > Bo > > > > 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")); > - > - if (ret == 0) { > - // FIXME: WriteAs can be asynch ! > - // but not right now...maybe we should remove that > - > - bool succeeded; > - > - if (buf->isUnnamed()) > - succeeded = writeAs(buf); > - else > - succeeded = menuWrite(buf); > - > - if (!succeeded) > - return false; > - } else if (ret == 1) { > - // if we crash after this we could > - // have no autosave file but I guess > - // this is really inprobable (Jug) > - if (buf->isUnnamed()) > - removeAutosaveFile(buf->fileName()); > - > - } else { > - return false; > - } > - > - return true; > -} > - > - > -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)) > - > LyX::ref().session().lastOpened().add(FileName((*it)->fileName())); > - } > - > - return true; > -} > - > - > void BufferList::release(Buffer * buf) > { > BOOST_ASSERT(buf); > Index: src/bufferlist.h > =================================================================== > --- src/bufferlist.h (revision 16658) > +++ src/bufferlist.h (working copy) > @@ -42,9 +42,6 @@ > iterator end(); > const_iterator end() const; > > - /// write all buffers, asking the user, returns false if cancelled > - bool quitWriteAll(); > - > /// create a new buffer > Buffer * newBuffer(std::string const & s, bool ronly = false); > > @@ -104,8 +101,6 @@ > void setCurrentAuthor(docstring const & name, docstring const & email); > > private: > - /// ask to save a buffer on quit, returns false if should cancel > - bool quitWriteBuffer(Buffer * buf); > > typedef std::vector<Buffer *> BufferStorage; > > 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)); > + if (theBufferList().empty()) > theApp()->gui().closeAllViews(); > 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 > + 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)); > + if (!theBufferList().empty()) { > close_event->ignore(); > return; > } > -- Peter Kümmel