#include "CutAndPaste.h"
#include "debug.h"
#include "dispatchresult.h"
+#include "errorlist.h"
#include "factory.h"
#include "FloatList.h"
#include "funcrequest.h"
}
setBuffer(b);
- owner_->showErrorList(_("Parse"));
+ // Send the "errors" signal in case of parsing errors
+ b->errors("Parse");
// scroll to the position when the file was last closed
if (lyxrc.use_lastfilepos) {
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))) {
+ ErrorList & el = buffer_->errorList("Parse");
+ // Copy the inserted document error list into the current buffer one.
+ el = buf.errorList("Parse");
lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(),
- buf.params().textclass);
+ buf.params().textclass, el);
res = _("Document %1$s inserted.");
} else
res = _("Could not insert document %1$s");
owner_->message(bformat(res, disp_fn));
- owner_->showErrorList(_("Document insertion"));
+ buffer_->errors("Parse");
resizeCurrentBuffer();
}
void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
- textclass_type textclass)
+ textclass_type textclass, ErrorList & errorList)
{
if (cur.inTexted()) {
LyXText * text = cur.text();
pit_type endpit;
PitPosPair ppp;
- ErrorList el;
boost::tie(ppp, endpit) =
pasteSelectionHelper(cur.buffer(),
text->paragraphs(),
cur.pit(), cur.pos(),
parlist, textclass,
- el);
- bufferErrors(cur.buffer(), el);
+ errorList);
updateLabels(cur.buffer());
cur.clearSelection();
text->setCursor(cur, ppp.first, ppp.second);
}
-void pasteSelection(LCursor & cur, size_t sel_index)
+void pasteSelection(LCursor & cur, ErrorList & errorList, size_t sel_index)
{
// this does not make sense, if there is nothing to paste
if (!checkPastePossible(sel_index))
return;
pasteParagraphList(cur, theCuts[sel_index].first,
- theCuts[sel_index].second);
- cur.bv().owner()->showErrorList(_("Paste"));
+ theCuts[sel_index].second, errorList);
cur.setSelection();
}
///
void copySelection(LCursor & cur);
///
-void pasteSelection(LCursor & cur, size_t sel_index = 0);
+void pasteSelection(LCursor & cur, ErrorList &, size_t sel_index = 0);
///
void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
- textclass_type textclass);
+ textclass_type textclass, ErrorList & errorList);
/** Needed to switch between different classes. This works
#include "Chktex.h"
#include "debug.h"
#include "encoding.h"
+#include "errorlist.h"
#include "exporter.h"
#include "format.h"
#include "funcrequest.h"
params().headsep.erase();
params().footskip.erase();
+ ErrorList & errorList = errorLists_["Parse"];
+
while (lex.isOK()) {
lex.next();
string const token = lex.getString();
"%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));
}
// 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));
}
params().textclass = 0;
}
- bool const res = text().read(*this, lex);
+ bool const res = text().read(*this, lex, errorList);
for_each(text().paragraphs().begin(),
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;
}
Alert::error(_("chktex failure"),
_("Could not run chktex successfully."));
} else if (res > 0) {
- // Insert all errors as errors boxes
- bufferErrors(*this, terr);
+ // Fill-in the error list with the TeX errors
+ bufferErrors(*this, terr, errorLists_["ChkTex"]);
}
busy(false);
+ errors("ChkTeX");
+
return res;
}
}
-ErrorList const & Buffer::getErrorList() const
+ErrorList const & Buffer::errorList(string const & type) const
{
- return errorList_;
-}
+ std::map<std::string, ErrorList>::const_iterator I = errorLists_.find(type);
+ if (I == errorLists_.end())
+ return emptyErrorList_;
-
-void Buffer::setErrorList(ErrorList const & errorList) const
-{
- errorList_ = errorList;
+ return I->second;
}
-void Buffer::addError(ErrorItem const & errorItem) const
+ErrorList & Buffer::errorList(string const & type)
{
- errorList_.push_back(errorItem);
+ std::map<std::string, ErrorList>::iterator I = errorLists_.find(type);
+ if (I == errorLists_.end()) {
+ errorLists_[type] = emptyErrorList_;
+ return errorLists_[type];
+ }
+
+ return I->second;
}
/// including preamble
void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source);
- /// 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;
+ /// errorLists_ accessors.
+ //@{
+ ErrorList const & errorList(std::string const & type) const;
+ ErrorList & errorList(std::string const & type);
+ //@}
private:
/** Inserts a file into a document
/// 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_;
+ /// Container for all sort of Buffer dependant errors.
+ std::map<std::string, ErrorList> errorLists_;
+
+ /// Empty Error List
+ ErrorList const emptyErrorList_;
};
#endif
}
-void bufferErrors(Buffer const & buf, TeXErrors const & terr)
+void bufferErrors(Buffer const & buf, TeXErrors const & terr,
+ ErrorList & errorList)
{
TeXErrors::Errors::const_iterator cit = terr.begin();
TeXErrors::Errors::const_iterator end = terr.end();
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())
///return the format of the buffer on a string
std::string const bufferFormat(Buffer const & buffer);
-///
-void bufferErrors(Buffer const &, TeXErrors const &);
-///
-void bufferErrors(Buffer const &, ErrorList const &);
+
+/// Fill in the ErrorList with the TeXErrors
+void bufferErrors(Buffer const &, TeXErrors const &, ErrorList &);
/// Count the number of words in the text between these two iterators
int countWords(DocIterator const & from, DocIterator const & to);
bool Converters::convert(Buffer const * buffer,
string const & from_file, string const & to_file_base,
string const & from_format, string const & to_format,
- string & to_file, bool try_default)
+ string & to_file, ErrorList & errorList, bool try_default)
{
string const to_ext = formats.extension(to_format);
to_file = changeExtension(to_file_base, to_ext);
runparams.flavor = getFlavor(edgepath);
string path = onlyPath(from_file);
Path p(path);
+ // empty the error list before any new conversion takes place.
+ errorList.clear();
bool run_latex = false;
string from_base = changeExtension(from_file, "");
run_latex = true;
string const command = subst(conv.command, token_from, "");
lyxerr[Debug::FILES] << "Running " << command << endl;
- if (!runLaTeX(*buffer, command, runparams))
+ if (!runLaTeX(*buffer, command, runparams, errorList))
return false;
} else {
if (conv.need_aux && !run_latex
lyxerr[Debug::FILES]
<< "Running " << latex_command_
<< " to update aux file"<< endl;
- runLaTeX(*buffer, latex_command_, runparams);
+ runLaTeX(*buffer, latex_command_, runparams, errorList);
}
string const infile2 = (conv.original_dir)
" < " + quoteName(infile2 + ".out") +
" > " + quoteName(logfile);
one.startscript(Systemcall::Wait, command2);
- if (!scanLog(*buffer, command, logfile))
+ if (!scanLog(*buffer, command, logfile, errorList))
return false;
}
bool Converters::convert(Buffer const * buffer,
string const & from_file, string const & to_file_base,
string const & from_format, string const & to_format,
- bool try_default)
+ ErrorList & errorList, bool try_default)
{
string to_file;
return convert(buffer, from_file, to_file_base, from_format, to_format,
- to_file, try_default);
+ to_file, errorList, try_default);
}
bool Converters::scanLog(Buffer const & buffer, string const & /*command*/,
- string const & filename)
+ string const & filename, ErrorList & errorList)
{
OutputParams runparams;
runparams.flavor = OutputParams::LATEX;
int const result = latex.scanLogFile(terr);
if (result & LaTeX::ERRORS)
- bufferErrors(buffer, terr);
+ bufferErrors(buffer, terr, errorList);
return true;
}
bool Converters::runLaTeX(Buffer const & buffer, string const & command,
- OutputParams const & runparams)
+ OutputParams const & runparams, ErrorList & errorList)
{
buffer.busy(true);
buffer.message(_("Running LaTeX..."));
int const result = latex.run(terr);
if (result & LaTeX::ERRORS)
- bufferErrors(buffer, terr);
+ bufferErrors(buffer, terr, errorList);
// check return value from latex.run().
if ((result & LaTeX::NO_LOGFILE)) {
class Buffer;
+class ErrorList;
class Format;
class Formats;
class OutputParams;
bool convert(Buffer const * buffer,
std::string const & from_file, std::string const & to_file_base,
std::string const & from_format, std::string const & to_format,
- std::string & to_file, bool try_default = false);
+ std::string & to_file, ErrorList & errorList,
+ bool try_default = false);
///
bool convert(Buffer const * buffer,
std::string const & from_file, std::string const & to_file_base,
std::string const & from_format, std::string const & to_format,
- bool try_default = false);
+ ErrorList & errorList, bool try_default = false);
///
void update(Formats const & formats);
///
intToFormat(std::vector<int> const & input);
///
bool scanLog(Buffer const & buffer, std::string const & command,
- std::string const & filename);
+ std::string const & filename, ErrorList & errorList);
///
bool runLaTeX(Buffer const & buffer, std::string const & command,
- OutputParams const &);
+ OutputParams const &, ErrorList & errorList);
///
ConverterList converterlist_;
///
buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
}
- if (!converters.convert(buffer, filename, filename,
- backend_format, format, result_file))
+ string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
+ bool const success = converters.convert(buffer, filename, filename,
+ backend_format, format, result_file,
+ buffer->errorList(error_type));
+ // Emit the signal to show the error list.
+ buffer->errors(error_type);
+ if (!success)
return false;
if (!put_in_tempdir) {
#include "bufferview_funcs.h"
#include "cursor.h"
#include "debug.h"
+#include "errorlist.h"
#include "funcrequest.h"
#include "gettext.h"
#include "intl.h"
disconnectBuffer();
bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
+ showErrorList("Parse");
+
updateMenubar();
updateToolbars();
updateLayoutChoice();
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(
boost::bind(&LyXView::showErrorList, this, _1));
}
-void LyXView::showErrorList(string const & action)
+void LyXView::showErrorList(string const & error_type)
{
- 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 & el = buffer()->errorList(error_type);
+ if (!el.empty()) {
+ getDialogs().show("errorlist", error_type);
}
}
#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;
}
-bool ControlErrorList::initialiseParams(string const & name)
+bool ControlErrorList::initialiseParams(string const & error_type)
{
- errorlist_ = kernel().bufferview()->buffer()->getErrorList();
- name_ = name;
+ Buffer * buf = kernel().bufferview()->buffer();
+ string const title = bformat(_("%1$s Errors (%2$s)"),
+ _(error_type), buf->fileName());
+ errorlist_ = buf->errorList(error_type);
+ name_ = title;
return true;
}
bool Importer::Import(LyXView * lv, string const & filename,
- string const & format)
+ string const & format, ErrorList & errorList)
{
string const displaypath = makeDisplayPath(filename);
lv->message(bformat(_("Importing %1$s..."), displaypath));
it != loaders.end(); ++it) {
if (converters.isReachable(format, *it)) {
if (!converters.convert(0, filename, filename,
- format, *it))
+ format, *it, errorList))
return false;
loader_format = *it;
break;
class LyXView;
+class ErrorList;
class Format;
class Importer {
///
static
bool Import(LyXView * lv, std::string const & filename,
- std::string const & format);
+ std::string const & format, ErrorList & errorList);
///
static
return; // SUCCESS
string const to_file_base =
support::changeExtension(to_file, string());
+
+ // FIXME (Abdel 12/08/06): Is there a need to show these errors?
+ ErrorList el;
/* bool const success = */
converters.convert(&buffer, temp_file, to_file_base,
- from_format, to_format, true);
+ from_format, to_format, el, true);
// return success
}
<< "\tfile to convert = " << temp_file << '\n'
<< "\t from " << from << " to " << to << '\n';
- if (converters.convert(&buf, temp_file, temp_file, from, to, true)) {
+ // FIXME (Abdel 12/08/06): Is there a need to show these errors?
+ ErrorList el;
+ if (converters.convert(&buf, temp_file, temp_file, from, to, el, true)) {
runparams.exportdata->addExternalFile(tex_format,
to_file, output_to_file);
runparams.exportdata->addExternalFile("dvi",
// delete the initial paragraph
Paragraph oldpar = *paragraphs().begin();
paragraphs().clear();
- bool res = text_.read(buf, lex);
+ ErrorList errorList;
+ bool res = text_.read(buf, lex, errorList);
init();
if (!res) {
last_loaded = b;
} else {
Buffer * buf = bufferlist.newBuffer(s, false);
- if (loadLyXFile(buf, s))
+ 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);
+ ErrorList const & el = buf->errorList("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);
}
}
case LFUN_BUFFER_UPDATE:
Exporter::Export(owner->buffer(), argument, true);
- owner->showErrorList(bufferFormat(*owner->buffer()));
break;
case LFUN_BUFFER_VIEW:
Exporter::preview(owner->buffer(), argument);
- owner->showErrorList(bufferFormat(*owner->buffer()));
break;
case LFUN_BUILD_PROGRAM:
Exporter::Export(owner->buffer(), "program", true);
- owner->showErrorList(_("Build"));
break;
case LFUN_BUFFER_CHKTEX:
owner->buffer()->runChktex();
- owner->showErrorList(_("ChkTeX"));
break;
case LFUN_BUFFER_EXPORT:
owner->getDialogs().show("sendto");
else {
Exporter::Export(owner->buffer(), argument, false);
- owner->showErrorList(bufferFormat(*owner->buffer()));
}
break;
break;
} else {
- Exporter::Export(buffer, format_name, true,
- filename);
+ Exporter::Export(buffer, format_name, true, filename);
}
// Substitute $$FName for filename
recordUndoFullDocument(view());
buffer->params().textclass = new_class;
StableDocIterator backcur(view()->cursor());
- ErrorList el;
+ ErrorList & el = buffer->errorList("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"));
+
+ buffer->errors("Class Switch");
updateLabels(*buffer);
updateforce = true;
break;
}
}
- Importer::Import(owner, filename, format);
+ ErrorList errorList;
+ Importer::Import(owner, filename, format, errorList);
+ // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
}
class BufferView;
class CursorSlice;
class Dimension;
+class ErrorList;
class InsetBase;
class InsetBase_code;
class FuncRequest;
///
void write(Buffer const & buf, std::ostream & os) const;
/// returns whether we've seen our usual 'end' marker
- bool read(Buffer const & buf, LyXLex & lex);
+ bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
///
int ascent() const;
void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
- string const & token, LyXFont & font, Change & change)
+ string const & token, LyXFont & font, Change & change, ErrorList & errorList)
{
BufferParams const & bp = buf.params();
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();
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") {
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()));
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()));
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()));
}
}
-void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
+void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex, ErrorList & errorList)
{
lex.nextToken();
string token = lex.getString();
while (lex.isOK()) {
- readParToken(buf, par, lex, token, font, change);
+ readParToken(buf, par, lex, token, font, change, errorList);
lex.nextToken();
token = lex.getString();
}
-bool LyXText::read(Buffer const & buf, LyXLex & lex)
+bool LyXText::read(Buffer const & buf, LyXLex & lex, ErrorList & errorList)
{
Paragraph::depth_type depth = 0;
// FIXME: goddamn InsetTabular makes us pass a Buffer
// not BufferParams
- ::readParagraph(buf, pars_.back(), lex);
+ ::readParagraph(buf, pars_.back(), lex, errorList);
} else if (token == "\\begin_deeper") {
++depth;
#include "CutAndPaste.h"
#include "debug.h"
#include "dispatchresult.h"
+#include "errorlist.h"
#include "factory.h"
#include "funcrequest.h"
#include "gettext.h"
cur.setSelection();
if (content) {
lyx::cap::replaceSelection(cur);
- pasteSelection(cur, 0);
+ pasteSelection(cur, bv->buffer()->errorList("Paste"), 0);
cur.clearSelection();
// restore position
cur.pit() = std::min(cur.lastpit(), spit);
cur.message(_("Paste"));
lyx::cap::replaceSelection(cur);
if (isStrUnsignedInt(cmd.argument))
- pasteSelection(cur, convert<unsigned int>(cmd.argument));
+ pasteSelection(cur, bv->buffer()->errorList("Paste"),
+ convert<unsigned int>(cmd.argument));
else
- pasteSelection(cur, 0);
+ pasteSelection(cur, bv->buffer()->errorList("Paste"),
+ 0);
+ bv->buffer()->errors("Paste");
cur.clearSelection(); // bug 393
bv->switchKeyMap();
finishUndo();