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.

Abdel.



TODO 1: All occurence of "LyXView::showErrorList()" in the "kernel" should be replaced by a boost signal emission (Buffer::errors()). This signal is already connected to this showErrorList() slot.

TODO 2: The ErrorList mechanism is used wrongly in a number of place, most notably in "Converter.C". Instead of replacing the ErrorList in the "Buffer" class, the "Converter" class should maintain its own list instead and connect directly to the LyXView::showErrorList() slot.


Comment Objection?

Abdel.

PS: I used errorList_ style because this style is used for other private member. AFAIR no real decision has been taken wrt to this.

Log:
Buffer:
* errorList_: new private member and associated access methods.
* setErrorList(): new accessor method.
* addError(): apend an error to the errorList_.
* error(): deleted.
* errors(): new boost signal, unused for now. Shall be used instead of LyXView::showErrorList().

LyXView:
* getErrorList(), addError(), errorlist_, errorConnection_: deleted.
* errorsConnection_: new boost connection for the Buffer::errors() signal.

lyx_main.C:
* LyX::exec2(): manually print all errors.



------------------------------------------------------------------------

Index: buffer.C
===================================================================
--- buffer.C    (revision 14447)
+++ buffer.C    (working copy)
@@ -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 @@
                                                           "%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 @@
 // 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 @@
                 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 @@
                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: buffer.h
===================================================================
--- buffer.h    (revision 14447)
+++ buffer.h    (working copy)
@@ -12,6 +12,7 @@
 #ifndef BUFFER_H
 #define BUFFER_H
+#include "errorlist.h"
 #include "InsetList.h"
#include "dociterator.h"
@@ -112,8 +113,8 @@
        /// 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<void(ErrorItem)> error;
+       /// 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.
@@ -347,6 +348,21 @@
        /// 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 @@
        /// 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: buffer_funcs.C
===================================================================
--- buffer_funcs.C      (revision 14447)
+++ buffer_funcs.C      (working copy)
@@ -230,15 +230,15 @@
                                                          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);
 }
Index: BufferView.h
===================================================================
--- BufferView.h        (revision 14458)
+++ BufferView.h        (working copy)
@@ -28,7 +28,6 @@
 class Buffer;
 class Change;
 class DocIterator;
-class ErrorList;
 class FuncRequest;
 class FuncStatus;
 class Language;
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 14458)
+++ BufferView_pimpl.C  (working copy)
@@ -787,7 +787,8 @@
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);
Index: frontends/controllers/ControlErrorList.C
===================================================================
--- frontends/controllers/ControlErrorList.C    (revision 14458)
+++ frontends/controllers/ControlErrorList.C    (working copy)
@@ -11,7 +11,6 @@
 #include <config.h>
#include "ControlErrorList.h"
-#include "frontends/LyXView.h"
 #include "buffer.h"
 #include "BufferView.h"
 #include "debug.h"
@@ -42,7 +41,7 @@
bool ControlErrorList::initialiseParams(string const & name)
 {
-       errorlist_ = kernel().lyxview().getErrorList();
+       errorlist_ = kernel().bufferview()->buffer()->getErrorList();
        name_ = name;
        return true;
 }
Index: frontends/LyXView.C
===================================================================
--- frontends/LyXView.C (revision 14458)
+++ frontends/LyXView.C (working copy)
@@ -167,12 +167,17 @@
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::disconnectBuffer()
 {
-       errorConnection_.disconnect();
        messageConnection_.disconnect();
        busyConnection_.disconnect();
        titleConnection_.disconnect();
@@ -212,29 +216,17 @@
 }
-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();
Index: frontends/LyXView.h
===================================================================
--- frontends/LyXView.h (revision 14458)
+++ frontends/LyXView.h (working copy)
@@ -13,8 +13,6 @@
 #ifndef LYXVIEW_H
 #define LYXVIEW_H
-#include "errorlist.h"
-
 #include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/signal.hpp>
@@ -167,15 +165,8 @@
        /// 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 @@
        /// dialogs for this view
        boost::scoped_ptr<Dialogs> 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
Index: lyx_main.C
===================================================================
--- lyx_main.C  (revision 14447)
+++ lyx_main.C  (working copy)
@@ -83,6 +83,7 @@
 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 @@
                                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);
+                                       }
+                               }
                        }
                }
Index: text.C
===================================================================
--- text.C      (revision 14447)
+++ text.C      (working copy)
@@ -180,7 +180,7 @@
                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 @@
                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 @@
                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 @@
                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 @@
                        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()));
        }

Reply via email to