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"
16 #include "BufferView.h"
17 #include "support/debug.h"
18 #include "support/gettext.h"
20 #include "ParIterator.h"
22 #include "qt_helpers.h"
24 #include "support/lstrings.h"
26 #include <QListWidget>
27 #include <QTextBrowser>
28 #include <QPushButton>
29 #include <QCloseEvent>
36 using support::bformat;
38 GuiErrorList::GuiErrorList(GuiView & lv)
39 : GuiDialog(lv, "errorlist")
43 connect(closePB, SIGNAL(clicked()),
44 this, SLOT(slotClose()));
45 connect(errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
46 this, SLOT(select(QListWidgetItem *)));
48 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
49 bc().setCancel(closePB);
53 void GuiErrorList::closeEvent(QCloseEvent * e)
60 void GuiErrorList::showEvent(QShowEvent * e)
62 errorsLW->setCurrentRow(0);
63 select(errorsLW->item(0));
68 void GuiErrorList::select(QListWidgetItem * wi)
70 int const item = errorsLW->row(wi);
72 descriptionTB->setPlainText(toqstr(errorList()[item].description));
76 void GuiErrorList::updateContents()
80 descriptionTB->setPlainText(QString());
82 ErrorList::const_iterator it = errorList().begin();
83 ErrorList::const_iterator end = errorList().end();
84 for (; it != end; ++it)
85 errorsLW->addItem(toqstr(it->error));
89 ErrorList const & GuiErrorList::errorList() const
91 return bufferview()->buffer().errorList(error_type_);
95 bool GuiErrorList::initialiseParams(string const & error_type)
97 error_type_ = error_type;
98 Buffer const & buf = bufferview()->buffer();
99 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
100 from_utf8(buf.absFileName()));
105 void GuiErrorList::goTo(int item)
107 ErrorItem const & err = errorList()[item];
109 if (err.par_id == -1)
112 Buffer & buf = buffer();
113 ParIterator pit = buf.getParFromID(err.par_id);
115 if (pit == buf.par_iterator_end()) {
116 LYXERR0("par id " << err.par_id << " not found");
120 // Now make the selection.
121 // This should be implemented using an LFUN. (Angus)
122 // if pos_end is 0, this means it is end-of-paragraph
123 pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
125 pos_type const start = std::min(err.pos_start, end);
126 pos_type const range = end - start;
127 DocIterator const dit = makeDocIterator(pit, start);
128 bufferview()->putSelectionAt(dit, range, false);
129 // FIXME: If we used an LFUN, we would not need this line:
130 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
134 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
136 } // namespace frontend
140 #include "GuiErrorList_moc.cpp"