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"
20 #include "ParIterator.h"
22 #include "qt_helpers.h"
24 // FIXME: those two headers are needed because of the
25 // WorkArea::redraw() call below.
26 #include "frontends/LyXView.h"
27 #include "frontends/WorkArea.h"
29 #include "support/lstrings.h"
31 #include <QListWidget>
32 #include <QTextBrowser>
33 #include <QPushButton>
34 #include <QCloseEvent>
43 using support::bformat;
45 GuiErrorList::GuiErrorList(LyXView & lv)
46 : GuiDialog(lv, "errorlist"), Controller(this)
49 setController(this, false);
51 connect(closePB, SIGNAL(clicked()),
52 this, SLOT(slotClose()));
53 connect(errorsLW, SIGNAL(itemActivated(QListWidgetItem *)),
54 this, SLOT(slotClose()));
55 connect( errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
56 this, SLOT(select_adaptor(QListWidgetItem *)));
58 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
59 bc().setCancel(closePB);
63 void GuiErrorList::closeEvent(QCloseEvent * e)
70 void GuiErrorList::showEvent(QShowEvent * e)
72 errorsLW->setCurrentRow(0);
73 select(errorsLW->item(0));
78 void GuiErrorList::select(QListWidgetItem * wi)
80 int const item = errorsLW->row(wi);
82 descriptionTB->setPlainText(toqstr(errorList()[item].description));
86 void GuiErrorList::updateContents()
90 descriptionTB->setPlainText(QString());
92 ErrorList::const_iterator it = errorList().begin();
93 ErrorList::const_iterator end = errorList().end();
94 for (; it != end; ++it)
95 errorsLW->addItem(toqstr(it->error));
99 ErrorList const & GuiErrorList::errorList() const
101 return bufferview()->buffer().errorList(error_type_);
105 bool GuiErrorList::initialiseParams(string const & error_type)
107 error_type_ = error_type;
108 Buffer const & buf = bufferview()->buffer();
109 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
110 from_utf8(buf.fileName()));
115 void GuiErrorList::goTo(int item)
117 ErrorItem const & err = errorList()[item];
119 if (err.par_id == -1)
122 Buffer & buf = buffer();
123 ParIterator pit = buf.getParFromID(err.par_id);
125 if (pit == buf.par_iterator_end()) {
126 lyxerr << "par id " << err.par_id << " not found" << endl;
130 // Now make the selection.
131 // This should be implemented using an LFUN. (Angus)
132 // if pos_end is 0, this means it is end-of-paragraph
133 pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
135 pos_type const start = std::min(err.pos_start, end);
136 pos_type const range = end - start;
137 DocIterator const dit = makeDocIterator(pit, start);
138 bufferview()->putSelectionAt(dit, range, false);
139 // FIXME: If we used an LFUN, we would not need those two lines:
140 bufferview()->update();
141 lyxview().currentWorkArea()->redraw();
145 Dialog * createGuiErrorList(LyXView & lv) { return new GuiErrorList(lv); }
147 } // namespace frontend
151 #include "GuiErrorList_moc.cpp"