Abdelrazak Younes wrote:
Abdelrazak Younes wrote:

This patch does that and it removes absolutely _no_ functionality. Actually, I think it should speed-up _significantly_ the latex compilation for example in case of problematic files.

I am going tomorrow and I really don't have the time to wait for Lars approval. I am going to commit this because I think this is the right thing to do. If you are not happy with it, just revert the patch(es), I won't be offended ;-)

Lars, before you get upset about the transfer of errorList_ to Buffer please have a little faith in me. I agree this is not the right place to put it but this is transitional. Transferring to Buffer simplify the code and the work flow quite significantly with minimal changes to the code. My next patch(es) will modify that.

I will then proceed to step 1 or maybe to steps 1 and 2 at the same time. I will probably use a global ErrorLists map variable. I hate global variables but considering the current structure of the code I have no real choice for now. I'll try to find some time to implement the one (theApp) unique variable when I come back.

Let's see how fast I can code the patch.

Hum... 2 hours... I need some sleep!

Attached my current patch. It works well at least for the loading of buggy documents (like document with no \begin_document). I haven't tested yet LateX compilation. There might be some adjustments to do WRT ErrorLists initialisation but the big work is done.

The good news is that, with this infrastructure, the error lists are persistent. With a few more code, it should be possible to show the LateX processing errors even after the error dialog has been closed.

Please find attached the patch.

Log:

- Replace the Buffer::ErrorList with a global ErrorLists object.
- Replace the showErrorList() manual calls with ErrorLists.errors() signal emission

Enjoy,
Abdel.

Index: src/buffer.C
===================================================================
--- src/buffer.C        (revision 14467)
+++ src/buffer.C        (working copy)
@@ -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 @@
        params().headsep.erase();
        params().footskip.erase();
 
+       ErrorList & errorList = errorLists["Parse"];
+
        while (lex.isOK()) {
                lex.next();
                string const token = lex.getString();
@@ -445,14 +448,14 @@
                                                           "%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 @@
 // 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));
        }
 
@@ -493,16 +497,6 @@
                 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;
 }
 
@@ -1671,21 +1665,3 @@
        else // DocBook
                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);
-}
Index: src/buffer.h
===================================================================
--- src/buffer.h        (revision 14467)
+++ src/buffer.h        (working copy)
@@ -12,7 +12,6 @@
 #ifndef BUFFER_H
 #define BUFFER_H
 
-#include "errorlist.h"
 #include "InsetList.h"
 
 #include "dociterator.h"
@@ -32,7 +31,6 @@
 
 
 class BufferParams;
-class ErrorItem;
 class FuncRequest;
 class InsetBase;
 class InsetText;
@@ -113,8 +111,6 @@
        /// do we have a paragraph with this id?
        bool hasParWithID(int id) const;
 
-       /// This signal is emitted when some parsing error shows up.
-       boost::signal<void(std::string)> errors;
        /// This signal is emitted when some message shows up.
        boost::signal<void(std::string)> message;
        /// This signal is emitted when the buffer busy status change.
@@ -348,21 +344,6 @@
        /// 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.
@@ -384,13 +365,6 @@
        /// A cache for the bibfiles (including bibfiles of loaded child
        /// documents), needed for appropriate update of natbib labels.
        std::vector<std::string> 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
Index: src/buffer_funcs.C
===================================================================
--- src/buffer_funcs.C  (revision 14467)
+++ src/buffer_funcs.C  (working copy)
@@ -216,6 +216,8 @@
        TeXErrors::Errors::const_iterator cit = terr.begin();
        TeXErrors::Errors::const_iterator end = terr.end();
 
+       ErrorList & errorList = errorLists["LaTeX"];
+
        for (; cit != end; ++cit) {
                int id_start = -1;
                int pos_start = -1;
@@ -230,18 +232,12 @@
                                                          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())
Index: src/buffer_funcs.h
===================================================================
--- src/buffer_funcs.h  (revision 14447)
+++ src/buffer_funcs.h  (working copy)
@@ -39,8 +39,6 @@
 std::string const bufferFormat(Buffer const & buffer);
 ///
 void bufferErrors(Buffer const &, TeXErrors const &);
