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 "qt_helpers.h"
19 #include "BufferView.h"
20 #include "FuncRequest.h"
21 #include "BufferList.h"
22 #include "ParIterator.h"
25 #include "support/debug.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
29 #include <QListWidget>
30 #include <QPushButton>
32 #include <QTextBrowser>
35 using namespace lyx::support;
39 string const guiErrorType(string const s)
43 else if (s == "literate")
44 return N_("Literate");
45 else if (s == "platex")
47 else if (s == "latex")
57 GuiErrorList::GuiErrorList(GuiView & lv)
58 : GuiDialog(lv, "errorlist", qt_("Error List"))
62 connect(closePB, SIGNAL(clicked()),
63 this, SLOT(slotClose()));
64 connect(viewLogPB, SIGNAL(clicked()),
65 this, SLOT(viewLog()));
66 connect(errorsLW, SIGNAL(currentRowChanged(int)),
67 this, SLOT(select()));
69 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
70 bc().setCancel(closePB);
74 void GuiErrorList::showEvent(QShowEvent * e)
82 void GuiErrorList::select()
84 int const item = errorsLW->row(errorsLW->currentItem());
88 descriptionTB->setPlainText(
89 toqstr(errorList()[item].description));
93 void GuiErrorList::viewLog()
95 if (&buffer() != buf_) {
96 if (!theBufferList().isLoaded(buf_))
98 FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName());
101 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
105 void GuiErrorList::paramsToDialog()
107 setTitle(toqstr(name_));
109 descriptionTB->setPlainText(QString());
111 ErrorList const & el = errorList();
112 ErrorList::const_iterator it = el.begin();
113 ErrorList::const_iterator const en = el.end();
114 for (; it != en; ++it)
115 errorsLW->addItem(toqstr(it->error));
116 errorsLW->setCurrentRow(0);
120 ErrorList const & GuiErrorList::errorList() const
122 Buffer const * buffer = from_master_
123 ? bufferview()->buffer().masterBuffer()
124 : &bufferview()->buffer();
126 error_list_ = buffer->errorList(error_type_);
132 bool GuiErrorList::initialiseParams(string const & data)
134 from_master_ = prefixIs(data, "from_master|");
135 string error_type = data;
137 error_type = split(data, '|');
138 error_type_ = error_type;
139 buf_ = from_master_ ?
140 bufferview()->buffer().masterBuffer()
141 : &bufferview()->buffer();
142 name_ = bformat(_("%1$s Errors (%2$s)"),
143 _(guiErrorType(error_type)),
144 from_utf8(buf_->absFileName()));
150 bool GuiErrorList::goTo(int item)
152 ErrorItem const & err = errorList()[item];
154 if (err.par_id == -1)
157 Buffer const * errbuf = err.buffer ? err.buffer : buf_;
159 if (&buffer() != errbuf) {
160 if (!theBufferList().isLoaded(errbuf))
162 FuncRequest fr(LFUN_BUFFER_SWITCH, errbuf->absFileName());
166 DocIterator dit = errbuf->getParFromID(err.par_id);
168 if (dit == doc_iterator_end(errbuf)) {
169 // FIXME: Happens when loading a read-only doc with
170 // unknown layout. Should this be the case?
171 LYXERR0("par id " << err.par_id << " not found");
175 // Don't try to highlight the content of non-editable insets
176 while (!dit.inset().editable())
179 // Now make the selection.
180 BufferView * bv = const_cast<BufferView *>(bufferview());
181 if (bv->selectIfEmpty(dit)) {
182 // The paragraph is empty but can be selected
183 bv->processUpdateFlags(Update::Force | Update::FitCursor);
187 // The paragraph is empty and cannot be selected
190 // if pos_end is 0, this means it is end-of-paragraph
191 pos_type const s = dit.paragraph().size();
192 pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
193 pos_type const start = min(err.pos_start, end);
194 pos_type const range = end == start ? s - start : end - start;
195 // end-of-paragraph cannot be highlighted, so highlight the last thing
196 dit.pos() = range ? start : end - 1;
198 // If we used an LFUN, we would not need these lines:
199 bv->putSelectionAt(dit, max(range, pos_type(1)), false);
200 bv->processUpdateFlags(Update::Force | Update::FitCursor);
205 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
207 } // namespace frontend
211 #include "moc_GuiErrorList.cpp"