diff --git a/src/BufferView.h b/src/BufferView.h index 48ca713fde..a30c5b8c65 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -28,7 +28,6 @@ class Buffer; class Change; class DocIterator; -class ErrorList; class FuncRequest; class FuncStatus; class Language; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a5f15793be..2c4e1e7d42 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -787,7 +787,8 @@ void BufferView::Pimpl::menuInsertLyXFile(string const & filenm) string res; Buffer buf("", false); - buf.error.connect(boost::bind(&LyXView::addError, owner_, _1)); + // FIXME: is there a need for something like that? + //buf.errors.connect(boost::bind(&LyXView::showErrorList, owner_, _1)); if (::loadLyXFile(&buf, makeAbsPath(filename))) { lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(), buf.params().textclass); diff --git a/src/buffer.C b/src/buffer.C index d5e60413b3..60a6af1892 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -22,7 +22,6 @@ #include "Chktex.h" #include "debug.h" #include "encoding.h" -#include "errorlist.h" #include "exporter.h" #include "format.h" #include "funcrequest.h" @@ -446,15 +445,17 @@ int Buffer::readHeader(LyXLex & lex) "%1$s %2$s\n"), token, lex.getString()); - error(ErrorItem(_("Document header error"), s, - -1, 0, 0)); + errorList_.push_back(ErrorItem(_("Document header error"), + s, -1, 0, 0)); } } } if (begin_header_line) { string const s = _("\\begin_header is missing"); - error(ErrorItem(_("Document header error"), s, -1, 0, 0)); + errorList_.push_back(ErrorItem(_("Document header error"), + s, -1, 0, 0)); } + return unknown_tokens; } @@ -464,11 +465,14 @@ int Buffer::readHeader(LyXLex & lex) // Returns false if "\end_document" is not read (Asger) bool Buffer::readDocument(LyXLex & lex) { + errorList_.clear(); + lex.next(); string const token = lex.getString(); if (token != "\\begin_document") { string const s = _("\\begin_document is missing"); - error(ErrorItem(_("Document header error"), s, -1, 0, 0)); + errorList_.push_back(ErrorItem(_("Document header error"), + s, -1, 0, 0)); } // we are reading in a brand new document @@ -488,6 +492,17 @@ bool Buffer::readDocument(LyXLex & lex) text().paragraphs().end(), bind(&Paragraph::setInsetOwner, _1, &inset())); updateBibfilesCache(); + + // FIXME: the signal emission below is not needed for now because + // there is a manual call to "LyXView::showErrorList(_("Parse"))" + // in BufferView::pimpl::loadLyXFile() + // Eventually, all manual call to "LyXView::showErrorList()" should + // be replace with this signal emission. + // + // Send the "errors" signal in case of parsing errors + //if (!errorList_.empty()) + // errors(_("Parse")); + return res; } @@ -1657,3 +1672,20 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type docbookParagraphs(paragraphs(), *this, os, runparams); } + +ErrorList const & Buffer::getErrorList() const +{ + return errorList_; +} + + +void Buffer::setErrorList(ErrorList const & errorList) const +{ + errorList_ = errorList; +} + + +void Buffer::addError(ErrorItem const & errorItem) const +{ + errorList_.push_back(errorItem); +} diff --git a/src/buffer.h b/src/buffer.h index a3cbc3f61f..60bcd28a42 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -12,6 +12,7 @@ #ifndef BUFFER_H #define BUFFER_H +#include "errorlist.h" #include "InsetList.h" #include "dociterator.h" @@ -112,8 +113,8 @@ public: /// do we have a paragraph with this id? bool hasParWithID(int id) const; - /// This signal is emitted when a parsing error shows up. - boost::signal error; + /// This signal is emitted when some parsing error shows up. + boost::signal errors; /// This signal is emitted when some message shows up. boost::signal message; /// This signal is emitted when the buffer busy status change. @@ -347,6 +348,21 @@ public: /// get source code (latex/docbook/linuxdoc) for some paragraphs void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end); + /// errorList_ accessor. + ErrorList const & getErrorList() const; + /// replace the internal errorList_ + /** FIXME: This method is const for now because the ErrorList GUI + * showing mechanism is used by other classes in order to show their + * own processing errors (ex: Converter.C). + */ + void setErrorList(ErrorList const &) const; + /// add an error to the errorList_ + /** FIXME: This method is const for now because the ErrorList GUI + * showing mechanism is used by other classes in order to show their + * own processing errors (ex: Converter.C). + */ + void addError(ErrorItem const &) const; + private: /** Inserts a file into a document \return \c false if method fails. @@ -368,6 +384,13 @@ private: /// A cache for the bibfiles (including bibfiles of loaded child /// documents), needed for appropriate update of natbib labels. std::vector bibfilesCache_; + + /// An error list (replaces the error insets) + /** FIXME: This member is mutable for now because the ErrorList GUI + * showing mechanism is used by other classes in order to show their + * own processing errors (ex: Converter.C). + */ + mutable ErrorList errorList_; }; #endif diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 5c545cbcdd..0d1cb5cddf 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -230,15 +230,15 @@ void bufferErrors(Buffer const & buf, TeXErrors const & terr) pos_end); } while (found && id_start == id_end && pos_start == pos_end); - buf.error(ErrorItem(cit->error_desc, cit->error_text, - id_start, pos_start, pos_end)); + buf.addError(ErrorItem(cit->error_desc, + cit->error_text, id_start, pos_start, pos_end)); } } void bufferErrors(Buffer const & buf, ErrorList const & el) { - for_each(el.begin(), el.end(), bind(ref(buf.error), _1)); + buf.setErrorList(el); } diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 4fa2308d32..b7de9834c6 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -167,12 +167,17 @@ bool LyXView::loadLyXFile(string const & filename, bool tolastfiles) void LyXView::connectBuffer(Buffer & buf) { - if (errorConnection_.connected()) + if (errorsConnection_.connected()) disconnectBuffer(); - errorConnection_ = - buf.error.connect( - boost::bind(&LyXView::addError, this, _1)); + // FIXME: (Abdel 15/07/2006) The connection below is not used for + // now. + // Nevertheless, it would be a very good idea to replace all manual + // calls of showErrorList to a call of the new modified + // "Buffer::errors" boost signal. + errorsConnection_ = + buf.errors.connect( + boost::bind(&LyXView::showErrorList, this, _1)); messageConnection_ = buf.message.connect( @@ -202,7 +207,6 @@ void LyXView::connectBuffer(Buffer & buf) void LyXView::disconnectBuffer() { - errorConnection_.disconnect(); messageConnection_.disconnect(); busyConnection_.disconnect(); titleConnection_.disconnect(); @@ -212,29 +216,17 @@ void LyXView::disconnectBuffer() } -void LyXView::addError(ErrorItem const & ei) -{ - errorlist_.push_back(ei); -} - - void LyXView::showErrorList(string const & action) { - if (errorlist_.size()) { + Buffer * b = work_area_->bufferView().buffer(); + if (!b->getErrorList().empty()) { 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(); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index df0440870f..104e0ed771 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -13,8 +13,6 @@ #ifndef LYXVIEW_H #define LYXVIEW_H -#include "errorlist.h" - #include #include #include @@ -167,15 +165,8 @@ 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). @@ -210,11 +201,8 @@ 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_; + boost::signals::connection errorsConnection_; /// buffer messages signal connection boost::signals::connection messageConnection_; /// buffer busy status signal connection diff --git a/src/frontends/controllers/ControlErrorList.C b/src/frontends/controllers/ControlErrorList.C index d4a39d6a62..d9e8c082ec 100644 --- a/src/frontends/controllers/ControlErrorList.C +++ b/src/frontends/controllers/ControlErrorList.C @@ -11,7 +11,6 @@ #include #include "ControlErrorList.h" -#include "frontends/LyXView.h" #include "buffer.h" #include "BufferView.h" #include "debug.h" @@ -42,7 +41,7 @@ ErrorList const & ControlErrorList::errorList() const bool ControlErrorList::initialiseParams(string const & name) { - errorlist_ = kernel().lyxview().getErrorList(); + errorlist_ = kernel().bufferview()->buffer()->getErrorList(); name_ = name; return true; } diff --git a/src/lyx_main.C b/src/lyx_main.C index fbe578706f..e5a31af35c 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -83,6 +83,7 @@ namespace fs = boost::filesystem; using std::endl; using std::string; using std::vector; +using std::mem_fun_ref; #ifndef CXX_GLOBAL_CSTD using std::exit; @@ -285,11 +286,21 @@ int LyX::exec2(int & argc, char * argv[]) last_loaded = newFile(*it, string(), true); } else { Buffer * buf = bufferlist.newBuffer(s, false); - buf->error.connect(boost::bind(&LyX::printError, this, _1)); if (loadLyXFile(buf, s)) last_loaded = buf; else bufferlist.release(buf); + + ErrorList const & el = buf->getErrorList(); + if (!el.empty()) { + // There should be a way to use the following but I (abdel) don't know + // how to make it compile on MSVC2005. + //for_each(el.begin(), el.end(), mem_fun_ref(&LyX::printError)); + for (ErrorList::const_iterator it = el.begin(); + it != el.end(); ++it) { + printError(*it); + } + } } } diff --git a/src/text.C b/src/text.C index da326879c5..88904b4d0d 100644 --- a/src/text.C +++ b/src/text.C @@ -180,7 +180,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, bool hasLayout = tclass.hasLayout(layoutname); if (!hasLayout) { - buf.error(ErrorItem(_("Unknown layout"), + buf.addError(ErrorItem(_("Unknown layout"), bformat(_("Layout '%1$s' does not exist in textclass '%2$s'\nTrying to use the default instead.\n"), layoutname, tclass.name()), par.id(), 0, par.size())); layoutname = tclass.defaultLayoutName(); @@ -212,7 +212,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, else { lex.eatLine(); string line = lex.getString(); - buf.error(ErrorItem(_("Unknown Inset"), line, + buf.addError(ErrorItem(_("Unknown Inset"), line, par.id(), 0, par.size())); } } else if (token == "\\family") { @@ -329,7 +329,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, lyx::time_type ct; is >> aid >> ct; if (aid >= bp.author_map.size()) { - buf.error(ErrorItem(_("Change tracking error"), + buf.addError(ErrorItem(_("Change tracking error"), bformat(_("Unknown author index for insertion: %1$d\n"), aid), par.id(), 0, par.size())); @@ -343,7 +343,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, lyx::time_type ct; is >> aid >> ct; if (aid >= bp.author_map.size()) { - buf.error(ErrorItem(_("Change tracking error"), + buf.addError(ErrorItem(_("Change tracking error"), bformat(_("Unknown author index for deletion: %1$d\n"), aid), par.id(), 0, par.size())); @@ -352,7 +352,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, change = Change(Change::DELETED, bp.author_map[aid], ct); } else { lex.eatLine(); - buf.error(ErrorItem(_("Unknown token"), + buf.addError(ErrorItem(_("Unknown token"), bformat(_("Unknown token: %1$s %2$s\n"), token, lex.getString()), par.id(), 0, par.size())); }