From a4032074c902a254bc46abd6d54433f5c9b050a2 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 14 Jul 2006 21:47:48 +0000 Subject: [PATCH] This commit continues the drastic diet operated on BufferView. It removes all boost signal connections from BufferView::pimpl and put them in LyXView. LyXView already inherits from boost::signals::trackable so this is not a big deal. If you look closely at the signal connections, it all makes sense IMO. With this change, the only difference between BufferView.h and BufferView_pimpl.h is "cursor.h" so I think it is time to merge the two classes at last. BufferView: * showErrorList(), getErrorList(): transfered to LyXView. BufferView::pimpl * addError(), showReadonly(), connectBuffer(), disconnectBuffer(): transfered to LyXView. CutAndPaste.C: adapted to API changes frontends/controllers/ControlErrorList.C: ditto lyxfunc.C: ditto git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14458 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 17 ---- src/BufferView.h | 4 - src/BufferView_pimpl.C | 70 +-------------- src/BufferView_pimpl.h | 29 +----- src/CutAndPaste.C | 2 +- src/frontends/LyXView.C | 94 +++++++++++++++++++- src/frontends/LyXView.h | 36 ++++++++ src/frontends/controllers/ControlErrorList.C | 3 +- src/lyxfunc.C | 12 +-- 9 files changed, 141 insertions(+), 126 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 86e1729681..510e86d3b1 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -253,23 +253,6 @@ void BufferView::scroll(int lines) } -void BufferView::showErrorList(string const & action) const -{ - if (getErrorList().size()) { - string const title = bformat(_("%1$s Errors (%2$s)"), - action, buffer()->fileName()); - owner()->getDialogs().show("errorlist", title); - pimpl_->errorlist_.clear(); - } -} - - -ErrorList const & BufferView::getErrorList() const -{ - return pimpl_->errorlist_; -} - - void BufferView::setCursorFromRow(int row) { int tmpid = -1; diff --git a/src/BufferView.h b/src/BufferView.h index c8f833496b..48ca713fde 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -155,10 +155,6 @@ public: /// move cursor to the named label void gotoLabel(std::string const & label); - /// get the stored error list - ErrorList const & getErrorList() const; - /// show the error list to the user - void showErrorList(std::string const &) const; /// set the cursor based on the given TeX source row void setCursorFromRow(int row); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 43c9c918f2..a5f15793be 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -144,66 +144,6 @@ BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner) } -void BufferView::Pimpl::addError(ErrorItem const & ei) -{ - errorlist_.push_back(ei); -} - - -void BufferView::Pimpl::showReadonly(bool) -{ - owner_->updateWindowTitle(); - owner_->getDialogs().updateBufferDependent(false); -} - - -void BufferView::Pimpl::connectBuffer(Buffer & buf) -{ - if (errorConnection_.connected()) - disconnectBuffer(); - - 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_)); - - readonlyConnection_ = - buf.readonly.connect( - boost::bind(&BufferView::Pimpl::showReadonly, this, _1)); - - closingConnection_ = - buf.closing.connect( - boost::bind(&LyXView::setBuffer, owner_, (Buffer *)0)); -} - - -void BufferView::Pimpl::disconnectBuffer() -{ - errorConnection_.disconnect(); - messageConnection_.disconnect(); - busyConnection_.disconnect(); - titleConnection_.disconnect(); - timerConnection_.disconnect(); - readonlyConnection_.disconnect(); - closingConnection_.disconnect(); -} - - bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) { // Get absolute path of file and add ".lyx" @@ -238,7 +178,6 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) if (found) { b = bufferlist.newBuffer(s); - connectBuffer(*b); if (!::loadLyXFile(b, s)) { bufferlist.release(b); return false; @@ -257,7 +196,7 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) } setBuffer(b); - bv_->showErrorList(_("Parse")); + owner_->showErrorList(_("Parse")); // scroll to the position when the file was last closed if (lyxrc.use_lastfilepos) { @@ -312,7 +251,6 @@ void BufferView::Pimpl::setBuffer(Buffer * b) << "[ b = " << b << "]" << endl; if (buffer_) { - disconnectBuffer(); // Save the actual cursor position and anchor inside the // buffer so that it can be restored in case we rechange // to this buffer later on. @@ -349,7 +287,6 @@ void BufferView::Pimpl::setBuffer(Buffer * b) if (buffer_) { lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION << "Buffer addr: " << buffer_ << endl; - connectBuffer(*buffer_); cursor_.push(buffer_->inset()); cursor_.resetAnchor(); buffer_->text().init(bv_); @@ -801,7 +738,6 @@ void BufferView::Pimpl::center() } - void BufferView::Pimpl::menuInsertLyXFile(string const & filenm) { BOOST_ASSERT(cursor_.inTexted()); @@ -851,7 +787,7 @@ void BufferView::Pimpl::menuInsertLyXFile(string const & filenm) string res; Buffer buf("", false); - buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1)); + buf.error.connect(boost::bind(&LyXView::addError, owner_, _1)); if (::loadLyXFile(&buf, makeAbsPath(filename))) { lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(), buf.params().textclass); @@ -860,7 +796,7 @@ void BufferView::Pimpl::menuInsertLyXFile(string const & filenm) res = _("Could not insert document %1$s"); owner_->message(bformat(res, disp_fn)); - bv_->showErrorList(_("Document insertion")); + owner_->showErrorList(_("Document insertion")); resizeCurrentBuffer(); } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 5d645cf029..f90d34b382 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -20,15 +20,12 @@ #include "BufferView.h" #include "cursor.h" -#include "errorlist.h" #include "metricsinfo.h" #include "frontends/LyXKeySym.h" #include "support/types.h" -#include - class Change; class LyXView; @@ -43,7 +40,7 @@ class Gui; /// -class BufferView::Pimpl : public boost::signals::trackable { +class BufferView::Pimpl { public: /// Pimpl(BufferView & bv, LyXView * owner); @@ -127,32 +124,8 @@ private: /// ScrollbarParameters scrollbarParameters_; - /// An error list (replaces the error insets) - ErrorList errorlist_; - /// add an error to the list - void addError(ErrorItem const &); - /// buffer errors signal connection - boost::signals::connection errorConnection_; - /// buffer messages signal connection - boost::signals::connection messageConnection_; - /// buffer busy status signal connection - boost::signals::connection busyConnection_; - /// buffer title changed signal connection - boost::signals::connection titleConnection_; - /// buffer reset timers signal connection - boost::signals::connection timerConnection_; - /// buffer readonly status changed signal connection - boost::signals::connection readonlyConnection_; - /// buffer closing signal connection - boost::signals::connection closingConnection_; - /// connect to signals in the given buffer - void connectBuffer(Buffer & buf); - /// disconnect from signals in the given buffer - void disconnectBuffer(); /// track changes for the document void trackChanges(); - /// notify readonly status - void showReadonly(bool); /// ViewMetricsInfo metrics_info_; diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index d88785bb14..a675c34801 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -649,7 +649,7 @@ void pasteSelection(LCursor & cur, size_t sel_index) pasteParagraphList(cur, theCuts[sel_index].first, theCuts[sel_index].second); - cur.bv().showErrorList(_("Paste")); + cur.bv().owner()->showErrorList(_("Paste")); cur.setSelection(); } diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 54dad90f3e..4fa2308d32 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -37,6 +37,7 @@ #include "controllers/ControlCommandBuffer.h" +#include "support/lstrings.h" #include "support/filetools.h" // OnlyFilename() #include @@ -51,6 +52,7 @@ using lyx::frontend::Gui; using lyx::frontend::WorkArea; +using lyx::support::bformat; using lyx::support::makeDisplayPath; using lyx::support::onlyFilename; @@ -128,30 +130,118 @@ Buffer * LyXView::buffer() const void LyXView::setBuffer(Buffer * b) { + if (work_area_->bufferView().buffer()) + disconnectBuffer(); + work_area_->bufferView().setBuffer(b); updateMenubar(); updateToolbars(); updateLayoutChoice(); updateWindowTitle(); - if (b) + if (b) { + connectBuffer(*b); setLayout(work_area_->bufferView().firstLayout()); + } redrawWorkArea(); } bool LyXView::loadLyXFile(string const & filename, bool tolastfiles) { + if (work_area_->bufferView().buffer()) + disconnectBuffer(); + bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles); updateMenubar(); updateToolbars(); updateLayoutChoice(); updateWindowTitle(); - if (loaded) + if (loaded) { + connectBuffer(*work_area_->bufferView().buffer()); setLayout(work_area_->bufferView().firstLayout()); + } redrawWorkArea(); return loaded; } + +void LyXView::connectBuffer(Buffer & buf) +{ + if (errorConnection_.connected()) + disconnectBuffer(); + + errorConnection_ = + buf.error.connect( + boost::bind(&LyXView::addError, this, _1)); + + messageConnection_ = + buf.message.connect( + boost::bind(&LyXView::message, this, _1)); + + busyConnection_ = + buf.busy.connect( + boost::bind(&LyXView::busy, this, _1)); + + titleConnection_ = + buf.updateTitles.connect( + boost::bind(&LyXView::updateWindowTitle, this)); + + timerConnection_ = + buf.resetAutosaveTimers.connect( + boost::bind(&LyXView::resetAutosaveTimer, this)); + + readonlyConnection_ = + buf.readonly.connect( + boost::bind(&LyXView::showReadonly, this, _1)); + + closingConnection_ = + buf.closing.connect( + boost::bind(&LyXView::setBuffer, this, (Buffer *)0)); +} + + +void LyXView::disconnectBuffer() +{ + errorConnection_.disconnect(); + messageConnection_.disconnect(); + busyConnection_.disconnect(); + titleConnection_.disconnect(); + timerConnection_.disconnect(); + readonlyConnection_.disconnect(); + closingConnection_.disconnect(); +} + + +void LyXView::addError(ErrorItem const & ei) +{ + errorlist_.push_back(ei); +} + + +void LyXView::showErrorList(string const & action) +{ + if (errorlist_.size()) { + string const title = bformat(_("%1$s Errors (%2$s)"), + action, buffer()->fileName()); + getDialogs().show("errorlist", title); + errorlist_.clear(); + } +} + + +ErrorList const & LyXView::getErrorList() const +{ + return errorlist_; +} + + +void LyXView::showReadonly(bool) +{ + updateWindowTitle(); + getDialogs().updateBufferDependent(false); +} + + BufferView * LyXView::view() const { return &work_area_->bufferView(); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 7c9a2a98e2..df0440870f 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -13,6 +13,8 @@ #ifndef LYXVIEW_H #define LYXVIEW_H +#include "errorlist.h" + #include #include #include @@ -165,6 +167,16 @@ public: /// This is needed for the qt3 and gtk frontend. lyx::frontend::WorkArea * workArea(); + /// get the stored error list + ErrorList const & getErrorList() const; + /// show the error list to the user + void showErrorList(std::string const &); + /// add an error to the list + /** FIXME: public method until the signal connection in + * BufferView::menuInsertLyXFile() is removed. + */ + void addError(ErrorItem const &); + protected: /// current work area (screen view of a BufferView). /** @@ -198,6 +210,30 @@ private: /// dialogs for this view boost::scoped_ptr dialogs_; + /// An error list (replaces the error insets) + ErrorList errorlist_; + + /// buffer errors signal connection + boost::signals::connection errorConnection_; + /// buffer messages signal connection + boost::signals::connection messageConnection_; + /// buffer busy status signal connection + boost::signals::connection busyConnection_; + /// buffer title changed signal connection + boost::signals::connection titleConnection_; + /// buffer reset timers signal connection + boost::signals::connection timerConnection_; + /// buffer readonly status changed signal connection + boost::signals::connection readonlyConnection_; + /// buffer closing signal connection + boost::signals::connection closingConnection_; + /// connect to signals in the given buffer + void connectBuffer(Buffer & buf); + /// disconnect from signals in the given buffer + void disconnectBuffer(); + /// notify readonly status + void showReadonly(bool); + protected: /// view's command buffer controller // this has to be declared _after_ lyxfunc_ as its initialization depends diff --git a/src/frontends/controllers/ControlErrorList.C b/src/frontends/controllers/ControlErrorList.C index 175955ae25..d4a39d6a62 100644 --- a/src/frontends/controllers/ControlErrorList.C +++ b/src/frontends/controllers/ControlErrorList.C @@ -11,6 +11,7 @@ #include #include "ControlErrorList.h" +#include "frontends/LyXView.h" #include "buffer.h" #include "BufferView.h" #include "debug.h" @@ -41,7 +42,7 @@ ErrorList const & ControlErrorList::errorList() const bool ControlErrorList::initialiseParams(string const & name) { - errorlist_ = kernel().bufferview()->getErrorList(); + errorlist_ = kernel().lyxview().getErrorList(); name_ = name; return true; } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 59f6c47fe9..6cadfff147 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -837,22 +837,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_BUFFER_UPDATE: Exporter::Export(owner->buffer(), argument, true); - view()->showErrorList(bufferFormat(*owner->buffer())); + owner->showErrorList(bufferFormat(*owner->buffer())); break; case LFUN_BUFFER_VIEW: Exporter::preview(owner->buffer(), argument); - view()->showErrorList(bufferFormat(*owner->buffer())); + owner->showErrorList(bufferFormat(*owner->buffer())); break; case LFUN_BUILD_PROGRAM: Exporter::Export(owner->buffer(), "program", true); - view()->showErrorList(_("Build")); + owner->showErrorList(_("Build")); break; case LFUN_BUFFER_CHKTEX: owner->buffer()->runChktex(); - view()->showErrorList(_("ChkTeX")); + owner->showErrorList(_("ChkTeX")); break; case LFUN_BUFFER_EXPORT: @@ -860,7 +860,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) owner->getDialogs().show("sendto"); else { Exporter::Export(owner->buffer(), argument, false); - view()->showErrorList(bufferFormat(*owner->buffer())); + owner->showErrorList(bufferFormat(*owner->buffer())); } break; @@ -1562,7 +1562,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) view()->setCursor(backcur.asDocIterator(&(buffer->inset()))); bufferErrors(*buffer, el); - view()->showErrorList(_("Class switch")); + owner->showErrorList(_("Class switch")); updateLabels(*buffer); updateforce = true; break; -- 2.39.2