2 * \file GuiErrorList.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
8 * Full author contact details are available in file CREDITS.
13 #include "GuiErrorList.h"
15 #include "qt_helpers.h"
18 #include "BufferView.h"
19 #include "ParIterator.h"
22 #include "support/debug.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
26 #include <QListWidget>
27 #include <QPushButton>
29 #include <QTextBrowser>
32 using namespace lyx::support;
37 GuiErrorList::GuiErrorList(GuiView & lv)
38 : GuiDialog(lv, "errorlist", qt_("Error List"))
42 connect(closePB, SIGNAL(clicked()),
43 this, SLOT(slotClose()));
44 connect(errorsLW, SIGNAL(currentRowChanged(int)),
45 this, SLOT(select()));
47 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
48 bc().setCancel(closePB);
52 void GuiErrorList::showEvent(QShowEvent * e)
54 errorsLW->setCurrentRow(0);
60 void GuiErrorList::select()
62 int const item = errorsLW->row(errorsLW->currentItem());
66 descriptionTB->setPlainText(
67 toqstr(errorList()[item].description));
71 void GuiErrorList::updateContents()
73 setTitle(toqstr(name_));
75 descriptionTB->setPlainText(QString());
77 ErrorList::const_iterator it = errorList().begin();
78 ErrorList::const_iterator end = errorList().end();
79 for (; it != end; ++it)
80 errorsLW->addItem(toqstr(it->error));
84 ErrorList const & GuiErrorList::errorList() const
86 return bufferview()->buffer().errorList(error_type_);
90 bool GuiErrorList::initialiseParams(string const & error_type)
92 error_type_ = error_type;
93 Buffer const & buf = bufferview()->buffer();
94 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
95 from_utf8(buf.absFileName()));
100 bool GuiErrorList::goTo(int item)
102 ErrorItem const & err = errorList()[item];
104 if (err.par_id == -1)
107 Buffer const & buf = buffer();
108 DocIterator dit = buf.getParFromID(err.par_id);
110 if (dit == doc_iterator_end(buf.inset())) {
111 // FIXME: Happens when loading a read-only doc with
112 // unknown layout. Should this be the case?
113 LYXERR0("par id " << err.par_id << " not found");
117 // Now make the selection.
118 // if pos_end is 0, this means it is end-of-paragraph
119 pos_type const s = dit.paragraph().size();
120 pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
121 pos_type const start = min(err.pos_start, end);
122 pos_type const range = end - start;
124 BufferView * bv = const_cast<BufferView *>(bufferview());
125 // FIXME: If we used an LFUN, we would not need this line:
126 bv->putSelectionAt(dit, range, false);
127 bv->processUpdateFlags(Update::Force | Update::FitCursor);
132 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
134 } // namespace frontend
138 #include "GuiErrorList_moc.cpp"