]> git.lyx.org Git - features.git/commitdiff
added a parseError signal to Buffer and use it
authorAlfredo Braunstein <abraunst@lyx.org>
Fri, 20 Jun 2003 23:03:43 +0000 (23:03 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Fri, 20 Jun 2003 23:03:43 +0000 (23:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7200 a592a061-630c-0410-9148-cb99ea01b6c8

16 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/ChangeLog
src/buffer.C
src/buffer.h
src/errorlist.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/QDocument.C
src/frontends/qt2/QDocumentDialog.C
src/insets/ChangeLog
src/insets/insettext.C
src/lyx_main.C
src/lyx_main.h
src/paragraph_funcs.C

index 6e3d8ba3c9773f650a8b67fb21866e5878fa3920..5b0a7330e7748a99c0eb310966b5b2e9b6f0b084 100644 (file)
@@ -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()) {
index a2fbaed17011e3da9c677b01bfe58614dc29ab66..e2031947ff6eaf5e0fb91f34af87eb5ee9388489 100644 (file)
@@ -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
index f2c3be9d81219075fe9240bc149933b0bd004769..a2770b274f54b7582f6b68cead2be0715b01d7b8 100644 (file)
@@ -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;
 }
 
index 7dea067f9345c6368a99155c3a0a9a9bc8484c28..040288298a22e86658a685e5874ad87d84fe8a86 100644 (file)
@@ -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();
index 5abfb2681c7a6aff87891204fd8b0480585ac6c8..6a29bb9bc472fe98ae7481d91cbf4b1d374baf37 100644 (file)
@@ -1,4 +1,12 @@
-
+2003-06-21  Alfredo Braunstein  <abraunst@libero.it>
+
+       * 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  <abraunst@libero.it>
 
        * bufferlist.[Ch] (loadLyXFile, readFile, newFile): removed the 
index 808f3149b2435ba80c469b072260ed91ee2d87d7..2b724aa8a2ff163450e7bb1ae4bb17d18e07dfc9 100644 (file)
@@ -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);
index 06e26a6919048a042d7cf3cbf0d4fbbff6b07060..7bed397524734cad025e3df28aabb0201902ee81 100644 (file)
 #include "ParagraphList.h"
 #include "author.h"
 #include "iterators.h"
+#include "errorlist.h"
 
 #include <boost/scoped_ptr.hpp>
+#include <boost/signals/signal1.hpp>
 
 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<void, ErrorItem> 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
index 993d2b1f937ec320e432b144a41c1644011a238b..21a87b08ed14880efb3a09ba67a6e32d5015533d 100644 (file)
@@ -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();
 };
 
index af224ddd8d5479f5dad4134b09d5fe689a89cf27..55c4a528e6240215c0dddf8abb92e6d92721f06c 100644 (file)
@@ -1,3 +1,9 @@
+
+2003-06-21  Alfredo Braunstein  <abraunst@libero.it>
+
+       * QDocumentDialog.C: header reordering to handle qt/boost "signals" 
+       symbol clash
+
 2003-06-20  Angus Leeming  <leeming@lyx.org>
 
        * QBibtexDialog.C (browsePressed): fix warning of comparison between
index 13dec25629563e26985df0465fb40acabcee6702..d5883b03985b8a78cc9eb2614e1efc1f0397982f 100644 (file)
@@ -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 <vector>
 
+
 using std::vector;
 
 typedef Qt2CB<ControlDocument, Qt2DB<QDocumentDialog> > base_class;
index 15c7b4f6e576c94174b985e80e7631e61bc59fa8..5964d23d519a91e4fae84fc5d5413ba1dad6537b 100644 (file)
@@ -9,6 +9,9 @@
  */
 
 #include <config.h>
+
+#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 <qwidgetstack.h>
 #include <qlistbox.h>
index ce91287b07c5d94beba818c717d8a20516a7185c..76ae310cc53c6c063b9e9e8914b15ad7bf459d3a 100644 (file)
@@ -1,3 +1,7 @@
+2003-06-21  Alfredo Braunstein  <abraunst@libero.it>
+
+       * insetinclude.C (docbook): use parseError instead of sgmlError 
+       
 2003-06-19  Alfredo Braunstein  <abraunst@libero.it>
 
        * insetinclude.C (loadIfNeeded): call ::loadLyXFile instead 
index bd9a60d50bd4592c1e0fbd33af4f0ac573dd365e..a5ff6909ad4d724964fa68e6b21d978c9406eded 100644 (file)
@@ -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;
 
index ad0165acc21ae120ce346a91c1b57d400185b112..dee88dd305b48c049a4f4c923c2c37de9ce8482c 100644 (file)
 #include "frontends/lyx_gui.h"
 
 #include <boost/function.hpp>
+#include <boost/bind.hpp>
+#include <boost/signals/signal1.hpp>
 
 #include <cstdlib>
 #include <csignal>
+#include <iostream>
 
 using std::vector;
 using std::endl;
@@ -144,6 +147,7 @@ LyX::LyX(int & argc, char * argv[])
                vector<string>::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);
index e8769300feb4e646446f24e53e71938c9186ff7c..6c3cff1867cadb6bed001f6dd59c0363c36c86e4 100644 (file)
 #define LYX_MAIN_H
 
 #include "LString.h"
+#include "errorlist.h"
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/utility.hpp>
 
 #include <csignal>
 
+
 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;
index 7c42132308a852c0a11b3b9f87c312517abeb980..73de67f9c20e019bf250d0e2db69204f066a607c 100644 (file)
@@ -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;