From c5a4f61f3377997a4b793481bd30a1a8e0627b86 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 13 Aug 2006 16:16:43 +0000 Subject: [PATCH] This commit creates a error_lists map member inside the Buffer class. I had no choice but to use string for the map key. This is because the only information that could be passed to the controller is a string. With this new architecture, persistent error lists are now possible. * Buffer - errorList_, addError(), : deleted - std::map errorLists_ : new member - errorList(std::string const & type): associated accessors * buffer_funcs.C - bufferErrors(Buffer const & buf, TeXErrors const & terr): now needs a third errorList argument - bufferErrors(Buffer const & buf, ErrorList const & el): deleted. * Converter - convert(): now needs an ErrorList argument instead of filling the Buffer errorList member directly. - runLaTeX(): ditto - scanLog(): ditto * CutAndPaste.C - pasteParagraphList(): ditto - pasteSelection(): ditto * lyxtext.h/text.C - readParagraph(): ditto - LyXText::read(): ditto * importer: - Importer::Import(): ditto * BufferView_pimpl.C - loadLyXFile(): send the Buffer::errors() signal instead of calling LyXView::showErrorList() directly. * exporter.C - Export(): send the Buffer::errors() signal instead of calling LyXView::showErrorList() directly in lyxfunc.C * ControlErrorList.C - initialiseParams(): translation operation transfered here from LyXView::showErrorList(). * LyXView.C - LoadLyXFile(): add a showErrorList("Parse") call. - showErrorList(): simplified due to code transferred to the ControlErrorList. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14652 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 13 +++-- src/CutAndPaste.C | 11 ++--- src/CutAndPaste.h | 4 +- src/buffer.C | 52 ++++++++++---------- src/buffer.h | 30 ++++------- src/buffer_funcs.C | 11 ++--- src/buffer_funcs.h | 7 ++- src/converter.C | 22 +++++---- src/converter.h | 10 ++-- src/exporter.C | 9 +++- src/frontends/LyXView.C | 18 +++---- src/frontends/controllers/ControlErrorList.C | 14 ++++-- src/importer.C | 4 +- src/importer.h | 3 +- src/insets/ExternalSupport.C | 5 +- src/insets/insetgraphics.C | 4 +- src/insets/insettext.C | 3 +- src/lyx_main.C | 24 ++++----- src/lyxfunc.C | 18 +++---- src/lyxtext.h | 3 +- src/text.C | 20 ++++---- src/text3.C | 10 ++-- 22 files changed, 150 insertions(+), 145 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index d1c7dd04a7..527dc2693b 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -28,6 +28,7 @@ #include "CutAndPaste.h" #include "debug.h" #include "dispatchresult.h" +#include "errorlist.h" #include "factory.h" #include "FloatList.h" #include "funcrequest.h" @@ -198,7 +199,8 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) } setBuffer(b); - owner_->showErrorList(_("Parse")); + // Send the "errors" signal in case of parsing errors + b->errors("Parse"); // scroll to the position when the file was last closed if (lyxrc.use_lastfilepos) { @@ -789,17 +791,18 @@ void BufferView::Pimpl::menuInsertLyXFile(string const & filenm) string res; Buffer buf("", false); - // FIXME: is there a need for something like that? - //buf.errors.connect(boost::bind(&LyXView::showErrorList, owner_, _1)); if (::loadLyXFile(&buf, makeAbsPath(filename))) { + ErrorList & el = buffer_->errorList("Parse"); + // Copy the inserted document error list into the current buffer one. + el = buf.errorList("Parse"); lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(), - buf.params().textclass); + buf.params().textclass, el); res = _("Document %1$s inserted."); } else res = _("Could not insert document %1$s"); owner_->message(bformat(res, disp_fn)); - owner_->showErrorList(_("Document insertion")); + buffer_->errors("Parse"); resizeCurrentBuffer(); } diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index a492d65196..566d63016f 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -612,7 +612,7 @@ std::string getSelection(Buffer const & buf, size_t sel_index) void pasteParagraphList(LCursor & cur, ParagraphList const & parlist, - textclass_type textclass) + textclass_type textclass, ErrorList & errorList) { if (cur.inTexted()) { LyXText * text = cur.text(); @@ -622,15 +622,13 @@ void pasteParagraphList(LCursor & cur, ParagraphList const & parlist, pit_type endpit; PitPosPair ppp; - ErrorList el; boost::tie(ppp, endpit) = pasteSelectionHelper(cur.buffer(), text->paragraphs(), cur.pit(), cur.pos(), parlist, textclass, - el); - bufferErrors(cur.buffer(), el); + errorList); updateLabels(cur.buffer()); cur.clearSelection(); text->setCursor(cur, ppp.first, ppp.second); @@ -641,15 +639,14 @@ void pasteParagraphList(LCursor & cur, ParagraphList const & parlist, } -void pasteSelection(LCursor & cur, size_t sel_index) +void pasteSelection(LCursor & cur, ErrorList & errorList, size_t sel_index) { // this does not make sense, if there is nothing to paste if (!checkPastePossible(sel_index)) return; pasteParagraphList(cur, theCuts[sel_index].first, - theCuts[sel_index].second); - cur.bv().owner()->showErrorList(_("Paste")); + theCuts[sel_index].second, errorList); cur.setSelection(); } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index c92bb3a24f..2b3a1c36be 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -56,11 +56,11 @@ void cutSelection(LCursor & cur, bool doclear = true, bool realcut = true); /// void copySelection(LCursor & cur); /// -void pasteSelection(LCursor & cur, size_t sel_index = 0); +void pasteSelection(LCursor & cur, ErrorList &, size_t sel_index = 0); /// void pasteParagraphList(LCursor & cur, ParagraphList const & parlist, - textclass_type textclass); + textclass_type textclass, ErrorList & errorList); /** Needed to switch between different classes. This works diff --git a/src/buffer.C b/src/buffer.C index 696b84a20f..367ef539a6 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -22,6 +22,7 @@ #include "Chktex.h" #include "debug.h" #include "encoding.h" +#include "errorlist.h" #include "exporter.h" #include "format.h" #include "funcrequest.h" @@ -416,6 +417,8 @@ int Buffer::readHeader(LyXLex & lex) params().headsep.erase(); params().footskip.erase(); + ErrorList & errorList = errorLists_["Parse"]; + while (lex.isOK()) { lex.next(); string const token = lex.getString(); @@ -445,14 +448,14 @@ int Buffer::readHeader(LyXLex & lex) "%1$s %2$s\n"), token, lex.getString()); - errorList_.push_back(ErrorItem(_("Document header error"), + errorList.push_back(ErrorItem(_("Document header error"), s, -1, 0, 0)); } } } if (begin_header_line) { string const s = _("\\begin_header is missing"); - errorList_.push_back(ErrorItem(_("Document header error"), + errorList.push_back(ErrorItem(_("Document header error"), s, -1, 0, 0)); } @@ -465,13 +468,14 @@ int Buffer::readHeader(LyXLex & lex) // Returns false if "\end_document" is not read (Asger) bool Buffer::readDocument(LyXLex & lex) { - errorList_.clear(); + ErrorList & errorList = errorLists_["Parse"]; + errorList.clear(); lex.next(); string const token = lex.getString(); if (token != "\\begin_document") { string const s = _("\\begin_document is missing"); - errorList_.push_back(ErrorItem(_("Document header error"), + errorList.push_back(ErrorItem(_("Document header error"), s, -1, 0, 0)); } @@ -487,22 +491,12 @@ bool Buffer::readDocument(LyXLex & lex) params().textclass = 0; } - bool const res = text().read(*this, lex); + bool const res = text().read(*this, lex, errorList); for_each(text().paragraphs().begin(), 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; } @@ -1175,12 +1169,14 @@ int Buffer::runChktex() Alert::error(_("chktex failure"), _("Could not run chktex successfully.")); } else if (res > 0) { - // Insert all errors as errors boxes - bufferErrors(*this, terr); + // Fill-in the error list with the TeX errors + bufferErrors(*this, terr, errorLists_["ChkTex"]); } busy(false); + errors("ChkTeX"); + return res; } @@ -1705,19 +1701,23 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type } -ErrorList const & Buffer::getErrorList() const +ErrorList const & Buffer::errorList(string const & type) const { - return errorList_; -} + std::map::const_iterator I = errorLists_.find(type); + if (I == errorLists_.end()) + return emptyErrorList_; - -void Buffer::setErrorList(ErrorList const & errorList) const -{ - errorList_ = errorList; + return I->second; } -void Buffer::addError(ErrorItem const & errorItem) const +ErrorList & Buffer::errorList(string const & type) { - errorList_.push_back(errorItem); + std::map::iterator I = errorLists_.find(type); + if (I == errorLists_.end()) { + errorLists_[type] = emptyErrorList_; + return errorLists_[type]; + } + + return I->second; } diff --git a/src/buffer.h b/src/buffer.h index 1ec123a005..429d0ac1cc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -357,20 +357,11 @@ public: /// including preamble void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source); - /// 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; + /// errorLists_ accessors. + //@{ + ErrorList const & errorList(std::string const & type) const; + ErrorList & errorList(std::string const & type); + //@} private: /** Inserts a file into a document @@ -394,12 +385,11 @@ private: /// 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_; + /// Container for all sort of Buffer dependant errors. + std::map errorLists_; + + /// Empty Error List + ErrorList const emptyErrorList_; }; #endif diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index a306de412e..ae975e1b5e 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -212,7 +212,8 @@ Buffer * newFile(string const & filename, string const & templatename, } -void bufferErrors(Buffer const & buf, TeXErrors const & terr) +void bufferErrors(Buffer const & buf, TeXErrors const & terr, + ErrorList & errorList) { TeXErrors::Errors::const_iterator cit = terr.begin(); TeXErrors::Errors::const_iterator end = terr.end(); @@ -231,18 +232,12 @@ void bufferErrors(Buffer const & buf, TeXErrors const & terr) pos_end); } while (found && id_start == id_end && pos_start == pos_end); - buf.addError(ErrorItem(cit->error_desc, + errorList.push_back(ErrorItem(cit->error_desc, cit->error_text, id_start, pos_start, pos_end)); } } -void bufferErrors(Buffer const & buf, ErrorList const & el) -{ - buf.setErrorList(el); -} - - string const bufferFormat(Buffer const & buffer) { if (buffer.isLinuxDoc()) diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index dba8ec93b5..599a2dbc71 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -37,10 +37,9 @@ Buffer * newFile(std::string const & filename, std::string const & templatename, ///return the format of the buffer on a string std::string const bufferFormat(Buffer const & buffer); -/// -void bufferErrors(Buffer const &, TeXErrors const &); -/// -void bufferErrors(Buffer const &, ErrorList const &); + +/// Fill in the ErrorList with the TeXErrors +void bufferErrors(Buffer const &, TeXErrors const &, ErrorList &); /// Count the number of words in the text between these two iterators int countWords(DocIterator const & from, DocIterator const & to); diff --git a/src/converter.C b/src/converter.C index 01da621ade..5dc703fed9 100644 --- a/src/converter.C +++ b/src/converter.C @@ -282,7 +282,7 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path) bool Converters::convert(Buffer const * buffer, string const & from_file, string const & to_file_base, string const & from_format, string const & to_format, - string & to_file, bool try_default) + string & to_file, ErrorList & errorList, bool try_default) { string const to_ext = formats.extension(to_format); to_file = changeExtension(to_file_base, to_ext); @@ -326,6 +326,8 @@ bool Converters::convert(Buffer const * buffer, runparams.flavor = getFlavor(edgepath); string path = onlyPath(from_file); Path p(path); + // empty the error list before any new conversion takes place. + errorList.clear(); bool run_latex = false; string from_base = changeExtension(from_file, ""); @@ -359,7 +361,7 @@ bool Converters::convert(Buffer const * buffer, run_latex = true; string const command = subst(conv.command, token_from, ""); lyxerr[Debug::FILES] << "Running " << command << endl; - if (!runLaTeX(*buffer, command, runparams)) + if (!runLaTeX(*buffer, command, runparams, errorList)) return false; } else { if (conv.need_aux && !run_latex @@ -367,7 +369,7 @@ bool Converters::convert(Buffer const * buffer, lyxerr[Debug::FILES] << "Running " << latex_command_ << " to update aux file"<< endl; - runLaTeX(*buffer, latex_command_, runparams); + runLaTeX(*buffer, latex_command_, runparams, errorList); } string const infile2 = (conv.original_dir) @@ -427,7 +429,7 @@ bool Converters::convert(Buffer const * buffer, " < " + quoteName(infile2 + ".out") + " > " + quoteName(logfile); one.startscript(Systemcall::Wait, command2); - if (!scanLog(*buffer, command, logfile)) + if (!scanLog(*buffer, command, logfile, errorList)) return false; } @@ -516,11 +518,11 @@ bool Converters::move(string const & fmt, bool Converters::convert(Buffer const * buffer, string const & from_file, string const & to_file_base, string const & from_format, string const & to_format, - bool try_default) + ErrorList & errorList, bool try_default) { string to_file; return convert(buffer, from_file, to_file_base, from_format, to_format, - to_file, try_default); + to_file, errorList, try_default); } @@ -537,7 +539,7 @@ bool Converters::formatIsUsed(string const & format) bool Converters::scanLog(Buffer const & buffer, string const & /*command*/, - string const & filename) + string const & filename, ErrorList & errorList) { OutputParams runparams; runparams.flavor = OutputParams::LATEX; @@ -546,7 +548,7 @@ bool Converters::scanLog(Buffer const & buffer, string const & /*command*/, int const result = latex.scanLogFile(terr); if (result & LaTeX::ERRORS) - bufferErrors(buffer, terr); + bufferErrors(buffer, terr, errorList); return true; } @@ -569,7 +571,7 @@ private: bool Converters::runLaTeX(Buffer const & buffer, string const & command, - OutputParams const & runparams) + OutputParams const & runparams, ErrorList & errorList) { buffer.busy(true); buffer.message(_("Running LaTeX...")); @@ -585,7 +587,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command, int const result = latex.run(terr); if (result & LaTeX::ERRORS) - bufferErrors(buffer, terr); + bufferErrors(buffer, terr, errorList); // check return value from latex.run(). if ((result & LaTeX::NO_LOGFILE)) { diff --git a/src/converter.h b/src/converter.h index d2bf173287..84841e82a8 100644 --- a/src/converter.h +++ b/src/converter.h @@ -20,6 +20,7 @@ class Buffer; +class ErrorList; class Format; class Formats; class OutputParams; @@ -107,12 +108,13 @@ public: bool convert(Buffer const * buffer, std::string const & from_file, std::string const & to_file_base, std::string const & from_format, std::string const & to_format, - std::string & to_file, bool try_default = false); + std::string & to_file, ErrorList & errorList, + bool try_default = false); /// bool convert(Buffer const * buffer, std::string const & from_file, std::string const & to_file_base, std::string const & from_format, std::string const & to_format, - bool try_default = false); + ErrorList & errorList, bool try_default = false); /// void update(Formats const & formats); /// @@ -134,10 +136,10 @@ private: intToFormat(std::vector const & input); /// bool scanLog(Buffer const & buffer, std::string const & command, - std::string const & filename); + std::string const & filename, ErrorList & errorList); /// bool runLaTeX(Buffer const & buffer, std::string const & command, - OutputParams const &); + OutputParams const &, ErrorList & errorList); /// ConverterList converterlist_; /// diff --git a/src/exporter.C b/src/exporter.C index a60fee117c..63d9aefaee 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -215,8 +215,13 @@ bool Exporter::Export(Buffer * buffer, string const & format, buffer->makeLaTeXFile(filename, buffer->filePath(), runparams); } - if (!converters.convert(buffer, filename, filename, - backend_format, format, result_file)) + string const error_type = (format == "program")? "Build" : bufferFormat(*buffer); + bool const success = converters.convert(buffer, filename, filename, + backend_format, format, result_file, + buffer->errorList(error_type)); + // Emit the signal to show the error list. + buffer->errors(error_type); + if (!success) return false; if (!put_in_tempdir) { diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index b7de9834c6..1bfeddc89e 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -25,6 +25,7 @@ #include "bufferview_funcs.h" #include "cursor.h" #include "debug.h" +#include "errorlist.h" #include "funcrequest.h" #include "gettext.h" #include "intl.h" @@ -152,6 +153,8 @@ bool LyXView::loadLyXFile(string const & filename, bool tolastfiles) disconnectBuffer(); bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles); + showErrorList("Parse"); + updateMenubar(); updateToolbars(); updateLayoutChoice(); @@ -170,11 +173,6 @@ void LyXView::connectBuffer(Buffer & buf) if (errorsConnection_.connected()) disconnectBuffer(); - // 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)); @@ -216,13 +214,11 @@ void LyXView::disconnectBuffer() } -void LyXView::showErrorList(string const & action) +void LyXView::showErrorList(string const & error_type) { - 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 & el = buffer()->errorList(error_type); + if (!el.empty()) { + getDialogs().show("errorlist", error_type); } } diff --git a/src/frontends/controllers/ControlErrorList.C b/src/frontends/controllers/ControlErrorList.C index d9e8c082ec..4ea92b835a 100644 --- a/src/frontends/controllers/ControlErrorList.C +++ b/src/frontends/controllers/ControlErrorList.C @@ -14,10 +14,15 @@ #include "buffer.h" #include "BufferView.h" #include "debug.h" +#include "gettext.h" #include "lyxtext.h" #include "paragraph.h" #include "pariterator.h" +#include "support/lstrings.h" + +using lyx::support::bformat; + using std::endl; using std::string; @@ -39,10 +44,13 @@ ErrorList const & ControlErrorList::errorList() const } -bool ControlErrorList::initialiseParams(string const & name) +bool ControlErrorList::initialiseParams(string const & error_type) { - errorlist_ = kernel().bufferview()->buffer()->getErrorList(); - name_ = name; + Buffer * buf = kernel().bufferview()->buffer(); + string const title = bformat(_("%1$s Errors (%2$s)"), + _(error_type), buf->fileName()); + errorlist_ = buf->errorList(error_type); + name_ = title; return true; } diff --git a/src/importer.C b/src/importer.C index b4e135cc8b..3f333515d7 100644 --- a/src/importer.C +++ b/src/importer.C @@ -39,7 +39,7 @@ extern BufferList bufferlist; bool Importer::Import(LyXView * lv, string const & filename, - string const & format) + string const & format, ErrorList & errorList) { string const displaypath = makeDisplayPath(filename); lv->message(bformat(_("Importing %1$s..."), displaypath)); @@ -53,7 +53,7 @@ bool Importer::Import(LyXView * lv, string const & filename, it != loaders.end(); ++it) { if (converters.isReachable(format, *it)) { if (!converters.convert(0, filename, filename, - format, *it)) + format, *it, errorList)) return false; loader_format = *it; break; diff --git a/src/importer.h b/src/importer.h index 7d62799cab..b63358de30 100644 --- a/src/importer.h +++ b/src/importer.h @@ -19,6 +19,7 @@ class LyXView; +class ErrorList; class Format; class Importer { @@ -26,7 +27,7 @@ public: /// static bool Import(LyXView * lv, std::string const & filename, - std::string const & format); + std::string const & format, ErrorList & errorList); /// static diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index d8fd28e7bd..ac6de16921 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -313,9 +313,12 @@ void updateExternal(InsetExternalParams const & params, return; // SUCCESS string const to_file_base = support::changeExtension(to_file, string()); + + // FIXME (Abdel 12/08/06): Is there a need to show these errors? + ErrorList el; /* bool const success = */ converters.convert(&buffer, temp_file, to_file_base, - from_format, to_format, true); + from_format, to_format, el, true); // return success } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 1440e9bad6..f4e01ea3e0 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -720,7 +720,9 @@ string const InsetGraphics::prepareFile(Buffer const & buf, << "\tfile to convert = " << temp_file << '\n' << "\t from " << from << " to " << to << '\n'; - if (converters.convert(&buf, temp_file, temp_file, from, to, true)) { + // FIXME (Abdel 12/08/06): Is there a need to show these errors? + ErrorList el; + if (converters.convert(&buf, temp_file, temp_file, from, to, el, true)) { runparams.exportdata->addExternalFile(tex_format, to_file, output_to_file); runparams.exportdata->addExternalFile("dvi", diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f6e5a6ae8d..1c69cb7d1c 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -163,7 +163,8 @@ void InsetText::read(Buffer const & buf, LyXLex & lex) // delete the initial paragraph Paragraph oldpar = *paragraphs().begin(); paragraphs().clear(); - bool res = text_.read(buf, lex); + ErrorList errorList; + bool res = text_.read(buf, lex, errorList); init(); if (!res) { diff --git a/src/lyx_main.C b/src/lyx_main.C index 422ecc0308..9f3dddbb92 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -280,21 +280,21 @@ int LyX::exec2(int & argc, char * argv[]) last_loaded = b; } else { Buffer * buf = bufferlist.newBuffer(s, false); - if (loadLyXFile(buf, s)) + 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); + ErrorList const & el = buf->errorList("Parse"); + 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); + } } } + else + bufferlist.release(buf); } } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index eff3011510..fbce9de95a 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -837,22 +837,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_BUFFER_UPDATE: Exporter::Export(owner->buffer(), argument, true); - owner->showErrorList(bufferFormat(*owner->buffer())); break; case LFUN_BUFFER_VIEW: Exporter::preview(owner->buffer(), argument); - owner->showErrorList(bufferFormat(*owner->buffer())); break; case LFUN_BUILD_PROGRAM: Exporter::Export(owner->buffer(), "program", true); - owner->showErrorList(_("Build")); break; case LFUN_BUFFER_CHKTEX: owner->buffer()->runChktex(); - owner->showErrorList(_("ChkTeX")); break; case LFUN_BUFFER_EXPORT: @@ -860,7 +856,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd) owner->getDialogs().show("sendto"); else { Exporter::Export(owner->buffer(), argument, false); - owner->showErrorList(bufferFormat(*owner->buffer())); } break; @@ -892,8 +887,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; } else { - Exporter::Export(buffer, format_name, true, - filename); + Exporter::Export(buffer, format_name, true, filename); } // Substitute $$FName for filename @@ -1555,14 +1549,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd) recordUndoFullDocument(view()); buffer->params().textclass = new_class; StableDocIterator backcur(view()->cursor()); - ErrorList el; + ErrorList & el = buffer->errorList("Class Switch"); lyx::cap::switchBetweenClasses( old_class, new_class, static_cast(buffer->inset()), el); view()->setCursor(backcur.asDocIterator(&(buffer->inset()))); - bufferErrors(*buffer, el); - owner->showErrorList(_("Class switch")); + + buffer->errors("Class Switch"); updateLabels(*buffer); updateforce = true; break; @@ -1889,7 +1883,9 @@ void LyXFunc::doImport(string const & argument) } } - Importer::Import(owner, filename, format); + ErrorList errorList; + Importer::Import(owner, filename, format, errorList); + // FIXME (Abdel 12/08/06): Is there a need to display the error list here? } diff --git a/src/lyxtext.h b/src/lyxtext.h index 8eb3931562..118d832d66 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -30,6 +30,7 @@ class BufferParams; class BufferView; class CursorSlice; class Dimension; +class ErrorList; class InsetBase; class InsetBase_code; class FuncRequest; @@ -320,7 +321,7 @@ public: /// void write(Buffer const & buf, std::ostream & os) const; /// returns whether we've seen our usual 'end' marker - bool read(Buffer const & buf, LyXLex & lex); + bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList); /// int ascent() const; diff --git a/src/text.C b/src/text.C index 88904b4d0d..a29c214577 100644 --- a/src/text.C +++ b/src/text.C @@ -156,7 +156,7 @@ int numberOfHfills(Paragraph const & par, Row const & row) void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, - string const & token, LyXFont & font, Change & change) + string const & token, LyXFont & font, Change & change, ErrorList & errorList) { BufferParams const & bp = buf.params(); @@ -180,7 +180,7 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, bool hasLayout = tclass.hasLayout(layoutname); if (!hasLayout) { - buf.addError(ErrorItem(_("Unknown layout"), + errorList.push_back(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.addError(ErrorItem(_("Unknown Inset"), line, + errorList.push_back(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.addError(ErrorItem(_("Change tracking error"), + errorList.push_back(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.addError(ErrorItem(_("Change tracking error"), + errorList.push_back(ErrorItem(_("Change tracking error"), bformat(_("Unknown author index for deletion: %1$d\n"), aid), par.id(), 0, par.size())); @@ -352,14 +352,14 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, change = Change(Change::DELETED, bp.author_map[aid], ct); } else { lex.eatLine(); - buf.addError(ErrorItem(_("Unknown token"), + errorList.push_back(ErrorItem(_("Unknown token"), bformat(_("Unknown token: %1$s %2$s\n"), token, lex.getString()), par.id(), 0, par.size())); } } -void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex) +void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex, ErrorList & errorList) { lex.nextToken(); string token = lex.getString(); @@ -368,7 +368,7 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex) while (lex.isOK()) { - readParToken(buf, par, lex, token, font, change); + readParToken(buf, par, lex, token, font, change, errorList); lex.nextToken(); token = lex.getString(); @@ -2083,7 +2083,7 @@ void LyXText::write(Buffer const & buf, std::ostream & os) const } -bool LyXText::read(Buffer const & buf, LyXLex & lex) +bool LyXText::read(Buffer const & buf, LyXLex & lex, ErrorList & errorList) { Paragraph::depth_type depth = 0; @@ -2122,7 +2122,7 @@ bool LyXText::read(Buffer const & buf, LyXLex & lex) // FIXME: goddamn InsetTabular makes us pass a Buffer // not BufferParams - ::readParagraph(buf, pars_.back(), lex); + ::readParagraph(buf, pars_.back(), lex, errorList); } else if (token == "\\begin_deeper") { ++depth; diff --git a/src/text3.C b/src/text3.C index 33eec5dbe2..027343eb4b 100644 --- a/src/text3.C +++ b/src/text3.C @@ -29,6 +29,7 @@ #include "CutAndPaste.h" #include "debug.h" #include "dispatchresult.h" +#include "errorlist.h" #include "factory.h" #include "funcrequest.h" #include "gettext.h" @@ -731,7 +732,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) cur.setSelection(); if (content) { lyx::cap::replaceSelection(cur); - pasteSelection(cur, 0); + pasteSelection(cur, bv->buffer()->errorList("Paste"), 0); cur.clearSelection(); // restore position cur.pit() = std::min(cur.lastpit(), spit); @@ -797,9 +798,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) cur.message(_("Paste")); lyx::cap::replaceSelection(cur); if (isStrUnsignedInt(cmd.argument)) - pasteSelection(cur, convert(cmd.argument)); + pasteSelection(cur, bv->buffer()->errorList("Paste"), + convert(cmd.argument)); else - pasteSelection(cur, 0); + pasteSelection(cur, bv->buffer()->errorList("Paste"), + 0); + bv->buffer()->errors("Paste"); cur.clearSelection(); // bug 393 bv->switchKeyMap(); finishUndo(); -- 2.39.2