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"
15 #include "qt_helpers.h"
18 #include "BufferView.h"
19 #include "FuncRequest.h"
20 #include "ParIterator.h"
23 #include "support/debug.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
27 #include <QListWidget>
28 #include <QPushButton>
30 #include <QTextBrowser>
33 using namespace lyx::support;
37 string const guiErrorType(string const s)
41 else if (s == "literate")
42 return N_("Literate");
43 else if (s == "platex")
45 else if (s == "latex")
55 GuiErrorList::GuiErrorList(GuiView & lv)
56 : GuiDialog(lv, "errorlist", qt_("Error List"))
60 connect(closePB, SIGNAL(clicked()),
61 this, SLOT(slotClose()));
62 connect(viewLogPB, SIGNAL(clicked()),
63 this, SLOT(viewLog()));
64 connect(errorsLW, SIGNAL(currentRowChanged(int)),
65 this, SLOT(select()));
67 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
68 bc().setCancel(closePB);
72 void GuiErrorList::showEvent(QShowEvent * e)
80 void GuiErrorList::select()
82 int const item = errorsLW->row(errorsLW->currentItem());
86 descriptionTB->setPlainText(
87 toqstr(errorList()[item].description));
91 void GuiErrorList::viewLog()
93 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
97 void GuiErrorList::paramsToDialog()
99 setTitle(toqstr(name_));
101 descriptionTB->setPlainText(QString());
103 ErrorList::const_iterator it = errorList().begin();
104 ErrorList::const_iterator end = errorList().end();
105 for (; it != end; ++it)
106 errorsLW->addItem(toqstr(it->error));
107 errorsLW->setCurrentRow(0);
111 ErrorList const & GuiErrorList::errorList() const
113 return from_master_ ?
114 bufferview()->buffer().masterBuffer()->errorList(error_type_)
115 : bufferview()->buffer().errorList(error_type_);
119 bool GuiErrorList::initialiseParams(string const & data)
121 from_master_ = prefixIs(data, "from_master|");
122 string error_type = data;
124 error_type = split(data, '|');
125 error_type_ = error_type;
126 Buffer const * buf = from_master_ ?
127 bufferview()->buffer().masterBuffer()
128 : &bufferview()->buffer();
129 name_ = bformat(_("%1$s Errors (%2$s)"),
130 _(guiErrorType(error_type)),
131 from_utf8(buf->absFileName()));
137 bool GuiErrorList::goTo(int item)
139 ErrorItem const & err = errorList()[item];
141 if (err.par_id == -1)
148 Buffer const & buf = buffer();
149 DocIterator dit = buf.getParFromID(err.par_id);
151 if (dit == doc_iterator_end(&buf)) {
152 // FIXME: Happens when loading a read-only doc with
153 // unknown layout. Should this be the case?
154 LYXERR0("par id " << err.par_id << " not found");
158 // Now make the selection.
159 // if pos_end is 0, this means it is end-of-paragraph
160 pos_type const s = dit.paragraph().size();
161 pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
162 pos_type const start = min(err.pos_start, end);
163 pos_type const range = end - start;
165 BufferView * bv = const_cast<BufferView *>(bufferview());
166 // FIXME: If we used an LFUN, we would not need this line:
167 bv->putSelectionAt(dit, range, false);
168 bv->processUpdateFlags(Update::Force | Update::FitCursor);
173 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
175 } // namespace frontend
179 #include "moc_GuiErrorList.cpp"