2003-05-13 21:15:48 +00:00
|
|
|
/**
|
|
|
|
* \file ControlErrorList.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ControlErrorList.h"
|
|
|
|
#include "support/lstrings.h" // tostr
|
|
|
|
#include "LaTeX.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "lyxtext.h"
|
2003-05-13 23:12:45 +00:00
|
|
|
#include "debug.h"
|
2003-05-13 21:15:48 +00:00
|
|
|
|
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
using std::endl;
|
2003-05-13 21:15:48 +00:00
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
|
|
|
|
ControlErrorList::ErrorItem::ErrorItem(string const & error,
|
|
|
|
string const & description,
|
|
|
|
int par_id, int pos_start, int pos_end)
|
|
|
|
: error(error), description(description), par_id(par_id),
|
2003-05-13 21:15:48 +00:00
|
|
|
pos_start(pos_start), pos_end(pos_end)
|
|
|
|
{}
|
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
|
|
|
|
ControlErrorList::ControlErrorList(Dialog & d)
|
2003-05-13 21:15:48 +00:00
|
|
|
: Dialog::Controller(d), current_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
void ControlErrorList::clearParams()
|
2003-05-13 21:15:48 +00:00
|
|
|
{
|
2003-05-14 09:36:52 +00:00
|
|
|
logfilename_.erase();
|
2003-05-13 21:15:48 +00:00
|
|
|
clearErrors();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
std::vector<ControlErrorList::ErrorItem> const &
|
2003-05-13 21:15:48 +00:00
|
|
|
ControlErrorList::ErrorList() const
|
|
|
|
{
|
|
|
|
return ErrorList_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ControlErrorList::currentItem() const
|
|
|
|
{
|
|
|
|
return current_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
bool ControlErrorList::initialiseParams(string const &)
|
2003-05-13 21:15:48 +00:00
|
|
|
{
|
|
|
|
logfilename_ = kernel().buffer()->getLogName().second;
|
|
|
|
clearErrors();
|
|
|
|
fillErrors();
|
|
|
|
current_ = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlErrorList::clearErrors()
|
|
|
|
{
|
|
|
|
ErrorList_.clear();
|
|
|
|
current_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlErrorList::fillErrors()
|
|
|
|
{
|
|
|
|
LaTeX latex("", logfilename_, "");
|
|
|
|
TeXErrors terr;
|
|
|
|
latex.scanLogFile(terr);
|
|
|
|
|
|
|
|
Buffer * const buf = kernel().buffer();
|
|
|
|
|
|
|
|
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);
|
|
|
|
ErrorList_.push_back(ErrorItem(cit->error_desc,
|
|
|
|
cit->error_text,
|
|
|
|
par_id, posstart, posend));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const & ControlErrorList::docName()
|
|
|
|
{
|
|
|
|
return kernel().buffer()->fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlErrorList::goTo(int item)
|
|
|
|
{
|
|
|
|
BufferView * const bv = kernel().bufferview();
|
|
|
|
Buffer * const buf = kernel().buffer();
|
|
|
|
|
|
|
|
current_ = item;
|
|
|
|
|
|
|
|
ControlErrorList::ErrorItem const & err = ErrorList_[item];
|
|
|
|
|
|
|
|
|
|
|
|
if (err.par_id == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ParagraphList::iterator pit = buf->getParFromID(err.par_id);
|
|
|
|
|
|
|
|
if (pit == bv->text->ownerParagraphs().end()) {
|
2003-05-13 23:12:45 +00:00
|
|
|
lyxerr << "par id not found" << endl;
|
2003-05-13 21:15:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int range = err.pos_end - err.pos_start;
|
|
|
|
|
|
|
|
if (err.pos_end > pit->size() || range <= 0)
|
|
|
|
range = pit->size() - err.pos_start;
|
|
|
|
|
2003-05-13 23:12:45 +00:00
|
|
|
// Now make the selection.
|
2003-05-13 21:15:48 +00:00
|
|
|
bv->insetUnlock();
|
|
|
|
bv->toggleSelection();
|
|
|
|
bv->text->clearSelection();
|
|
|
|
bv->text->setCursor(pit, err.pos_start);
|
|
|
|
bv->text->setSelectionRange(range);
|
|
|
|
bv->toggleSelection(false);
|
|
|
|
bv->fitCursor();
|
|
|
|
bv->update(bv->text, BufferView::SELECT);
|
|
|
|
}
|