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")
50 connect(closePB, SIGNAL(clicked()),
51 this, SLOT(slotClose()));
52 connect(errorsLW, SIGNAL(itemActivated(QListWidgetItem *)),
53 this, SLOT(slotClose()));
54 connect( errorsLW, SIGNAL(itemClicked(QListWidgetItem *)),
55 this, SLOT(select_adaptor(QListWidgetItem *)));
57 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
58 bc().setCancel(closePB);
62 void GuiErrorList::closeEvent(QCloseEvent * e)
69 void GuiErrorList::showEvent(QShowEvent * e)
71 errorsLW->setCurrentRow(0);
72 select(errorsLW->item(0));
77 void GuiErrorList::select(QListWidgetItem * wi)
79 int const item = errorsLW->row(wi);
81 descriptionTB->setPlainText(toqstr(errorList()[item].description));
85 void GuiErrorList::updateContents()
89 descriptionTB->setPlainText(QString());
91 ErrorList::const_iterator it = errorList().begin();
92 ErrorList::const_iterator end = errorList().end();
93 for (; it != end; ++it)
94 errorsLW->addItem(toqstr(it->error));
98 ErrorList const & GuiErrorList::errorList() const
100 return bufferview()->buffer().errorList(error_type_);
104 bool GuiErrorList::initialiseParams(string const & error_type)
106 error_type_ = error_type;
107 Buffer const & buf = bufferview()->buffer();
108 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
109 from_utf8(buf.fileName()));
114 void GuiErrorList::goTo(int item)
116 ErrorItem const & err = errorList()[item];
118 if (err.par_id == -1)
121 Buffer & buf = buffer();
122 ParIterator pit = buf.getParFromID(err.par_id);
124 if (pit == buf.par_iterator_end()) {
125 lyxerr << "par id " << err.par_id << " not found" << endl;
129 // Now make the selection.
130 // This should be implemented using an LFUN. (Angus)
131 // if pos_end is 0, this means it is end-of-paragraph
132 pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
134 pos_type const start = std::min(err.pos_start, end);
135 pos_type const range = end - start;
136 DocIterator const dit = makeDocIterator(pit, start);
137 bufferview()->putSelectionAt(dit, range, false);
138 // FIXME: If we used an LFUN, we would not need this line:
139 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
143 Dialog * createGuiErrorList(LyXView & lv) { return new GuiErrorList(lv); }
145 } // namespace frontend
149 #include "GuiErrorList_moc.cpp"