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
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "ParIterator.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "Text.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2007-10-06 14:13:25 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
2008-02-18 09:55:14 +00:00
|
|
|
#include <QShowEvent>
|
|
|
|
#include <QTextBrowser>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiErrorList::GuiErrorList(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: GuiDialog(lv, "errorlist", qt_("Error List"))
|
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()));
|
2007-10-30 20:22:50 +00:00
|
|
|
connect(errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
|
2007-10-10 16:57:05 +00:00
|
|
|
this, SLOT(select(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::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
|
|
|
{
|
2008-02-05 12:43:19 +00:00
|
|
|
setTitle(toqstr(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),
|
2007-10-20 10:03:45 +00:00
|
|
|
from_utf8(buf.absFileName()));
|
2007-10-06 14:13:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiErrorList::goTo(int item)
|
|
|
|
{
|
|
|
|
ErrorItem const & err = errorList()[item];
|
|
|
|
|
|
|
|
if (err.par_id == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Buffer & buf = buffer();
|
2008-02-09 15:23:05 +00:00
|
|
|
DocIterator dit = buf.getParFromID(err.par_id);
|
2007-10-06 14:13:25 +00:00
|
|
|
|
2008-02-09 15:23:05 +00:00
|
|
|
if (dit == doc_iterator_end(buf.inset())) {
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR0("par id " << err.par_id << " not found");
|
2007-10-06 14:13:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make the selection.
|
|
|
|
// if pos_end is 0, this means it is end-of-paragraph
|
2008-02-09 15:23:05 +00:00
|
|
|
pos_type const s = dit.paragraph().size();
|
|
|
|
pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
|
2007-12-12 19:28:07 +00:00
|
|
|
pos_type const start = min(err.pos_start, end);
|
2007-10-06 14:13:25 +00:00
|
|
|
pos_type const range = end - start;
|
2008-02-09 15:23:05 +00:00
|
|
|
dit.pos() = start;
|
2007-10-06 14:13:25 +00:00
|
|
|
bufferview()->putSelectionAt(dit, range, false);
|
2007-10-10 08:52:55 +00:00
|
|
|
// FIXME: If we used an LFUN, we would not need this line:
|
|
|
|
bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
|
2007-10-06 14:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
|
2007-10-06 14:13:25 +00:00
|
|
|
|
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"
|