This patch make further errorlist-related cleaning:
- eliminates BufferView::resetErrorList, making an automatic reset with
every dialog show.
- eliminates BufferView::setErrorList, making the callers use the parseError
signal (added a couple of buffer_funcs helpers).
- removed calls to bv->showErrorList out of Buffer and Exporter, making the
callers do it instead (lyxfunc basically)
- moved Exporter::BufferFormat to buffer_funcs
- moved Exporter::Backends to anon namespace
Please comment.
Alfredo
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.162
diff -u -p -u -r1.162 BufferView.C
--- BufferView.C 20 Jun 2003 23:03:40 -0000 1.162
+++ BufferView.C 24 Jun 2003 18:19:39 -0000
@@ -336,18 +336,6 @@ bool BufferView::insertLyXFile(string co
}
-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();
}
Index: BufferView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v
retrieving revision 1.127
diff -u -p -u -r1.127 BufferView.h
--- BufferView.h 20 Jun 2003 23:03:40 -0000 1.127
+++ BufferView.h 24 Jun 2003 18:19:39 -0000
@@ -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
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.378
diff -u -p -u -r1.378 BufferView_pimpl.C
--- BufferView_pimpl.C 20 Jun 2003 23:03:40 -0000 1.378
+++ BufferView_pimpl.C 24 Jun 2003 18:19:41 -0000
@@ -167,14 +167,13 @@ bool BufferView::Pimpl::loadLyXFile(stri
}
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(stri
bufferlist.close(buffer_, false);
buffer(newFile(s, string(), true));
}
-
- loaded = false;
}
buffer(b);
Index: buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.486
diff -u -p -u -r1.486 buffer.C
--- buffer.C 22 Jun 2003 18:08:49 -0000 1.486
+++ buffer.C 24 Jun 2003 18:19:45 -0000
@@ -11,6 +11,7 @@
#include <config.h>
#include "buffer.h"
+#include "buffer_funcs.h"
#include "bufferlist.h"
#include "LyXAction.h"
#include "lyxrc.h"
@@ -1146,8 +1147,6 @@ void Buffer::makeLinuxDocFile(string con
string item_name;
vector<string> 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 con
// we want this to be true outside previews (for insetexternal)
niceFile = true;
-
- users->showErrorList(_("LinuxDoc"));
}
@@ -1594,8 +1591,6 @@ void Buffer::makeDocBookFile(string cons
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 cons
// 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);
Index: buffer_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer_funcs.C,v
retrieving revision 1.1
diff -u -p -u -r1.1 buffer_funcs.C
--- buffer_funcs.C 20 Jun 2003 12:46:24 -0000 1.1
+++ buffer_funcs.C 24 Jun 2003 18:19:45 -0000
@@ -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"
@@ -193,4 +195,46 @@ Buffer * newFile(string const & filename
b->updateDocLang(b->params.language);
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";
}
Index: buffer_funcs.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer_funcs.h,v
retrieving revision 1.1
diff -u -p -u -r1.1 buffer_funcs.h
--- buffer_funcs.h 20 Jun 2003 12:46:24 -0000 1.1
+++ buffer_funcs.h 24 Jun 2003 18:19:45 -0000
@@ -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
*/
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
Index: converter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.C,v
retrieving revision 1.76
diff -u -p -u -r1.76 converter.C
--- converter.C 24 May 2003 11:54:09 -0000 1.76
+++ converter.C 24 Jun 2003 18:19:46 -0000
@@ -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 *
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 *
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)) {
Index: errorlist.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/errorlist.C,v
retrieving revision 1.1
diff -u -p -u -r1.1 errorlist.C
--- errorlist.C 20 May 2003 16:51:27 -0000 1.1
+++ errorlist.C 24 Jun 2003 18:19:46 -0000
@@ -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));
- }
-}
Index: errorlist.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/errorlist.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 errorlist.h
--- errorlist.h 20 Jun 2003 23:03:41 -0000 1.3
+++ errorlist.h 24 Jun 2003 18:19:46 -0000
@@ -18,7 +18,6 @@
#include <vector>
class Buffer;
-class TeXErrors;
/// A class to hold an error item
struct ErrorItem {
@@ -36,7 +35,6 @@ class ErrorList : private std::vector<Er
{
public:
ErrorList() : std::vector<ErrorItem> () {};
- ErrorList(Buffer const & buf, TeXErrors const &);
using std::vector<ErrorItem>::push_back;
using std::vector<ErrorItem>::end;
Index: exporter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/exporter.C,v
retrieving revision 1.35
diff -u -p -u -r1.35 exporter.C
--- exporter.C 23 May 2003 09:50:38 -0000 1.35
+++ exporter.C 24 Jun 2003 18:19:47 -0000
@@ -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<string> const Backends(Buffer const * buffer)
+{
+ vector<string> 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 co
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<string> const Exporter::Backends(Buffer const * buffer)
-{
- vector<string> v;
- if (buffer->params.getLyXTextClass().isTeXClassAvailable())
- v.push_back(BufferFormat(buffer));
- v.push_back("text");
- return v;
-}
Index: exporter.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/exporter.h,v
retrieving revision 1.13
diff -u -p -u -r1.13 exporter.h
--- exporter.h 13 Feb 2003 16:52:27 -0000 1.13
+++ exporter.h 24 Jun 2003 18:19:47 -0000
@@ -39,11 +39,5 @@ public:
std::vector<Format const *> const
GetExportableFormats(Buffer const * buffer, bool only_viewable);
///
-private:
- static
- string const BufferFormat(Buffer const * buffer);
- ///
- static
- std::vector<string> const Backends(Buffer const * buffer);
};
#endif
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.456
diff -u -p -u -r1.456 lyxfunc.C
--- lyxfunc.C 20 Jun 2003 12:46:25 -0000 1.456
+++ lyxfunc.C 24 Jun 2003 18:19:49 -0000
@@ -1094,25 +1094,31 @@ void LyXFunc::dispatch(FuncRequest const
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:
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.372
diff -u -p -u -r1.372 text2.C
--- text2.C 18 Jun 2003 17:43:48 -0000 1.372
+++ text2.C 24 Jun 2003 18:19:53 -0000
@@ -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_
cursor.par(), cursor.pos(),
bv()->buffer()->params.textclass,
sel_index, el);
- bv()->setErrorList(el);
+ parseErrors(*bv()->buffer(), el);
bv()->showErrorList(_("Paste"));
redoParagraphs(cursor, endpit);
Index: frontends/controllers/ControlDocument.C
===================================================================
RCS file:
/usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlDocument.C,v
retrieving revision 1.24
diff -u -p -u -r1.24 ControlDocument.C
--- frontends/controllers/ControlDocument.C 6 Jun 2003 14:47:43 -0000 1.24
+++ frontends/controllers/ControlDocument.C 24 Jun 2003 18:19:53 -0000
@@ -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"));
}