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;
38 GuiErrorList::GuiErrorList(GuiView & lv)
39 : GuiDialog(lv, "errorlist", qt_("Error List"))
43 connect(closePB, SIGNAL(clicked()),
44 this, SLOT(slotClose()));
45 connect(viewLogPB, SIGNAL(clicked()),
46 this, SLOT(viewLog()));
47 connect(errorsLW, SIGNAL(currentRowChanged(int)),
48 this, SLOT(select()));
50 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
51 bc().setCancel(closePB);
55 void GuiErrorList::showEvent(QShowEvent * e)
63 void GuiErrorList::select()
65 int const item = errorsLW->row(errorsLW->currentItem());
69 descriptionTB->setPlainText(
70 toqstr(errorList()[item].description));
74 void GuiErrorList::viewLog()
76 dispatch(FuncRequest(LFUN_DIALOG_SHOW, "latexlog"));
80 void GuiErrorList::paramsToDialog()
82 setTitle(toqstr(name_));
84 descriptionTB->setPlainText(QString());
86 ErrorList::const_iterator it = errorList().begin();
87 ErrorList::const_iterator end = errorList().end();
88 for (; it != end; ++it)
89 errorsLW->addItem(toqstr(it->error));
90 errorsLW->setCurrentRow(0);
94 ErrorList const & GuiErrorList::errorList() const
97 bufferview()->buffer().masterBuffer()->errorList(error_type_)
98 : bufferview()->buffer().errorList(error_type_);
102 bool GuiErrorList::initialiseParams(string const & data)
104 from_master_ = prefixIs(data, "from_master|");
105 string error_type = data;
107 error_type = split(data, '|');
108 error_type_ = error_type;
109 Buffer const * buf = from_master_ ?
110 bufferview()->buffer().masterBuffer()
111 : &bufferview()->buffer();
112 name_ = bformat(_("%1$s Errors (%2$s)"), _(error_type),
113 from_utf8(buf->absFileName()));
119 bool GuiErrorList::goTo(int item)
121 ErrorItem const & err = errorList()[item];
123 if (err.par_id == -1)
130 Buffer const & buf = buffer();
131 DocIterator dit = buf.getParFromID(err.par_id);
133 if (dit == doc_iterator_end(&buf)) {
134 // FIXME: Happens when loading a read-only doc with
135 // unknown layout. Should this be the case?
136 LYXERR0("par id " << err.par_id << " not found");
140 // Now make the selection.
141 // if pos_end is 0, this means it is end-of-paragraph
142 pos_type const s = dit.paragraph().size();
143 pos_type const end = err.pos_end ? min(err.pos_end, s) : s;
144 pos_type const start = min(err.pos_start, end);
145 pos_type const range = end - start;
147 BufferView * bv = const_cast<BufferView *>(bufferview());
148 // FIXME: If we used an LFUN, we would not need this line:
149 bv->putSelectionAt(dit, range, false);
150 bv->processUpdateFlags(Update::Force | Update::FitCursor);
155 Dialog * createGuiErrorList(GuiView & lv) { return new GuiErrorList(lv); }
157 } // namespace frontend
161 #include "moc_GuiErrorList.cpp"