-///
-void bufferErrors(Buffer const &, ErrorList const &);
 
 /// Count the number of words in the text between these two iterators
 int countWords(DocIterator const & from, DocIterator const & to);
Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C      (revision 14467)
+++ src/BufferView_pimpl.C      (working copy)
@@ -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"
@@ -196,7 +197,8 @@
        }
 
        setBuffer(b);
-       owner_->showErrorList(_("Parse"));
+       // Send the "errors" signal in case of parsing errors
+       errorLists.errors("Parse");
 
        // scroll to the position when the file was last closed
        if (lyxrc.use_lastfilepos) {
@@ -787,8 +789,6 @@
 
        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))) {
                lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(),
                                             buf.params().textclass);
@@ -797,7 +797,9 @@
                res = _("Could not insert document %1$s");
 
        owner_->message(bformat(res, disp_fn));
-       owner_->showErrorList(_("Document insertion"));
+       // FIXME: should we create a ""Document insertion" errorList?
+       //errorLists.errors("Document insertion");
+       errorLists.errors("Parse");
        resizeCurrentBuffer();
 }
 
Index: src/CutAndPaste.C
===================================================================
--- src/CutAndPaste.C   (revision 14458)
+++ src/CutAndPaste.C   (working copy)
@@ -622,7 +622,7 @@
 
                pit_type endpit;
                PitPosPair ppp;
-               ErrorList el;
+               ErrorList & el = errorLists["Paste"];
 
                boost::tie(ppp, endpit) =
                        pasteSelectionHelper(cur.buffer(),
@@ -630,7 +630,6 @@
                                             cur.pit(), cur.pos(),
                                             parlist, textclass,
                                             el);
-               bufferErrors(cur.buffer(), el);
                updateLabels(cur.buffer());
                cur.clearSelection();
                text->setCursor(cur, ppp.first, ppp.second);
@@ -649,7 +648,7 @@
 
        pasteParagraphList(cur, theCuts[sel_index].first,
                           theCuts[sel_index].second);
-       cur.bv().owner()->showErrorList(_("Paste"));
+       errorLists.errors("Paste");
        cur.setSelection();
 }
 
Index: src/errorlist.C
===================================================================
--- src/errorlist.C     (revision 14447)
+++ src/errorlist.C     (working copy)
@@ -15,6 +15,7 @@
 using lyx::pos_type;
 using std::string;
 
+ErrorLists errorLists;
 
 ErrorItem::ErrorItem(string const & error_, string const & description_,
                     int par_id_, pos_type pos_start_, pos_type pos_end_)
Index: src/errorlist.h
===================================================================
--- src/errorlist.h     (revision 14447)
+++ src/errorlist.h     (working copy)
@@ -14,7 +14,10 @@
 
 #include "support/types.h"
 
+#include <boost/signal.hpp>
+
 #include <vector>
+#include <map>
 #include <string>
 
 class Buffer;
@@ -48,4 +51,16 @@
        using std::vector<ErrorItem>::const_iterator;
 };
 
+class ErrorLists: public std::map<std::string, ErrorList>
+{
+public:
+       ErrorLists() : std::map<std::string, ErrorList> () {}
+
+       /// This signal should be emitted when the ErrorList
+       /// associated with the string needs to be displayed.
+       boost::signal<void(std::string)> errors;
+};
+
+extern ErrorLists errorLists;
+
 #endif
Index: src/frontends/controllers/ControlErrorList.C
===================================================================
--- src/frontends/controllers/ControlErrorList.C        (revision 14467)
+++ src/frontends/controllers/ControlErrorList.C        (working copy)
@@ -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;
 
@@ -41,8 +46,10 @@
 
 bool ControlErrorList::initialiseParams(string const & name)
 {
-       errorlist_ = kernel().bufferview()->buffer()->getErrorList();
-       name_ = name;
+       string const title = bformat(_("%1$s Errors (%2$s)"),
+               _(name), kernel().bufferview()->buffer()->fileName());
+       errorlist_ = errorLists[name];
+       name_ = title;
        return true;
 }
 
