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()));
|
2008-09-25 16:16:25 +00:00
|
|
|
connect(errorsLW, SIGNAL(currentRowChanged(int)),
|
2008-05-29 12:37:22 +00:00
|
|
|
this, SLOT(select()));
|
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
|
|
|
{
|
2008-05-29 12:37:22 +00:00
|
|
|
select();
|
2008-11-23 10:55:41 +00:00
|
|
|
updateContents();
|
2007-04-25 10:25:37 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-29 12:37:22 +00:00
|
|
|
void GuiErrorList::select()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-05-29 12:37:22 +00:00
|
|
|
int const item = errorsLW->row(errorsLW->currentItem());
|
2008-07-20 17:05:58 +00:00
|
|
|
if (item == -1)
|
|
|
|
return;
|
|
|
|
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));
|
2008-10-21 09:07:15 +00:00
|
|
|
errorsLW->setCurrentRow(0);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-06 10:55:47 +00:00
|
|
|
bool GuiErrorList::goTo(int item)
|
2007-10-06 14:13:25 +00:00
|
|
|
{
|
|
|
|
ErrorItem const & err = errorList()[item];
|
|
|
|
|
|
|
|
if (err.par_id == -1)
|
2008-07-06 10:55:47 +00:00
|
|
|
return false;
|
2007-10-06 14:13:25 +00:00
|
|
|
|
2008-09-29 10:52:17 +00:00
|
|
|
Buffer const & 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-11-17 11:46:07 +00:00
|
|
|
if (dit == doc_iterator_end(&buf)) {
|
2008-07-06 10:55:47 +00:00
|
|
|
// FIXME: Happens when loading a read-only doc with
|
|
|
|
// unknown layout. Should this be the case?
|
2007-11-28 22:12:03 +00:00
|
|
|
LYXERR0("par id " << err.par_id << " not found");
|
2008-07-06 10:55:47 +00:00
|
|
|
return false;
|
2007-10-06 14:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2008-09-29 10:52:17 +00:00
|
|
|
BufferView * bv = const_cast<BufferView *>(bufferview());
|
2007-10-10 08:52:55 +00:00
|
|
|
// FIXME: If we used an LFUN, we would not need this line:
|
2008-09-29 10:52:17 +00:00
|
|
|
bv->putSelectionAt(dit, range, false);
|
|
|
|
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
2008-07-06 10:56:47 +00:00
|
|
|
return true;
|
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
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiErrorList.cpp"
|