2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiErrorList.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* 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>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiErrorList.h"
|
2007-10-06 14:13:25 +00:00
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "Text.h"
|
|
|
|
#include "ParIterator.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
// FIXME: those two headers are needed because of the
|
|
|
|
// WorkArea::redraw() call below.
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QListWidget>
|
|
|
|
#include <QTextBrowser>
|
|
|
|
#include <QPushButton>
|
2007-04-25 10:25:37 +00:00
|
|
|
#include <QCloseEvent>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
using std::endl;
|
|
|
|
using std::string;
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
using support::bformat;
|
2007-04-25 10:25:37 +00:00
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
GuiErrorList::GuiErrorList(LyXView & lv)
|
2007-10-09 19:34:27 +00:00
|
|
|
: GuiDialog(lv, "errorlist")
|
2007-04-25 10:25:37 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-04-25 10:25:37 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(slotClose()));
|
|
|
|
connect(errorsLW, SIGNAL(itemActivated(QListWidgetItem *)),
|
|
|
|
this, SLOT(slotClose()));
|
|
|
|
connect( errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
|
2007-04-25 10:25:37 +00:00
|
|
|
this, SLOT(select_adaptor(QListWidgetItem *)));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkCancelPolicy);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
void GuiErrorList::closeEvent(QCloseEvent * e)
|
2007-04-25 10:25:37 +00:00
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
slotClose();
|
2007-04-25 10:25:37 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
void GuiErrorList::showEvent(QShowEvent * e)
|
2007-04-25 10:25:37 +00:00
|
|
|
{
|
|
|
|
errorsLW->setCurrentRow(0);
|
2007-09-05 20:33:29 +00:00
|
|
|
select(errorsLW->item(0));
|
2007-04-25 10:25:37 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
void GuiErrorList::select(QListWidgetItem * wi)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
int const item = errorsLW->row(wi);
|
2007-10-06 14:13:25 +00:00
|
|
|
goTo(item);
|
|
|
|
descriptionTB->setPlainText(toqstr(errorList()[item].description));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
void GuiErrorList::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 14:13:25 +00:00
|
|
|
setViewTitle(name_);
|
2007-09-05 20:33:29 +00:00
|
|
|
errorsLW->clear();
|
|
|
|
descriptionTB->setPlainText(QString());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
ErrorList::const_iterator it = errorList().begin();
|
|
|
|
ErrorList::const_iterator end = errorList().end();
|
2007-09-05 20:33:29 +00:00
|
|
|
for (; it != end; ++it)
|
|
|
|
errorsLW->addItem(toqstr(it->error));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
|
|
|
|
ErrorList const & GuiErrorList::errorList() const
|
|
|
|
{
|
|
|
|
return bufferview()->buffer().errorList(error_type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiErrorList::initialiseParams(string const & error_type)
|
|
|
|
{
|
|
|
|
error_type_ = error_type;
|
|
|
|
Buffer const & buf = bufferview()->buffer();
|
|
|
|
name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
|
|
|
|
from_utf8(buf.fileName()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiErrorList::goTo(int item)
|
|
|
|
{
|
|
|
|
ErrorItem const & err = errorList()[item];
|
|
|
|
|
|
|
|
if (err.par_id == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Buffer & buf = buffer();
|
|
|
|
ParIterator pit = buf.getParFromID(err.par_id);
|
|
|
|
|
|
|
|
if (pit == buf.par_iterator_end()) {
|
|
|
|
lyxerr << "par id " << err.par_id << " not found" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make the selection.
|
|
|
|
// This should be implemented using an LFUN. (Angus)
|
|
|
|
// if pos_end is 0, this means it is end-of-paragraph
|
|
|
|
pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
|
|
|
|
: pit->size();
|
|
|
|
pos_type const start = std::min(err.pos_start, end);
|
|
|
|
pos_type const range = end - start;
|
|
|
|
DocIterator const dit = makeDocIterator(pit, start);
|
|
|
|
bufferview()->putSelectionAt(dit, range, false);
|
|
|
|
// FIXME: If we used an LFUN, we would not need those two lines:
|
|
|
|
bufferview()->update();
|
|
|
|
lyxview().currentWorkArea()->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog * createGuiErrorList(LyXView & lv) { return new GuiErrorList(lv); }
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 10:25:37 +00:00
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiErrorList_moc.cpp"
|