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(itemClicked(QListWidgetItem *)),
53 this, SLOT(select(QListWidgetItem *)));
55 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
56 bc().setCancel(closePB);
60 void GuiErrorList::closeEvent(QCloseEvent * e)
67 void GuiErrorList::showEvent(QShowEvent * e)
69 errorsLW->setCurrentRow(0);
70 select(errorsLW->item(0));
75 void GuiErrorList::select(QListWidgetItem * wi)
77 int const item = errorsLW->row(wi);
79 descriptionTB->setPlainText(toqstr(errorList()[item].description));
83 void GuiErrorList::updateContents()
87 descriptionTB->setPlainText(QString());
89 ErrorList::const_iterator it = errorList().begin();
90 ErrorList::const_iterator end = errorList().end();
91 for (; it != end; ++it)
92 errorsLW->addItem(toqstr(it->error));
96 ErrorList const & GuiErrorList::errorList() const
98 return bufferview()->buffer().errorList(error_type_);
102 bool GuiErrorList::initialiseParams(string const & error_type)
104 error_type_ = error_type;
105 Buffer const & buf = bufferview()->buffer();
106 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
107 from_utf8(buf.absFileName()));
112 void GuiErrorList::goTo(int item)
114 ErrorItem const & err = errorList()[item];
116 if (err.par_id == -1)
119 Buffer & buf = buffer();
120 ParIterator pit = buf.getParFromID(err.par_id);
122 if (pit == buf.par_iterator_end()) {
123 lyxerr << "par id " << err.par_id << " not found" << endl;
127 // Now make the selection.
128 // This should be implemented using an LFUN. (Angus)
129 // if pos_end is 0, this means it is end-of-paragraph
130 pos_type const end = err.pos_end ? std::min(err.pos_end, pit->size())
132 pos_type const start = std::min(err.pos_start, end);
133 pos_type const range = end - start;
134 DocIterator const dit = makeDocIterator(pit, start);
135 bufferview()->putSelectionAt(dit, range, false);
136 // FIXME: If we used an LFUN, we would not need this line:
137 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
141 Dialog * createGuiErrorList(LyXView & lv) { return new GuiErrorList(lv); }
143 } // namespace frontend
147 #include "GuiErrorList_moc.cpp"