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 "FuncStatus.h"
22 #include "BufferList.h"
24 #include "ParIterator.h"
27 #include "support/debug.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
31 #include <QListWidget>
32 #include <QPushButton>
34 #include <QTextBrowser>
37 using namespace lyx::support;
41 string const guiErrorType(string const & s)
45 else if (s == "literate")
46 return N_("Literate");
47 else if (s == "platex")
49 else if (s == "latex" || "xetex")
50 // All LaTeX variants except pLaTeX
51 // (LaTeX, PDFLaTeX, XeTeX, LuaTeX)
61 GuiErrorList::GuiErrorList(GuiView & lv)
62 : GuiDialog(lv, "errorlist", qt_("Error List")), from_master_(false)
66 connect(closePB, SIGNAL(clicked()),
67 this, SLOT(slotClose()));
68 connect(viewLogPB, SIGNAL(clicked()),
69 this, SLOT(viewLog()));
70 connect(showAnywayPB, SIGNAL(clicked()),
71 this, SLOT(showAnyway()));
72 connect(errorsLW, SIGNAL(currentRowChanged(int)),
73 this, SLOT(select()));
75 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
76 bc().setCancel(closePB);
80 void GuiErrorList::showEvent(QShowEvent * e)
88 void GuiErrorList::select()
90 int const item = errorsLW->row(errorsLW->currentItem());
94 descriptionTB->setPlainText(
95 toqstr(errorList()[item].description));
99 void GuiErrorList::viewLog()
101 if (&buffer() != buf_) {
102 if (!theBufferList().isLoaded(buf_))
104 FuncRequest fr(LFUN_BUFFER_SWITCH, buf_->absFileName());
107 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
111 void GuiErrorList::showAnyway()
113 dispatch(FuncRequest(LFUN_BUFFER_VIEW_CACHE));
117 void GuiErrorList::paramsToDialog()
119 setTitle(toqstr(name_));
121 descriptionTB->setPlainText(QString());
123 ErrorList const & el = errorList();
124 ErrorList::const_iterator it = el.begin();
125 ErrorList::const_iterator const en = el.end();
126 for (; it != en; ++it)
127 errorsLW->addItem(toqstr(it->error));
128 errorsLW->setCurrentRow(0);
129 showAnywayPB->setEnabled(
130 lyx::getStatus(FuncRequest(LFUN_BUFFER_VIEW_CACHE)).enabled());
134 ErrorList const & GuiErrorList::errorList() const
136 Buffer const * buffer = from_master_
137 ? bufferview()->buffer().masterBuffer()
138 : &bufferview()->buffer();
140 error_list_ = buffer->errorList(error_type_);
146 bool GuiErrorList::initialiseParams(string const & data)
148 from_master_ = prefixIs(data, "from_master|");
149 string error_type = data;
151 error_type = split(data, '|');
152 error_type_ = error_type;
153 buf_ = from_master_ ?
154 bufferview()->buffer().masterBuffer()
155 : &bufferview()->buffer();
156 name_ = bformat(_("%1$s Errors (%2$s)"),
157 _(guiErrorType(error_type)),
158 from_utf8(buf_->absFileName()));
164 bool GuiErrorList::goTo(int item)
166 ErrorItem const & err = errorList()[item];
168 if (err.par_id == -1)
171 Buffer const * errbuf = err.buffer ? err.buffer : buf_;
173 if (&buffer() != errbuf) {
174 if (!theBufferList().isLoaded(errbuf))
176 FuncRequest fr(LFUN_BUFFER_SWITCH, errbuf->absFileName());
180 DocIterator dit = errbuf->getParFromID(err.par_id);
182 if (dit == doc_iterator_end(errbuf)) {
183 // FIXME: Happens when loading a read-only doc with
184 // unknown layout. Should this be the case?
185 LYXERR0("par id " << err.par_id << " not found");
189 // Don't try to highlight the content of non-editable insets
190 while (!dit.inset().editable())
193 // Now make the selection.
194 BufferView * bv = const_cast<BufferView *>(bufferview());
195 if (bv->selectIfEmpty(dit)) {
196 // The paragraph is empty but can be selected
197 bv->processUpdateFlags(Update::Force | Update::FitCursor);
201 // The paragraph is empty and cannot be selected
204 // if pos_end is 0, this means it is end-of-paragraph
205 pos_type const s = dit.lastpos();
206 pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
207 pos_type const start = min(err.pos_start, end);
208 pos_type const range = end == start ? s - start : end - start;
209 // end-of-paragraph cannot be highlighted, so highlight the last thing
210 dit.pos() = range ? start : end - 1;
212 // If we used an LFUN, we would not need these lines:
213 bv->putSelectionAt(dit, max(range, pos_type(1)), false);
214 bv->processUpdateFlags(Update::Force | Update::FitCursor);
219 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
221 } // namespace frontend
225 #include "moc_GuiErrorList.cpp"