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
|
|
|
|
2010-03-12 15:06:13 +00:00
|
|
|
#include "GuiView.h"
|
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"
|
2009-11-14 15:52:54 +00:00
|
|
|
#include "FuncRequest.h"
|
2015-03-31 22:54:49 +00:00
|
|
|
#include "FuncStatus.h"
|
2010-03-12 15:06:13 +00:00
|
|
|
#include "BufferList.h"
|
2015-03-31 22:54:49 +00:00
|
|
|
#include "LyX.h"
|
2007-10-06 14:13:25 +00:00
|
|
|
#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
|
|
|
|
2010-03-12 13:47:28 +00:00
|
|
|
namespace {
|
|
|
|
|
2014-07-05 17:13:10 +00:00
|
|
|
string const guiErrorType(string const & s)
|
2010-03-12 13:47:28 +00:00
|
|
|
{
|
|
|
|
if (s == "docbook")
|
|
|
|
return N_("DocBook");
|
|
|
|
else if (s == "literate")
|
|
|
|
return N_("Literate");
|
|
|
|
else if (s == "platex")
|
|
|
|
return N_("pLaTeX");
|
2016-07-10 09:14:03 +00:00
|
|
|
else if (s == "latex" || "xetex")
|
|
|
|
// All LaTeX variants except pLaTeX
|
|
|
|
// (LaTeX, PDFLaTeX, XeTeX, LuaTeX)
|
2010-03-12 13:47:28 +00:00
|
|
|
return N_("LaTeX");
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiErrorList::GuiErrorList(GuiView & lv)
|
2016-06-09 14:58:13 +00:00
|
|
|
: GuiDialog(lv, "errorlist", qt_("Error List")), from_master_(false)
|
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()));
|
2009-11-14 15:52:54 +00:00
|
|
|
connect(viewLogPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(viewLog()));
|
2015-03-31 22:54:49 +00:00
|
|
|
connect(showAnywayPB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(showAnyway()));
|
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();
|
2009-11-28 00:52:08 +00:00
|
|
|
paramsToDialog();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 15:52:54 +00:00
|
|
|
void GuiErrorList::viewLog()
|
|
|
|
{
|
2010-03-12 15:06:13 +00:00
|
|
|
if (&buffer() != buf_) {
|
|
|
|
if (!theBufferList().isLoaded(buf_))
|
|
|
|
return;
|
|
|
|
FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName());
|
|
|
|
dispatch(fr);
|
|
|
|
}
|
2009-11-14 15:52:54 +00:00
|
|
|
dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-31 22:54:49 +00:00
|
|
|
void GuiErrorList::showAnyway()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_BUFFER_VIEW_CACHE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-28 00:52:08 +00:00
|
|
|
void GuiErrorList::paramsToDialog()
|
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
|
|
|
|
2010-03-13 11:39:50 +00:00
|
|
|
ErrorList const & el = errorList();
|
|
|
|
ErrorList::const_iterator it = el.begin();
|
2010-03-13 16:55:59 +00:00
|
|
|
ErrorList::const_iterator const en = el.end();
|
|
|
|
for (; it != en; ++it)
|
2007-09-05 20:33:29 +00:00
|
|
|
errorsLW->addItem(toqstr(it->error));
|
2008-10-21 09:07:15 +00:00
|
|
|
errorsLW->setCurrentRow(0);
|
2015-04-05 08:50:30 +00:00
|
|
|
showAnywayPB->setEnabled(
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_BUFFER_VIEW_CACHE)).enabled());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
|
|
|
|
ErrorList const & GuiErrorList::errorList() const
|
|
|
|
{
|
2011-03-03 13:57:46 +00:00
|
|
|
Buffer const * buffer = from_master_
|
|
|
|
? bufferview()->buffer().masterBuffer()
|
|
|
|
: &bufferview()->buffer();
|
|
|
|
if (buffer == buf_)
|
|
|
|
error_list_ = buffer->errorList(error_type_);
|
|
|
|
|
2010-03-12 15:06:13 +00:00
|
|
|
return error_list_;
|
2007-10-06 14:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-21 12:26:41 +00:00
|
|
|
bool GuiErrorList::initialiseParams(string const & data)
|
2007-10-06 14:13:25 +00:00
|
|
|
{
|
2009-06-21 12:26:41 +00:00
|
|
|
from_master_ = prefixIs(data, "from_master|");
|
|
|
|
string error_type = data;
|
|
|
|
if (from_master_)
|
|
|
|
error_type = split(data, '|');
|
2007-10-06 14:13:25 +00:00
|
|
|
error_type_ = error_type;
|
2010-03-12 15:06:13 +00:00
|
|
|
buf_ = from_master_ ?
|
2009-06-21 12:26:41 +00:00
|
|
|
bufferview()->buffer().masterBuffer()
|
|
|
|
: &bufferview()->buffer();
|
2010-03-12 13:47:28 +00:00
|
|
|
name_ = bformat(_("%1$s Errors (%2$s)"),
|
|
|
|
_(guiErrorType(error_type)),
|
2010-03-12 15:06:13 +00:00
|
|
|
from_utf8(buf_->absFileName()));
|
2009-11-28 00:52:08 +00:00
|
|
|
paramsToDialog();
|
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
|
|
|
|
2011-03-04 13:37:14 +00:00
|
|
|
Buffer const * errbuf = err.buffer ? err.buffer : buf_;
|
|
|
|
|
|
|
|
if (&buffer() != errbuf) {
|
|
|
|
if (!theBufferList().isLoaded(errbuf))
|
|
|
|
return false;
|
|
|
|
FuncRequest fr(LFUN_BUFFER_SWITCH, errbuf->absFileName());
|
|
|
|
dispatch(fr);
|
|
|
|
}
|
|
|
|
|
|
|
|
DocIterator dit = errbuf->getParFromID(err.par_id);
|
2007-10-06 14:13:25 +00:00
|
|
|
|
2011-03-04 13:37:14 +00:00
|
|
|
if (dit == doc_iterator_end(errbuf)) {
|
2010-10-14 20:49:34 +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
|
|
|
}
|
|
|
|
|
2011-04-05 15:40:00 +00:00
|
|
|
// Don't try to highlight the content of non-editable insets
|
|
|
|
while (!dit.inset().editable())
|
2011-04-05 01:00:30 +00:00
|
|
|
dit.backwardPos();
|
|
|
|
|
2007-10-06 14:13:25 +00:00
|
|
|
// Now make the selection.
|
2011-03-19 10:34:59 +00:00
|
|
|
BufferView * bv = const_cast<BufferView *>(bufferview());
|
|
|
|
if (bv->selectIfEmpty(dit)) {
|
|
|
|
// The paragraph is empty but can be selected
|
|
|
|
bv->processUpdateFlags(Update::Force | Update::FitCursor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (dit.empty()) {
|
|
|
|
// The paragraph is empty and cannot be selected
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-06 14:13:25 +00:00
|
|
|
// if pos_end is 0, this means it is end-of-paragraph
|
2014-03-22 11:09:18 +00:00
|
|
|
pos_type const s = dit.lastpos();
|
2008-02-09 15:23:05 +00:00
|
|
|
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);
|
2011-02-10 21:28:43 +00:00
|
|
|
pos_type const range = end == start ? s - start : end - start;
|
2011-02-21 10:27:50 +00:00
|
|
|
// end-of-paragraph cannot be highlighted, so highlight the last thing
|
|
|
|
dit.pos() = range ? start : end - 1;
|
2010-10-14 15:04:57 +00:00
|
|
|
// FIXME LFUN
|
|
|
|
// If we used an LFUN, we would not need these lines:
|
2011-02-21 16:08:02 +00:00
|
|
|
bv->putSelectionAt(dit, max(range, pos_type(1)), false);
|
2010-10-14 15:02:48 +00:00
|
|
|
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"
|