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 <QTextBrowser>
28 #include <QPushButton>
31 using namespace lyx::support;
36 GuiErrorList::GuiErrorList(GuiView & lv)
37 : GuiDialog(lv, "errorlist", qt_("Error List"))
41 connect(closePB, SIGNAL(clicked()),
42 this, SLOT(slotClose()));
43 connect(errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
44 this, SLOT(select(QListWidgetItem *)));
46 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
47 bc().setCancel(closePB);
51 void GuiErrorList::showEvent(QShowEvent * e)
53 errorsLW->setCurrentRow(0);
54 select(errorsLW->item(0));
59 void GuiErrorList::select(QListWidgetItem * wi)
61 int const item = errorsLW->row(wi);
63 descriptionTB->setPlainText(toqstr(errorList()[item].description));
67 void GuiErrorList::updateContents()
69 setTitle(toqstr(name_));
71 descriptionTB->setPlainText(QString());
73 ErrorList::const_iterator it = errorList().begin();
74 ErrorList::const_iterator end = errorList().end();
75 for (; it != end; ++it)
76 errorsLW->addItem(toqstr(it->error));
80 ErrorList const & GuiErrorList::errorList() const
82 return bufferview()->buffer().errorList(error_type_);
86 bool GuiErrorList::initialiseParams(string const & error_type)
88 error_type_ = error_type;
89 Buffer const & buf = bufferview()->buffer();
90 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
91 from_utf8(buf.absFileName()));
96 void GuiErrorList::goTo(int item)
98 ErrorItem const & err = errorList()[item];
100 if (err.par_id == -1)
103 Buffer & buf = buffer();
104 DocIterator dit = buf.getParFromID(err.par_id);
106 if (dit == doc_iterator_end(buf.inset())) {
107 LYXERR0("par id " << err.par_id << " not found");
111 // Now make the selection.
112 // if pos_end is 0, this means it is end-of-paragraph
113 pos_type const s = dit.paragraph().size();
114 pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
115 pos_type const start = min(err.pos_start, end);
116 pos_type const range = end - start;
118 bufferview()->putSelectionAt(dit, range, false);
119 // FIXME: If we used an LFUN, we would not need this line:
120 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
124 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
126 } // namespace frontend
130 #include "GuiErrorList_moc.cpp"