added a parseError signal to Buffer and use it

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7200 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-06-20 23:03:43 +00:00
parent 2b1a447714
commit ffb610695f
16 changed files with 91 additions and 62 deletions

View File

@ -36,7 +36,6 @@
#include "frontends/screen.h"
#include "insets/insetcommand.h" // ChangeRefs
#include "insets/inseterror.h"
#include "insets/updatableinset.h"
#include "support/FileInfo.h"
@ -349,13 +348,6 @@ void BufferView::setErrorList(ErrorList const & el)
}
void BufferView::addError(ErrorItem const & ei)
{
pimpl_->errorlist_.push_back(ei);
}
void BufferView::showErrorList(string const & action) const
{
if (getErrorList().size()) {

View File

@ -161,8 +161,6 @@ public:
void resetErrorList();
/// stored this error list
void setErrorList(ErrorList const &);
/// adds a single error to the list
void addError(ErrorItem const &);
/// show the error list to the user
void showErrorList(string const &) const;
/// set the cursor based on the given TeX source row

View File

@ -130,6 +130,12 @@ BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
}
void BufferView::Pimpl::addError(ErrorItem const & ei)
{
errorlist_.push_back(ei);
}
bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
{
@ -161,9 +167,14 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
}
Buffer * b = bufferlist.newBuffer(s);
//this is the point to attach to the error signal in the buffer
bv_->resetErrorList();
//attach to the error signal in the buffer
b->parseError.connect(boost::bind(&BufferView::Pimpl::addError,
this, _1));
if (!::loadLyXFile(b, s)) {
bool loaded = true;
if (! ::loadLyXFile(b, s)) {
bufferlist.release(b);
string text = bformat(_("The document %1$s does "
"not yet exist.\n\n"
@ -176,6 +187,8 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
bufferlist.close(buffer_, false);
buffer(newFile(s, string(), true));
}
loaded = false;
}
buffer(b);
@ -183,6 +196,9 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
if (tolastfiles)
lastfiles->newFile(b->fileName());
if (loaded)
bv_->showErrorList(_("Parse"));
return true;
}

View File

@ -109,6 +109,8 @@ struct BufferView::Pimpl : public boost::signals::trackable {
private:
/// An error list (replaces the error insets)
ErrorList errorlist_;
/// add an error to the list
void addError(ErrorItem const &);
/// track changes for the document
void trackChanges();

View File

@ -1,3 +1,11 @@
2003-06-21 Alfredo Braunstein <abraunst@libero.it>
* buffer.[Ch]: added the parseError signal and use it, removed
sgmlError
* BufferView.[Ch] (addError): moved to ...
* BufferView_pimpl.[Ch] (addError, loadLyXFile): ... here. Attach
to the Buffer::parseError signal to catch (guess what) parse errors
* lyx_main.[Ch] (printError,LyX): added gui-less parsing error feedback
2003-06-19 Alfredo Braunstein <abraunst@libero.it>

View File

@ -45,7 +45,6 @@
#include "mathed/formulamacro.h"
#include "mathed/formula.h"
#include "insets/inseterror.h"
#include "insets/insetbibitem.h"
#include "insets/insetbibtex.h"
#include "insets/insetinclude.h"
@ -280,6 +279,12 @@ int Buffer::readHeader(LyXLex & lex)
unknownClass(unknown);
} else {
++unknown_tokens;
string const s = bformat(_("Unknown token: "
"%1$s %2$s\n"),
token,
lex.getString());
parseError(ErrorItem(_("Header error"), s,
-1, 0, 0));
}
}
}
@ -297,14 +302,10 @@ int Buffer::readHeader(LyXLex & lex)
// Returns false if "\the_end" is not read (Asger)
bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
{
int unknown_tokens = 0;
Paragraph::depth_type depth = 0;
bool the_end_read = false;
if (paragraphs.empty()) {
unknown_tokens += readHeader(lex);
if (!params.getLyXTextClass().load()) {
string theclass = params.getLyXTextClass().name();
Alert::error(_("Can't load document class"), bformat(
@ -339,20 +340,7 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
continue;
}
unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
}
if (unknown_tokens > 0) {
string s;
if (unknown_tokens == 1) {
s = bformat(_("Encountered one unknown token when reading "
"the document %1$s."), fileName());
} else {
s = bformat(_("Encountered %1$s unknown tokens when reading "
"the document %2$s."), tostr(unknown_tokens), fileName());
}
Alert::warning(_("Document format failure"), s);
readParagraph(lex, token, paragraphs, pit, depth);
}
return the_end_read;
@ -360,8 +348,8 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
int Buffer::readParagraph(LyXLex & lex, string const & token,
ParagraphList & pars, ParagraphList::iterator & pit,
Paragraph::depth_type & depth)
ParagraphList & pars, ParagraphList::iterator & pit,
Paragraph::depth_type & depth)
{
static Change current_change;
int unknown = 0;
@ -376,14 +364,16 @@ int Buffer::readParagraph(LyXLex & lex, string const & token,
LyXFont f(LyXFont::ALL_INHERIT, params.language);
par.setFont(0, f);
// FIXME: goddamn InsetTabular makes us pass a Buffer
// not BufferParams
unknown += ::readParagraph(*this, par, lex);
// insert after
if (pit != pars.end())
++pit;
pit = pars.insert(pit, par);
// FIXME: goddamn InsetTabular makes us pass a Buffer
// not BufferParams
::readParagraph(*this, *pit, lex);
} else if (token == "\\begin_deeper") {
++depth;
} else if (token == "\\end_deeper") {
@ -1194,8 +1184,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
case LATEX_COMMAND:
if (depth != 0)
sgmlError(pit, 0,
_("Error: Wrong depth for LatexType Command.\n"));
parseError(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
if (!environment_stack[depth].empty()) {
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
@ -1539,14 +1528,6 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
}
// Print an error message.
void Buffer::sgmlError(ParagraphList::iterator pit, int pos,
string const & message) const
{
users->addError(ErrorItem(message, string(), pit->id(), pos, pos));
}
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
{
ofstream ofs(fname.c_str());
@ -1662,8 +1643,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
case LATEX_COMMAND:
if (depth != 0)
sgmlError(par, 0,
_("Error: Wrong depth for LatexType Command.\n"));
parseError(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
command_name = style->latexname();
@ -1952,7 +1932,7 @@ int Buffer::runChktex()
if (res == -1) {
Alert::error(_("chktex failure"),
_("Could not run chktex successfully."));
_("Could not run chktex successfully."));
} else if (res > 0) {
// Insert all errors as errors boxes
ErrorList el (*this, terr);

View File

@ -22,8 +22,10 @@
#include "ParagraphList.h"
#include "author.h"
#include "iterators.h"
#include "errorlist.h"
#include <boost/scoped_ptr.hpp>
#include <boost/signals/signal1.hpp>
class BufferView;
class LyXRC;
@ -126,6 +128,9 @@ public:
bool hasParWithID(int id) const;
public:
/// This signal is emitted when a parsing error shows up.
boost::signal1<void, ErrorItem> parseError;
/** Save file.
Takes care of auto-save files and backup file if requested.
Returns \c true if the save is successful, \c false otherwise.
@ -168,9 +173,6 @@ public:
///
void makeDocBookFile(string const & filename,
bool nice, bool only_body = false);
///
void sgmlError(ParagraphList::iterator par, int pos, string const & message) const;
/// returns the main language for the buffer (document)
Language const * getLanguage() const;
/// get l10n translated to the buffers language

View File

@ -27,8 +27,8 @@ struct ErrorItem {
int par_id;
int pos_start;
int pos_end;
ErrorItem(string const &, string const &,
int, int, int);
ErrorItem(string const & error, string const & description,
int parid, int posstart, int posend);
ErrorItem();
};

View File

@ -1,3 +1,9 @@
2003-06-21 Alfredo Braunstein <abraunst@libero.it>
* QDocumentDialog.C: header reordering to handle qt/boost "signals"
symbol clash
2003-06-20 Angus Leeming <leeming@lyx.org>
* QBibtexDialog.C (browsePressed): fix warning of comparison between

View File

@ -17,6 +17,7 @@
#include "QDocumentDialog.h"
#include "Qt2BC.h"
#include "language.h"
#include "helper_funcs.h" // getSecond()
#include "insets/insetquotes.h"
@ -46,6 +47,7 @@
#include <vector>
using std::vector;
typedef Qt2CB<ControlDocument, Qt2DB<QDocumentDialog> > base_class;

View File

@ -9,6 +9,9 @@
*/
#include <config.h>
#include "buffer.h" //*here* because of braindead qt headers's #define signals
#include "qt_helpers.h"
#include "ControlDocument.h"
@ -34,7 +37,7 @@
#include "Spacing.h"
#include "support/lstrings.h"
#include "lyxrc.h"
#include "buffer.h"
#include <qwidgetstack.h>
#include <qlistbox.h>

View File

@ -1,3 +1,7 @@
2003-06-21 Alfredo Braunstein <abraunst@libero.it>
* insetinclude.C (docbook): use parseError instead of sgmlError
2003-06-19 Alfredo Braunstein <abraunst@libero.it>
* insetinclude.C (loadIfNeeded): call ::loadLyXFile instead

View File

@ -19,6 +19,7 @@
#include "dimension.h"
#include "funcrequest.h"
#include "gettext.h"
#include "errorlist.h"
#include "intl.h"
#include "LaTeXFeatures.h"
#include "LColor.h"
@ -1517,7 +1518,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
break;
case LATEX_COMMAND:
buf->sgmlError(pit, 0, _("Error: LatexType Command not allowed here.\n"));
buf->parseError(ErrorItem(_("Error"), _("LatexType Command not allowed here.\n"), pit->id(), 0, pit->size()));
return -1;
break;

View File

@ -41,9 +41,12 @@
#include "frontends/lyx_gui.h"
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/signals/signal1.hpp>
#include <cstdlib>
#include <csignal>
#include <iostream>
using std::vector;
using std::endl;
@ -144,6 +147,7 @@ LyX::LyX(int & argc, char * argv[])
vector<string>::iterator end = files.end();
for (; it != end; ++it) {
last_loaded = bufferlist.newBuffer(*it, false);
last_loaded->parseError.connect(boost::bind(&LyX::printError, this, _1));
loadLyXFile(last_loaded, *it);
}
@ -215,6 +219,14 @@ static void error_handler(int err_sig)
}
void LyX::printError(ErrorItem const & ei)
{
std::cerr << _("LyX: ") << ei.error
<< ':' << ei.description << std::endl;
}
void LyX::init(bool gui)
{
signal(SIGHUP, error_handler);

View File

@ -11,12 +11,14 @@
#define LYX_MAIN_H
#include "LString.h"
#include "errorlist.h"
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
#include <csignal>
class LyXRC;
class LastFiles;
class Buffer;
@ -60,6 +62,8 @@ private:
void readEncodingsFile(string const & name);
/// parsing of non-gui LyX options. Returns true if gui
bool easyParse(int & argc, char * argv[]);
/// shows up a parsing error on screen
void printError(ErrorItem const &);
/// has this user started lyx for the first time?
bool first_start;

View File

@ -32,7 +32,6 @@
#include "insets/insetlatexaccent.h"
#include "insets/insettabular.h"
#include "insets/insethfill.h"
#include "insets/inseterror.h"
#include "insets/insetnewline.h"
extern string bibitemWidest(Buffer const *);
@ -1007,9 +1006,9 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
lex.eatLine();
string const s = bformat(_("Unknown token: %1$s %2$s\n"),
token, lex.getString());
// we can do this here this way because we're actually reading
// the buffer and don't care about LyXText right now.
par.insertInset(par.size(), new InsetError(s), font);
buf.parseError(ErrorItem(_("Unknown token"), s,
par.id(), 0, par.size()));
return 1;
}
return 0;