Index: src/frontends/LyXView.C
===================================================================
--- src/frontends/LyXView.C     (revision 14467)
+++ src/frontends/LyXView.C     (working copy)
@@ -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"
@@ -170,13 +171,8 @@
        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(
+               errorLists.errors.connect(
                        boost::bind(&LyXView::showErrorList, this, _1));
 
        messageConnection_ =
@@ -218,11 +214,8 @@
 
 void LyXView::showErrorList(string const & action)
 {
-       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);
+       if (!errorLists[action].empty()) {
+               getDialogs().show("errorlist", action);
        }
 }
 
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C      (revision 14467)
+++ src/lyx_main.C      (working copy)
@@ -286,21 +286,21 @@
                                last_loaded = newFile(*it, string(), true);
                        } else {
                                Buffer * buf = bufferlist.newBuffer(s, false);
-                               if (loadLyXFile(buf, s))
+                               if (loadLyXFile(buf, s)) {
                                        last_loaded = buf;
+                                       ErrorList const & el = 
errorLists["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);
-
-                               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);
-                                       }
-                               }
                        }
                }
 
Index: src/lyxfunc.C
===================================================================
--- src/lyxfunc.C       (revision 14458)
+++ src/lyxfunc.C       (working copy)
@@ -837,22 +837,22 @@
 
                case LFUN_BUFFER_UPDATE:
                        Exporter::Export(owner->buffer(), argument, true);
-                       owner->showErrorList(bufferFormat(*owner->buffer()));
+                       errorLists.errors(bufferFormat(*owner->buffer()));
                        break;
 
                case LFUN_BUFFER_VIEW:
                        Exporter::preview(owner->buffer(), argument);
-                       owner->showErrorList(bufferFormat(*owner->buffer()));
+                       errorLists.errors(bufferFormat(*owner->buffer()));
                        break;
 
                case LFUN_BUILD_PROGRAM:
                        Exporter::Export(owner->buffer(), "program", true);
-                       owner->showErrorList(_("Build"));
+                       errorLists.errors("Build");
                        break;
 
                case LFUN_BUFFER_CHKTEX:
                        owner->buffer()->runChktex();
-                       owner->showErrorList(_("ChkTeX"));
+                       errorLists.errors("ChkTeX");
                        break;
 
                case LFUN_BUFFER_EXPORT:
@@ -860,7 +860,7 @@
                                owner->getDialogs().show("sendto");
                        else {
                                Exporter::Export(owner->buffer(), argument, 
false);
-                               
owner->showErrorList(bufferFormat(*owner->buffer()));
+                               
errorLists.errors(bufferFormat(*owner->buffer()));
                        }
                        break;
 
@@ -1555,14 +1555,13 @@
                        recordUndoFullDocument(view());
                        buffer->params().textclass = new_class;
                        StableDocIterator backcur(view()->cursor());
-                       ErrorList el;
+                       ErrorList & el = errorLists["Class switch"];
                        lyx::cap::switchBetweenClasses(
                                old_class, new_class,
                                static_cast<InsetText &>(buffer->inset()), el);
 
                        
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
-                       bufferErrors(*buffer, el);
-                       owner->showErrorList(_("Class switch"));
+                       errorLists.errors("Class switch");
                        updateLabels(*buffer);
                        updateforce = true;
                        break;
Index: src/text.C
===================================================================
--- src/text.C  (revision 14467)
+++ src/text.C  (working copy)
@@ -159,6 +159,7 @@
        string const & token, LyXFont & font, Change & change)
 {
        BufferParams const & bp = buf.params();
+       ErrorList & errorList = errorLists["Parse"];
 
        if (token[0] != '\\') {
                string::const_iterator cit = token.begin();
@@ -180,7 +181,7 @@
                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 +213,7 @@
                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 +330,7 @@
                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 +344,7 @@
                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,7 +353,7 @@
                        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()));
        }

Reply via email to