diff --git a/src/BufferView.C b/src/BufferView.C index 5b0a7330e7..f5e0dcae38 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -336,18 +336,6 @@ bool BufferView::insertLyXFile(string const & filen) } -void BufferView::resetErrorList() -{ - pimpl_->errorlist_.clear(); -} - - -void BufferView::setErrorList(ErrorList const & el) -{ - pimpl_->errorlist_ = el; -} - - void BufferView::showErrorList(string const & action) const { if (getErrorList().size()) { @@ -361,6 +349,7 @@ ErrorList const & BufferView::getErrorList() const { return pimpl_->errorlist_; + pimpl_->errorlist_.clear(); } diff --git a/src/BufferView.h b/src/BufferView.h index e2031947ff..3767c584dc 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -157,10 +157,6 @@ public: /// get the stored error list ErrorList const & getErrorList() const; - /// clears the stored error list - void resetErrorList(); - /// stored this error list - void setErrorList(ErrorList 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 a2770b274f..13cf1d1b98 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -167,14 +167,13 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) } Buffer * b = bufferlist.newBuffer(s); - bv_->resetErrorList(); //attach to the error signal in the buffer b->parseError.connect(boost::bind(&BufferView::Pimpl::addError, this, _1)); - bool loaded = true; + bool loaded = ::loadLyXFile(b, s); - if (! ::loadLyXFile(b, s)) { + if (! loaded) { bufferlist.release(b); string text = bformat(_("The document %1$s does " "not yet exist.\n\n" @@ -187,8 +186,6 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles) bufferlist.close(buffer_, false); buffer(newFile(s, string(), true)); } - - loaded = false; } buffer(b); diff --git a/src/ChangeLog b/src/ChangeLog index 23eea8d8a7..5f4a525dd1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2003-06-24 Alfredo Brauntein + + * converter.C (scanLog, runLaTeX): + * buffer.C (makeLinuxDocFile, makeDocBookFile, runChkTeX): + move the bv->showErrorList call to the callers + * lyxfunc.C: i.e. here... + * text2.C: and here + * BufferView.[Ch] (setErrorList, resetErrorList): both removed + * exporter.[Ch] (Backends, BufferFormat): the first was moved to anon + namespace, the second to... + * buffer_funcs (BufferFormat, parseErrors): added + * errorlist.C (ErrorList(TeXErrors const &)): removed + 2003-06-24 Jean-Marc Lasgouttes * ToolbarBackend.C (getIcon): complain when icon cannot be found diff --git a/src/buffer.C b/src/buffer.C index bacbbe69d7..658cc859c4 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -11,6 +11,7 @@ #include #include "buffer.h" +#include "buffer_funcs.h" #include "bufferlist.h" #include "LyXAction.h" #include "lyxrc.h" @@ -1146,8 +1147,6 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) string item_name; vector environment_stack(5); - users->resetErrorList(); - ParagraphList::iterator pit = paragraphs.begin(); ParagraphList::iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { @@ -1276,8 +1275,6 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) // we want this to be true outside previews (for insetexternal) niceFile = true; - - users->showErrorList(_("LinuxDoc")); } @@ -1594,8 +1591,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) string item_name; string command_name; - users->resetErrorList(); - ParagraphList::iterator par = paragraphs.begin(); ParagraphList::iterator pend = paragraphs.end(); @@ -1811,7 +1806,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) // we want this to be true outside previews (for insetexternal) niceFile = true; - users->showErrorList(_("DocBook")); } @@ -1937,9 +1931,7 @@ int Buffer::runChktex() _("Could not run chktex successfully.")); } else if (res > 0) { // Insert all errors as errors boxes - ErrorList el (*this, terr); - users->setErrorList(el); - users->showErrorList(_("ChkTeX")); + parseErrors(*this, terr); } users->owner()->busy(false); diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 3590c774fb..0eaca7c0dd 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -15,9 +15,11 @@ #include "buffer_funcs.h" #include "bufferlist.h" #include "buffer.h" +#include "errorlist.h" #include "gettext.h" #include "vc-backend.h" #include "lyxlex.h" +#include "LaTeX.h" #include "ParagraphList.h" #include "paragraph.h" @@ -194,3 +196,45 @@ Buffer * newFile(string const & filename, string const & templatename, return b; } + + +void parseErrors(Buffer const & buf, TeXErrors const & terr) +{ + TeXErrors::Errors::const_iterator cit = terr.begin(); + TeXErrors::Errors::const_iterator end = terr.end(); + + for (; cit != end; ++cit) { + int par_id = -1; + int posstart = -1; + int const errorrow = cit->error_in_line; + buf.texrow.getIdFromRow(errorrow, par_id, posstart); + int posend = -1; + buf.texrow.getIdFromRow(errorrow + 1, par_id, posend); + buf.parseError(ErrorItem(cit->error_desc, + cit->error_text, + par_id, posstart, posend)); + } +} + + +void parseErrors(Buffer const & buf, ErrorList const & el) +{ + ErrorList::const_iterator it = el.begin(); + ErrorList::const_iterator end = el.end(); + + for (; it != end; ++it) + buf.parseError(*it); +} + + +string const BufferFormat(Buffer const & buffer) +{ + if (buffer.isLinuxDoc()) + return "linuxdoc"; + else if (buffer.isDocBook()) + return "docbook"; + else if (buffer.isLiterate()) + return "literate"; + else + return "latex"; +} diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index dc6a440b76..372d99daea 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -9,9 +9,14 @@ * Full author contact details are available in file CREDITS */ +#ifndef BUFFER_FUNCS_H +#define BUFFER_FUNCS_H + #include "LString.h" class Buffer; +class TeXErrors; +class ErrorList; /** * Loads a LyX file \c filename into \c Buffer @@ -24,3 +29,12 @@ bool loadLyXFile(Buffer *, string const & filename); */ Buffer * newFile(string const & filename, string const & templatename, bool isNamed = false); + +///return the format of the buffer on a string +string const BufferFormat(Buffer const & buffer); + +void parseErrors(Buffer const &, TeXErrors const &); + +void parseErrors(Buffer const &, ErrorList const &); + +#endif // BUFFER_FUNCS_H diff --git a/src/converter.C b/src/converter.C index cd8a7ae10e..c93b39f3f6 100644 --- a/src/converter.C +++ b/src/converter.C @@ -15,6 +15,7 @@ #include "format.h" #include "lyxrc.h" #include "buffer.h" +#include "buffer_funcs.h" #include "bufferview_funcs.h" #include "errorlist.h" #include "LaTeX.h" @@ -476,11 +477,8 @@ bool Converters::scanLog(Buffer const * buffer, string const & /*command*/, TeXErrors terr; int result = latex.scanLogFile(terr); - if (bv && (result & LaTeX::ERRORS)) { - ErrorList el(*buffer, terr); - bv->setErrorList(el); - bv->showErrorList(_("LaTeX")); - } + if (bv && (result & LaTeX::ERRORS)) + parseErrors(*buffer, terr); return true; } @@ -507,12 +505,8 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command, int result = latex.run(terr, bv ? &bv->owner()->getLyXFunc() : 0); - if (bv && (result & LaTeX::ERRORS)) { - //show errors - ErrorList el(*buffer, terr); - bv->setErrorList(el); - bv->showErrorList(_("LaTeX")); - } + if (bv && (result & LaTeX::ERRORS)) + parseErrors(*buffer, terr); // check return value from latex.run(). if ((result & LaTeX::NO_LOGFILE)) { diff --git a/src/errorlist.C b/src/errorlist.C index b9a3c341e5..fd62e75548 100644 --- a/src/errorlist.C +++ b/src/errorlist.C @@ -12,7 +12,6 @@ #include "errorlist.h" #include "buffer.h" -#include "LaTeX.h" ErrorItem::ErrorItem(string const & error, string const & description, @@ -27,21 +26,3 @@ ErrorItem::ErrorItem() {} -ErrorList::ErrorList(Buffer const & buf, - TeXErrors const & terr) -{ - TeXErrors::Errors::const_iterator cit = terr.begin(); - TeXErrors::Errors::const_iterator end = terr.end(); - - for (; cit != end; ++cit) { - int par_id = -1; - int posstart = -1; - int const errorrow = cit->error_in_line; - buf.texrow.getIdFromRow(errorrow, par_id, posstart); - int posend = -1; - buf.texrow.getIdFromRow(errorrow + 1, par_id, posend); - push_back(ErrorItem(cit->error_desc, - cit->error_text, - par_id, posstart, posend)); - } -} diff --git a/src/errorlist.h b/src/errorlist.h index 21a87b08ed..f2a9b2d467 100644 --- a/src/errorlist.h +++ b/src/errorlist.h @@ -18,7 +18,6 @@ #include class Buffer; -class TeXErrors; /// A class to hold an error item struct ErrorItem { @@ -36,7 +35,6 @@ class ErrorList : private std::vector { public: ErrorList() : std::vector () {}; - ErrorList(Buffer const & buf, TeXErrors const &); using std::vector::push_back; using std::vector::end; diff --git a/src/exporter.C b/src/exporter.C index c84c7cd49d..49e59e1949 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -12,6 +12,7 @@ #include "exporter.h" #include "buffer.h" +#include "buffer_funcs.h" #include "lyx_cb.h" //ShowMessage() #include "support/filetools.h" #include "lyxrc.h" @@ -26,6 +27,21 @@ using std::vector; using std::find; + +namespace { + +vector const Backends(Buffer const * buffer) +{ + vector v; + if (buffer->params.getLyXTextClass().isTeXClassAvailable()) + v.push_back(BufferFormat(*buffer)); + v.push_back("text"); + return v; +} + +} //namespace anon + + bool Exporter::Export(Buffer * buffer, string const & format, bool put_in_tempdir, string & result_file) { @@ -142,25 +158,3 @@ Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable) return result; } - -string const Exporter::BufferFormat(Buffer const * buffer) -{ - if (buffer->isLinuxDoc()) - return "linuxdoc"; - else if (buffer->isDocBook()) - return "docbook"; - else if (buffer->isLiterate()) - return "literate"; - else - return "latex"; -} - - -vector const Exporter::Backends(Buffer const * buffer) -{ - vector v; - if (buffer->params.getLyXTextClass().isTeXClassAvailable()) - v.push_back(BufferFormat(buffer)); - v.push_back("text"); - return v; -} diff --git a/src/exporter.h b/src/exporter.h index f02e8472a0..12ccebd4da 100644 --- a/src/exporter.h +++ b/src/exporter.h @@ -39,11 +39,5 @@ public: std::vector const GetExportableFormats(Buffer const * buffer, bool only_viewable); /// -private: - static - string const BufferFormat(Buffer const * buffer); - /// - static - std::vector const Backends(Buffer const * buffer); }; #endif diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 74c224d6cd..93b3f5fcb3 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-06-24 Alfredo Braunstein + + * ControlDocument.C (classApply): removed the call to resetErrorList, + replaced setErrorList by parseErrors + 2003-06-21 Alfredo Braunstein * ControlError.[Ch]: removed diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index e30f5eb216..29f11a19dd 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -19,6 +19,7 @@ #include "lyxfind.h" #include "buffer.h" +#include "buffer_funcs.h" #include "errorlist.h" #include "language.h" #include "lyx_main.h" @@ -126,8 +127,7 @@ void ControlDocument::classApply() CutAndPaste::SwitchLayoutsBetweenClasses(old_class, new_class, lv_.buffer()->paragraphs, el); - - bufferview()->setErrorList(el); + parseErrors(*buffer(), el); bufferview()->showErrorList(_("Class switch")); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 576d918963..6799685caf 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1094,25 +1094,31 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) case LFUN_UPDATE: Exporter::Export(owner->buffer(), argument, true); + view()->showErrorList(BufferFormat(*owner->buffer())); break; case LFUN_PREVIEW: Exporter::Preview(owner->buffer(), argument); + view()->showErrorList(BufferFormat(*owner->buffer())); break; case LFUN_BUILDPROG: Exporter::Export(owner->buffer(), "program", true); + view()->showErrorList(_("Build")); break; case LFUN_RUNCHKTEX: owner->buffer()->runChktex(); + view()->showErrorList(_("ChkTeX")); break; case LFUN_EXPORT: if (argument == "custom") owner->getDialogs().showSendto(); - else + else { Exporter::Export(owner->buffer(), argument, false); + view()->showErrorList(BufferFormat(*owner->buffer())); + } break; case LFUN_IMPORT: diff --git a/src/text2.C b/src/text2.C index 311f6e3458..94ce377a9f 100644 --- a/src/text2.C +++ b/src/text2.C @@ -18,6 +18,7 @@ #include "frontends/LyXView.h" #include "undo_funcs.h" #include "buffer.h" +#include "buffer_funcs.h" #include "bufferparams.h" #include "errorlist.h" #include "gettext.h" @@ -1415,7 +1416,7 @@ void LyXText::pasteSelection(size_t sel_index) cursor.par(), cursor.pos(), bv()->buffer()->params.textclass, sel_index, el); - bv()->setErrorList(el); + parseErrors(*bv()->buffer(), el); bv()->showErrorList(_("Paste")); redoParagraphs(cursor, endpit);