From ffb610695f141232d287534d29f985acf0ef318d Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Fri, 20 Jun 2003 23:03:43 +0000 Subject: [PATCH] added a parseError signal to Buffer and use it git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7200 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 8 ----- src/BufferView.h | 2 -- src/BufferView_pimpl.C | 22 ++++++++++-- src/BufferView_pimpl.h | 2 ++ src/ChangeLog | 10 +++++- src/buffer.C | 56 ++++++++++------------------- src/buffer.h | 8 +++-- src/errorlist.h | 4 +-- src/frontends/qt2/ChangeLog | 6 ++++ src/frontends/qt2/QDocument.C | 2 ++ src/frontends/qt2/QDocumentDialog.C | 5 ++- src/insets/ChangeLog | 4 +++ src/insets/insettext.C | 3 +- src/lyx_main.C | 12 +++++++ src/lyx_main.h | 4 +++ src/paragraph_funcs.C | 7 ++-- 16 files changed, 92 insertions(+), 63 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 6e3d8ba3c9..5b0a7330e7 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -36,7 +36,6 @@ #include "frontends/screen.h" #include "insets/insetcommand.h" // ChangeRefs -#include "insets/inseterror.h" #include "insets/updatableinset.h" #include "support/FileInfo.h" @@ -349,13 +348,6 @@ void BufferView::setErrorList(ErrorList const & el) } -void BufferView::addError(ErrorItem const & ei) -{ - pimpl_->errorlist_.push_back(ei); - -} - - void BufferView::showErrorList(string const & action) const { if (getErrorList().size()) { diff --git a/src/BufferView.h b/src/BufferView.h index a2fbaed170..e2031947ff 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -161,8 +161,6 @@ public: void resetErrorList(); /// stored this error list void setErrorList(ErrorList const &); - /// adds a single error to the list - void addError(ErrorItem const &); /// show the error list to the user void showErrorList(string const &) const; /// set the cursor based on the given TeX source row diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index f2c3be9d81..a2770b274f 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -130,6 +130,12 @@ BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner, } +void BufferView::Pimpl::addError(ErrorItem const & ei) +{ + errorlist_.push_back(ei); + +} + bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) { @@ -161,9 +167,14 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) } Buffer * b = bufferlist.newBuffer(s); - //this is the point to attach to the error signal in the buffer + bv_->resetErrorList(); + //attach to the error signal in the buffer + b->parseError.connect(boost::bind(&BufferView::Pimpl::addError, + this, _1)); - if (!::loadLyXFile(b, s)) { + bool loaded = true; + + if (! ::loadLyXFile(b, s)) { bufferlist.release(b); string text = bformat(_("The document %1$s does " "not yet exist.\n\n" @@ -176,13 +187,18 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) bufferlist.close(buffer_, false); buffer(newFile(s, string(), true)); } - } + + loaded = false; + } buffer(b); if (tolastfiles) lastfiles->newFile(b->fileName()); + if (loaded) + bv_->showErrorList(_("Parse")); + return true; } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 7dea067f93..040288298a 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -109,6 +109,8 @@ struct BufferView::Pimpl : public boost::signals::trackable { private: /// An error list (replaces the error insets) ErrorList errorlist_; + /// add an error to the list + void addError(ErrorItem const &); /// track changes for the document void trackChanges(); diff --git a/src/ChangeLog b/src/ChangeLog index 5abfb2681c..6a29bb9bc4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,12 @@ - +2003-06-21 Alfredo Braunstein + + * buffer.[Ch]: added the parseError signal and use it, removed + sgmlError + * BufferView.[Ch] (addError): moved to ... + * BufferView_pimpl.[Ch] (addError, loadLyXFile): ... here. Attach + to the Buffer::parseError signal to catch (guess what) parse errors + * lyx_main.[Ch] (printError,LyX): added gui-less parsing error feedback + 2003-06-19 Alfredo Braunstein * bufferlist.[Ch] (loadLyXFile, readFile, newFile): removed the diff --git a/src/buffer.C b/src/buffer.C index 808f3149b2..2b724aa8a2 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -45,7 +45,6 @@ #include "mathed/formulamacro.h" #include "mathed/formula.h" -#include "insets/inseterror.h" #include "insets/insetbibitem.h" #include "insets/insetbibtex.h" #include "insets/insetinclude.h" @@ -280,6 +279,12 @@ int Buffer::readHeader(LyXLex & lex) unknownClass(unknown); } else { ++unknown_tokens; + string const s = bformat(_("Unknown token: " + "%1$s %2$s\n"), + token, + lex.getString()); + parseError(ErrorItem(_("Header error"), s, + -1, 0, 0)); } } } @@ -297,14 +302,10 @@ int Buffer::readHeader(LyXLex & lex) // Returns false if "\the_end" is not read (Asger) bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit) { - int unknown_tokens = 0; - Paragraph::depth_type depth = 0; bool the_end_read = false; if (paragraphs.empty()) { - unknown_tokens += readHeader(lex); - if (!params.getLyXTextClass().load()) { string theclass = params.getLyXTextClass().name(); Alert::error(_("Can't load document class"), bformat( @@ -339,20 +340,7 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit) continue; } - unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth); - } - - - if (unknown_tokens > 0) { - string s; - if (unknown_tokens == 1) { - s = bformat(_("Encountered one unknown token when reading " - "the document %1$s."), fileName()); - } else { - s = bformat(_("Encountered %1$s unknown tokens when reading " - "the document %2$s."), tostr(unknown_tokens), fileName()); - } - Alert::warning(_("Document format failure"), s); + readParagraph(lex, token, paragraphs, pit, depth); } return the_end_read; @@ -360,8 +348,8 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit) int Buffer::readParagraph(LyXLex & lex, string const & token, - ParagraphList & pars, ParagraphList::iterator & pit, - Paragraph::depth_type & depth) + ParagraphList & pars, ParagraphList::iterator & pit, + Paragraph::depth_type & depth) { static Change current_change; int unknown = 0; @@ -376,14 +364,16 @@ int Buffer::readParagraph(LyXLex & lex, string const & token, LyXFont f(LyXFont::ALL_INHERIT, params.language); par.setFont(0, f); - // FIXME: goddamn InsetTabular makes us pass a Buffer - // not BufferParams - unknown += ::readParagraph(*this, par, lex); - // insert after if (pit != pars.end()) ++pit; + pit = pars.insert(pit, par); + + // FIXME: goddamn InsetTabular makes us pass a Buffer + // not BufferParams + ::readParagraph(*this, *pit, lex); + } else if (token == "\\begin_deeper") { ++depth; } else if (token == "\\end_deeper") { @@ -1194,8 +1184,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) case LATEX_COMMAND: if (depth != 0) - sgmlError(pit, 0, - _("Error: Wrong depth for LatexType Command.\n")); + parseError(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size())); if (!environment_stack[depth].empty()) { sgml::closeTag(ofs, depth, false, environment_stack[depth]); @@ -1539,14 +1528,6 @@ void Buffer::simpleLinuxDocOnePar(ostream & os, } -// Print an error message. -void Buffer::sgmlError(ParagraphList::iterator pit, int pos, - string const & message) const -{ - users->addError(ErrorItem(message, string(), pit->id(), pos, pos)); -} - - void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) { ofstream ofs(fname.c_str()); @@ -1662,8 +1643,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) case LATEX_COMMAND: if (depth != 0) - sgmlError(par, 0, - _("Error: Wrong depth for LatexType Command.\n")); + parseError(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size())); command_name = style->latexname(); @@ -1952,7 +1932,7 @@ int Buffer::runChktex() if (res == -1) { Alert::error(_("chktex failure"), - _("Could not run chktex successfully.")); + _("Could not run chktex successfully.")); } else if (res > 0) { // Insert all errors as errors boxes ErrorList el (*this, terr); diff --git a/src/buffer.h b/src/buffer.h index 06e26a6919..7bed397524 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -22,8 +22,10 @@ #include "ParagraphList.h" #include "author.h" #include "iterators.h" +#include "errorlist.h" #include +#include class BufferView; class LyXRC; @@ -126,6 +128,9 @@ public: bool hasParWithID(int id) const; public: + /// This signal is emitted when a parsing error shows up. + boost::signal1 parseError; + /** Save file. Takes care of auto-save files and backup file if requested. Returns \c true if the save is successful, \c false otherwise. @@ -168,9 +173,6 @@ public: /// void makeDocBookFile(string const & filename, bool nice, bool only_body = false); - /// - void sgmlError(ParagraphList::iterator par, int pos, string const & message) const; - /// returns the main language for the buffer (document) Language const * getLanguage() const; /// get l10n translated to the buffers language diff --git a/src/errorlist.h b/src/errorlist.h index 993d2b1f93..21a87b08ed 100644 --- a/src/errorlist.h +++ b/src/errorlist.h @@ -27,8 +27,8 @@ struct ErrorItem { int par_id; int pos_start; int pos_end; - ErrorItem(string const &, string const &, - int, int, int); + ErrorItem(string const & error, string const & description, + int parid, int posstart, int posend); ErrorItem(); }; diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index af224ddd8d..55c4a528e6 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ + +2003-06-21 Alfredo Braunstein + + * QDocumentDialog.C: header reordering to handle qt/boost "signals" + symbol clash + 2003-06-20 Angus Leeming * QBibtexDialog.C (browsePressed): fix warning of comparison between diff --git a/src/frontends/qt2/QDocument.C b/src/frontends/qt2/QDocument.C index 13dec25629..d5883b0398 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -17,6 +17,7 @@ #include "QDocumentDialog.h" #include "Qt2BC.h" + #include "language.h" #include "helper_funcs.h" // getSecond() #include "insets/insetquotes.h" @@ -46,6 +47,7 @@ #include + using std::vector; typedef Qt2CB > base_class; diff --git a/src/frontends/qt2/QDocumentDialog.C b/src/frontends/qt2/QDocumentDialog.C index 15c7b4f6e5..5964d23d51 100644 --- a/src/frontends/qt2/QDocumentDialog.C +++ b/src/frontends/qt2/QDocumentDialog.C @@ -9,6 +9,9 @@ */ #include + +#include "buffer.h" //*here* because of braindead qt headers's #define signals + #include "qt_helpers.h" #include "ControlDocument.h" @@ -34,7 +37,7 @@ #include "Spacing.h" #include "support/lstrings.h" #include "lyxrc.h" -#include "buffer.h" + #include #include diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index ce91287b07..76ae310cc5 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2003-06-21 Alfredo Braunstein + + * insetinclude.C (docbook): use parseError instead of sgmlError + 2003-06-19 Alfredo Braunstein * insetinclude.C (loadIfNeeded): call ::loadLyXFile instead diff --git a/src/insets/insettext.C b/src/insets/insettext.C index bd9a60d50b..a5ff6909ad 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -19,6 +19,7 @@ #include "dimension.h" #include "funcrequest.h" #include "gettext.h" +#include "errorlist.h" #include "intl.h" #include "LaTeXFeatures.h" #include "LColor.h" @@ -1517,7 +1518,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const break; case LATEX_COMMAND: - buf->sgmlError(pit, 0, _("Error: LatexType Command not allowed here.\n")); + buf->parseError(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size())); return -1; break; diff --git a/src/lyx_main.C b/src/lyx_main.C index ad0165acc2..dee88dd305 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -41,9 +41,12 @@ #include "frontends/lyx_gui.h" #include +#include +#include #include #include +#include using std::vector; using std::endl; @@ -144,6 +147,7 @@ LyX::LyX(int & argc, char * argv[]) vector::iterator end = files.end(); for (; it != end; ++it) { last_loaded = bufferlist.newBuffer(*it, false); + last_loaded->parseError.connect(boost::bind(&LyX::printError, this, _1)); loadLyXFile(last_loaded, *it); } @@ -215,6 +219,14 @@ static void error_handler(int err_sig) } +void LyX::printError(ErrorItem const & ei) +{ + std::cerr << _("LyX: ") << ei.error + << ':' << ei.description << std::endl; + +} + + void LyX::init(bool gui) { signal(SIGHUP, error_handler); diff --git a/src/lyx_main.h b/src/lyx_main.h index e8769300fe..6c3cff1867 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -11,12 +11,14 @@ #define LYX_MAIN_H #include "LString.h" +#include "errorlist.h" #include #include #include + class LyXRC; class LastFiles; class Buffer; @@ -60,6 +62,8 @@ private: void readEncodingsFile(string const & name); /// parsing of non-gui LyX options. Returns true if gui bool easyParse(int & argc, char * argv[]); + /// shows up a parsing error on screen + void printError(ErrorItem const &); /// has this user started lyx for the first time? bool first_start; diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 7c42132308..73de67f9c2 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -32,7 +32,6 @@ #include "insets/insetlatexaccent.h" #include "insets/insettabular.h" #include "insets/insethfill.h" -#include "insets/inseterror.h" #include "insets/insetnewline.h" extern string bibitemWidest(Buffer const *); @@ -1007,9 +1006,9 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok lex.eatLine(); string const s = bformat(_("Unknown token: %1$s %2$s\n"), token, lex.getString()); - // we can do this here this way because we're actually reading - // the buffer and don't care about LyXText right now. - par.insertInset(par.size(), new InsetError(s), font); + + buf.parseError(ErrorItem(_("Unknown token"), s, + par.id(), 0, par.size())); return 1; } return 0; -- 2.39.2