the idea is to get rid of view-related back pointers in buffer, and make it act as a mere backend as it should.
I suppose the patch can be syntetized in say: |RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v |retrieving revision 1.491 |diff -u -p -u -r1.491 buffer.C |--- buffer.C 7 Jul 2003 08:36:57 -0000 1.491 |+++ buffer.C 9 Jul 2003 10:01:11 -0000 |@@ -32,7 +32,6 @@ | #include "errorlist.h" | #include "Lsstream.h" | #include "format.h" |-#include "BufferView.h" It also cleans up the VC code a little IMHO. BufferView_pimpl.C | 15 +++++------ BufferView_pimpl.h | 4 ++ buffer.C | 67 +------------------------------------------------- buffer.h | 46 ++++++---------------------------- bufferview_funcs.C | 11 ++++++++ bufferview_funcs.h | 2 + insets/insettabular.C | 17 +++++++----- insets/insettabular.h | 2 + lyxfunc.C | 41 ++++++++++++++++++++++++++++-- lyxvc.C | 45 +-------------------------------- lyxvc.h | 3 -- vc-backend.C | 17 ------------ vc-backend.h | 3 -- 13 files changed, 88 insertions(+), 185 deletions(-) Of course, a lot of testing needed probably. Please comment, Alfredo Index: BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.386 diff -u -p -u -r1.386 BufferView_pimpl.C --- BufferView_pimpl.C 7 Jul 2003 08:36:55 -0000 1.386 +++ BufferView_pimpl.C 9 Jul 2003 10:01:08 -0000 @@ -146,6 +146,8 @@ void BufferView::Pimpl::connectBuffer(Bu errorConnection_ = buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1)); messageConnection_ = buf.message.connect(boost::bind(&LyXView::message, owner_, _1)); busyConnection_ = buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1)); + titleConnection_ = buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_)); + timerConnection_ = buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_)); } @@ -154,6 +156,8 @@ void BufferView::Pimpl::disconnectBuffer errorConnection_.disconnect(); messageConnection_.disconnect(); busyConnection_.disconnect(); + titleConnection_.disconnect(); + timerConnection_.disconnect(); } @@ -246,8 +250,6 @@ void BufferView::Pimpl::buffer(Buffer * << b << ')' << endl; if (buffer_) { disconnectBuffer(); - buffer_->delUser(bv_); - // Put the old text into the TextCache, but // only if the buffer is still loaded. // Also set the owner of the test to 0 @@ -273,7 +275,6 @@ void BufferView::Pimpl::buffer(Buffer * if (buffer_) { lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl; - buffer_->addUser(bv_); connectBuffer(*buffer_); // If we don't have a text object for this, we make one @@ -381,7 +382,7 @@ int BufferView::Pimpl::resizeCurrentBuff selection = bv_->text->selection.set(); mark_set = bv_->text->selection.mark(); the_locking_inset = bv_->theLockingInset(); - buffer_->resizeInsets(bv_); + bv_funcs::resizeInsets(bv_); // I don't think the delete and new are necessary here we // just could call only init! (Jug 20020419) delete bv_->text; @@ -401,11 +402,11 @@ int BufferView::Pimpl::resizeCurrentBuff if (lyxerr.debugging()) textcache.show(lyxerr, "resizeCurrentBuffer"); - buffer_->resizeInsets(bv_); + bv_funcs::resizeInsets(bv_); } else { bv_->text = new LyXText(bv_); bv_->text->init(bv_); - //buffer_->resizeInsets(bv_); + //bv_funcs::resizeInsets(bv_); } par = bv_->text->ownerParagraphs().end(); @@ -606,7 +607,7 @@ void BufferView::Pimpl::workAreaResize() textcache.show(lyxerr, "Expose delete all"); textcache.clear(); // FIXME: this is already done in resizeCurrentBuffer() ?? - buffer_->resizeInsets(bv_); + bv_funcs::resizeInsets(bv_); } else if (heightChange) { // fitCursor() ensures we don't jump back // to the start of the document on vertical Index: BufferView_pimpl.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v retrieving revision 1.91 diff -u -p -u -r1.91 BufferView_pimpl.h --- BufferView_pimpl.h 7 Jul 2003 08:36:55 -0000 1.91 +++ BufferView_pimpl.h 9 Jul 2003 10:01:08 -0000 @@ -119,6 +119,10 @@ private: boost::signals::connection messageConnection_; /// buffer busy status signal connection boost::signals::connection busyConnection_; + /// buffer title changed signal connection + boost::signals::connection titleConnection_; + /// buffer title changed signal connection + boost::signals::connection timerConnection_; /// connect to signals in the given buffer void connectBuffer(Buffer & buf); /// disconnect from signals in the given buffer Index: buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.491 diff -u -p -u -r1.491 buffer.C --- buffer.C 7 Jul 2003 08:36:57 -0000 1.491 +++ buffer.C 9 Jul 2003 10:01:11 -0000 @@ -32,7 +32,6 @@ #include "errorlist.h" #include "Lsstream.h" #include "format.h" -#include "BufferView.h" #include "ParagraphParameters.h" #include "iterators.h" #include "lyxtextclasslist.h" @@ -124,7 +123,7 @@ const int LYX_FORMAT = 224; Buffer::Buffer(string const & file, bool ronly) : niceFile(true), lyx_clean(true), bak_clean(true), unnamed(false), read_only(ronly), - filename_(file), users(0) + filename_(file) { lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl; filepath_ = OnlyPath(file); @@ -148,9 +147,6 @@ Buffer::~Buffer() // make sure that views using this buffer // forgets it. - if (users) - users->buffer(0); - if (!tmppath.empty() && destroyDir(tmppath) != 0) { Alert::warning(_("Could not remove temporary directory"), bformat(_("Could not remove the temporary directory %1$s"), tmppath)); @@ -210,8 +206,7 @@ void Buffer::setReadonly(bool flag) if (read_only != flag) { read_only = flag; updateTitles(); - if (users) - users->owner()->getDialogs().updateBufferDependent(false); + readonly(flag); } } @@ -222,24 +217,6 @@ AuthorList & Buffer::authors() } -/// Update window titles of all users -// Should work on a list -void Buffer::updateTitles() const -{ - if (users) - users->owner()->updateWindowTitle(); -} - - -/// Reset autosave timer of all users -// Should work on a list -void Buffer::resetAutosaveTimers() const -{ - if (users) - users->owner()->resetAutosaveTimer(); -} - - void Buffer::setFileName(string const & newfile) { filename_ = MakeAbsPath(newfile); @@ -321,9 +298,6 @@ bool Buffer::readBody(LyXLex & lex, Para params.textclass = 0; } } else { - // We are inserting into an existing document - users->text->breakParagraph(paragraphs); - // We don't want to adopt the parameters from the // document we insert, so read them into a temporary buffer // and then discard it @@ -1904,8 +1878,6 @@ void Buffer::simpleDocBookOnePar(ostream // Other flags: -wall -v0 -x int Buffer::runChktex() { - if (!users->text) return 0; - busy(true); // get LaTeX-Filename @@ -2087,22 +2059,6 @@ bool Buffer::dispatch(int action, string } -void Buffer::resizeInsets(BufferView * bv) -{ - /// then remove all LyXText in text-insets - for_each(paragraphs.begin(), paragraphs.end(), - boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv)); -} - - -void Buffer::redraw() -{ -#warning repaint needed here, or do you mean update() ? - users->repaint(); - users->fitCursor(); -} - - void Buffer::changeLanguage(Language const * from, Language const * to) { lyxerr << "Changing Language!" << endl; @@ -2222,19 +2178,6 @@ ParConstIterator Buffer::par_iterator_en } - -void Buffer::addUser(BufferView * u) -{ - users = u; -} - - -void Buffer::delUser(BufferView *) -{ - users = 0; -} - - Language const * Buffer::getLanguage() const { return params.language; @@ -2325,12 +2268,6 @@ string const & Buffer::filePath() const bool Buffer::isReadonly() const { return read_only; -} - - -BufferView * Buffer::getUser() const -{ - return users; } Index: buffer.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v retrieving revision 1.147 diff -u -p -u -r1.147 buffer.h --- buffer.h 7 Jul 2003 08:36:57 -0000 1.147 +++ buffer.h 9 Jul 2003 10:01:11 -0000 @@ -25,9 +25,9 @@ #include "errorlist.h" #include <boost/scoped_ptr.hpp> +#include <boost/signals/signal0.hpp> #include <boost/signals/signal1.hpp> -class BufferView; class LyXRC; class TeXErrors; class LaTeXFeatures; @@ -69,29 +69,6 @@ public: /// Maybe we know the function already by number... bool dispatch(int ac, string const & argument, bool * result = 0); - /// - void resizeInsets(BufferView *); - - /// Update window titles of all users. - void updateTitles() const; - - /// Reset autosave timers for all users. - void resetAutosaveTimers() const; - - /** Adds the BufferView to the users list. - Later this func will insert the \c BufferView into a real list, - not just setting a pointer. - */ - void addUser(BufferView * u); - - /** Removes the #BufferView# from the users list. - Since we only can have one at the moment, we just reset it. - */ - void delUser(BufferView *); - - /// - void redraw(); - /// Load the autosaved file. void loadAutoSaveFile(); @@ -132,8 +109,15 @@ public: boost::signal1<void, ErrorItem> error; /// This signal is emitted when some message shows up. boost::signal1<void, string> message; - /// This signal is emmtted when the buffer busy status change. + /// This signal is emitted when the buffer busy status change. boost::signal1<void, bool> busy; + /// This signal is emitted when the buffer readonly status change. + boost::signal1<void, bool> readonly; + /// Update window titles of all users. + boost::signal0<void> updateTitles; + /// Reset autosave timers for all users. + boost::signal0<void> resetAutosaveTimers; + /** Save file. Takes care of auto-save files and backup file if requested. @@ -264,10 +248,6 @@ public: /// void getLabelList(std::vector<string> &) const; - /** This will clearly have to change later. Later we can have more - than one user per buffer. */ - BufferView * getUser() const; - /// void changeLanguage(Language const * from, Language const * to); @@ -335,14 +315,6 @@ private: /// Format number of buffer int file_format; - /** A list of views using this buffer. - Why not keep a list of the BufferViews that use this buffer? - - At least then we don't have to do a lot of magic like: - #buffer->lyx_gui->bufferview->updateLayoutChoice#. Just ask each - of the buffers in the list of users to do a #updateLayoutChoice#. - */ - BufferView * users; /// boost::scoped_ptr<Messages> messages_; public: Index: bufferview_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferview_funcs.C,v retrieving revision 1.84 diff -u -p -u -r1.84 bufferview_funcs.C --- bufferview_funcs.C 30 Jun 2003 23:55:51 -0000 1.84 +++ bufferview_funcs.C 9 Jul 2003 10:01:12 -0000 @@ -35,6 +35,7 @@ #include "Lsstream.h" #include "insets/updatableinset.h" +#include <boost/bind.hpp> using namespace lyx::support; @@ -47,6 +48,16 @@ bool toggleall(false); } namespace bv_funcs { + + +void resizeInsets(BufferView * bv) +{ + ParagraphList paragraphs = bv->buffer()->paragraphs; + /// then remove all LyXText in text-insets + for_each(paragraphs.begin(), paragraphs.end(), + boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv)); +} + // Set data using font and toggle // If successful, returns true Index: bufferview_funcs.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferview_funcs.h,v retrieving revision 1.18 diff -u -p -u -r1.18 bufferview_funcs.h --- bufferview_funcs.h 3 Apr 2003 01:26:00 -0000 1.18 +++ bufferview_funcs.h 9 Jul 2003 10:01:12 -0000 @@ -22,6 +22,8 @@ class LyXText; namespace bv_funcs { +/// + void resizeInsets(BufferView * bv); /** Set \param data using \param font and \param toggle. * If successful, returns true. */ Index: lyxfunc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v retrieving revision 1.460 diff -u -p -u -r1.460 lyxfunc.C --- lyxfunc.C 7 Jul 2003 08:36:58 -0000 1.460 +++ lyxfunc.C 9 Jul 2003 10:01:15 -0000 @@ -799,7 +799,27 @@ void LyXFunc::dispatch(int ac, bool verb dispatch(lyxaction.retrieveActionArg(ac), verbose); } +namespace { + bool ensureBufferClean(BufferView * bv) { + Buffer & buf = *bv->buffer(); + if (buf.isClean()) + return true; + + string const file = MakeDisplayPath(buf.fileName(), 30); + string text = bformat(_("The document %1$s has unsaved " + "changes.\n\nDo you want to save " + "the document?"), file); + int const ret = Alert::prompt(_("Save changed document?"), + text, 0, 1, _("&Save"), + _("&Cancel")); + + if (ret == 0) + bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE)); + + return buf.isClean(); + } +} //namespace anon void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) { @@ -1211,36 +1231,51 @@ void LyXFunc::dispatch(FuncRequest const // --- version control ------------------------------- case LFUN_VC_REGISTER: { - if (!owner->buffer()->lyxvc.inUse()) + ensureBufferClean(view()); + if (!owner->buffer()->lyxvc.inUse()) { owner->buffer()->lyxvc.registrer(); + view()->reload(); + } } break; case LFUN_VC_CHECKIN: { + ensureBufferClean(view()); + // Maybe the save fails, or we answered "no". In both cases, + // the document will be dirty, and we abort. + if (!owner->buffer()->isClean()) + break; if (owner->buffer()->lyxvc.inUse() - && !owner->buffer()->isReadonly()) + && !owner->buffer()->isReadonly()) { owner->buffer()->lyxvc.checkIn(); + view()->reload(); + } } break; case LFUN_VC_CHECKOUT: { + ensureBufferClean(view()); if (owner->buffer()->lyxvc.inUse() - && owner->buffer()->isReadonly()) + && owner->buffer()->isReadonly()) { owner->buffer()->lyxvc.checkOut(); + view()->reload(); + } } break; case LFUN_VC_REVERT: { owner->buffer()->lyxvc.revert(); + view()->reload(); } break; case LFUN_VC_UNDO: { owner->buffer()->lyxvc.undoLast(); + view()->reload(); } break; Index: lyxvc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxvc.C,v retrieving revision 1.48 diff -u -p -u -r1.48 lyxvc.C --- lyxvc.C 30 Jun 2003 23:55:56 -0000 1.48 +++ lyxvc.C 9 Jul 2003 10:01:15 -0000 @@ -4,7 +4,6 @@ #include "vc-backend.h" #include "debug.h" #include "buffer.h" -#include "BufferView.h" #include "gettext.h" #include "funcrequest.h" @@ -22,10 +21,6 @@ using std::endl; using std::pair; -/* WARNING: Several of the vcs-> methods end up - * deleting this object via BufferView::reload() ! - */ - LyXVC::LyXVC() { vcs = 0; @@ -76,25 +71,6 @@ void LyXVC::buffer(Buffer * buf) } -bool LyXVC::ensureClean() -{ - if (owner_->isClean()) - return true; - - string const file = MakeDisplayPath(owner_->fileName(), 30); - string text = bformat(_("The document %1$s has unsaved changes.\n\n" - "Do you want to save the document?"), file); - int const ret = Alert::prompt(_("Save changed document?"), - text, 0, 1, _("&Save"), _("&Cancel")); - - if (ret == 0) { - vcs->owner()->getUser()->owner()->dispatch(FuncRequest(LFUN_MENUWRITE)); - } - - return owner_->isClean(); -} - - void LyXVC::registrer() { string const filename = owner_->fileName(); @@ -102,8 +78,8 @@ void LyXVC::registrer() // there must be a file to save if (!IsFileReadable(filename)) { Alert::error(_("Document not saved"), - _("You must save the document " - "before it can be registered.")); + _("You must save the document " + "before it can be registered.")); return; } @@ -129,11 +105,6 @@ void LyXVC::registrer() vcs->owner(owner_); } - // Maybe the save fails, or we answered "no". In both cases, - // the document will be dirty, and we abort. - if (!ensureClean()) - return; - lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl; pair<bool, string> tmp = Alert::askForText(_("LyX VC: Initial description"), @@ -150,16 +121,6 @@ void LyXVC::registrer() void LyXVC::checkIn() { - // If the document is changed, we might want to save it - if (!vcs->owner()->isClean()) { - vcs->owner()->getUser()->owner() - ->dispatch(FuncRequest(LFUN_MENUWRITE)); - } - - // Maybe the save fails, or we answered "no". In both cases, - // the document will be dirty, and we abort. - if (!vcs->owner()->isClean()) - return; lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl; pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message")); @@ -177,8 +138,6 @@ void LyXVC::checkIn() void LyXVC::checkOut() { lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl; - if (!ensureClean()) - return; vcs->checkOut(); } Index: lyxvc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxvc.h,v retrieving revision 1.12 diff -u -p -u -r1.12 lyxvc.h --- lyxvc.h 29 Mar 2003 07:09:12 -0000 1.12 +++ lyxvc.h 9 Jul 2003 10:01:15 -0000 @@ -86,9 +86,6 @@ public: string const & locker() const; private: - /// returns false if still not clean - bool ensureClean(); - /// Buffer * owner_; Index: vc-backend.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/vc-backend.C,v retrieving revision 1.40 diff -u -p -u -r1.40 vc-backend.C --- vc-backend.C 30 Jun 2003 23:56:09 -0000 1.40 +++ vc-backend.C 9 Jul 2003 10:01:16 -0000 @@ -3,7 +3,6 @@ #include "vc-backend.h" #include "debug.h" #include "buffer.h" -#include "BufferView.h" #include "frontends/LyXView.h" #include "funcrequest.h" @@ -47,15 +46,6 @@ int VCS::doVCCommand(string const & cmd, } -void VCS::reload() -{ - owner_->getUser()->reload(); - /* Watch out ! We have deleted ourselves here - * via the ->reload() ! - */ -} - - RCS::RCS(string const & m) { master_ = m; @@ -172,7 +162,6 @@ void RCS::registrer(string const & msg) cmd += OnlyFilename(owner_->fileName()); cmd += '"'; doVCCommand(cmd, owner_->filePath()); - reload(); } @@ -181,7 +170,6 @@ void RCS::checkIn(string const & msg) doVCCommand("ci -q -u -m\"" + msg + "\" \"" + OnlyFilename(owner_->fileName()) + '"', owner_->filePath()); - reload(); } @@ -191,7 +179,6 @@ void RCS::checkOut() doVCCommand("co -q -l \"" + OnlyFilename(owner_->fileName()) + '"', owner_->filePath()); - reload(); } @@ -202,7 +189,6 @@ void RCS::revert() owner_->filePath()); // We ignore changes and just reload! owner_->markClean(); - reload(); } @@ -311,7 +297,6 @@ void CVS::registrer(string const & msg) doVCCommand("cvs -q add -m \"" + msg + "\" \"" + OnlyFilename(owner_->fileName()) + '"', owner_->filePath()); - reload(); } @@ -320,7 +305,6 @@ void CVS::checkIn(string const & msg) doVCCommand("cvs -q commit -m \"" + msg + "\" \"" + OnlyFilename(owner_->fileName()) + '"', owner_->filePath()); - reload(); } @@ -340,7 +324,6 @@ void CVS::revert() doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + '"', owner_->filePath()); owner_->markClean(); - reload(); } Index: vc-backend.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/vc-backend.h,v retrieving revision 1.12 diff -u -p -u -r1.12 vc-backend.h --- vc-backend.h 8 Mar 2003 05:37:54 -0000 1.12 +++ vc-backend.h 9 Jul 2003 10:01:16 -0000 @@ -59,9 +59,6 @@ protected: /// parse information from the version file virtual void scanMaster() = 0; - /// reload the document - void reload(); - /** * doVCCommand - call out to the version control utility * @param cmd the command to execute Index: insets/insettabular.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v retrieving revision 1.293 diff -u -p -u -r1.293 insettabular.C --- insets/insettabular.C 4 Jul 2003 08:23:21 -0000 1.293 +++ insets/insettabular.C 9 Jul 2003 10:01:22 -0000 @@ -206,9 +206,16 @@ InsetBase * InsetTabular::clone() const } +Buffer const * InsetTabular::buffer() const +{ + return buffer_; +} + + BufferView * InsetTabular::view() const { - return buffer_->getUser(); + Assert(false); + return 0; } @@ -2903,9 +2910,7 @@ int InsetTabularMailer::string2params(st if (!lex.isOK()) return -1; - // FIXME: even current_view would be better than this. - BufferView * const bv = inset.view(); - Buffer const * const buffer = bv ? bv->buffer() : 0; + Buffer const * const buffer = inset.buffer(); if (buffer) inset.read(buffer, lex); @@ -2917,9 +2922,7 @@ int InsetTabularMailer::string2params(st string const InsetTabularMailer::params2string(InsetTabular const & inset) { - // FIXME: even current_view would be better than this. - BufferView * const bv = inset.view(); - Buffer const * const buffer = bv ? bv->buffer() : 0; + Buffer const * const buffer = inset.buffer(); if (!buffer) return string(); Index: insets/insettabular.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.h,v retrieving revision 1.127 diff -u -p -u -r1.127 insettabular.h --- insets/insettabular.h 4 Jul 2003 08:23:22 -0000 1.127 +++ insets/insettabular.h 9 Jul 2003 10:01:22 -0000 @@ -225,6 +225,8 @@ public: /// virtual BufferView * view() const; + /// + Buffer const * buffer() const; /// set the owning buffer void buffer(Buffer * b);