3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
17 #include "GuiApplication.h"
18 #include "qt_helpers.h"
21 #include "frontends/Clipboard.h"
23 #include "support/docstring.h"
24 #include "support/FileName.h"
25 #include "support/gettext.h"
27 #include <QTextBrowser>
28 #include <QSyntaxHighlighter>
35 using namespace lyx::support;
41 // Regular expressions needed at several places
42 // FIXME: These regexes are incomplete. It would be good if we could collect those used in LaTeX::scanLogFile
43 // and LaTeX::scanBlgFile and re-use them here!(spitz, 2013-05-27)
45 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|Underfull|Overfull|.*> INFO - |\\(|\\\\).*$");
47 QRegExp exprWarning("^(LaTeX Warning|LaTeX Font Warning|Package [\\w\\.]+ Warning|Class \\w+ Warning|Warning--|.*> WARN - ).*$");
49 QRegExp exprError("^(!|.*---line [0-9]+ of file|.*> FATAL - |.*> ERROR - |Missing character: There is no ).*$");
52 /////////////////////////////////////////////////////////////////////
56 ////////////////////////////////////////////////////////////////////
58 class LogHighlighter : public QSyntaxHighlighter
61 LogHighlighter(QTextDocument * parent);
64 void highlightBlock(QString const & text);
67 QTextCharFormat infoFormat;
68 QTextCharFormat warningFormat;
69 QTextCharFormat errorFormat;
74 LogHighlighter::LogHighlighter(QTextDocument * parent)
75 : QSyntaxHighlighter(parent)
77 infoFormat.setForeground(Qt::darkGray);
78 warningFormat.setForeground(Qt::darkBlue);
79 errorFormat.setForeground(Qt::red);
83 void LogHighlighter::highlightBlock(QString const & text)
86 int index = exprInfo.indexIn(text);
88 int length = exprInfo.matchedLength();
89 setFormat(index, length, infoFormat);
90 index = exprInfo.indexIn(text, index + length);
93 index = exprWarning.indexIn(text);
95 int length = exprWarning.matchedLength();
96 setFormat(index, length, warningFormat);
97 index = exprWarning.indexIn(text, index + length);
100 index = exprError.indexIn(text);
102 int length = exprError.matchedLength();
103 setFormat(index, length, errorFormat);
104 index = exprError.indexIn(text, index + length);
109 /////////////////////////////////////////////////////////////////////
113 /////////////////////////////////////////////////////////////////////
115 GuiLog::GuiLog(GuiView & lv)
116 : GuiDialog(lv, "log", qt_("LaTeX Log")), type_(LatexLog)
120 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
121 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
122 connect(findPB, SIGNAL(clicked()), this, SLOT(find()));
123 // FIXME: find via returnPressed() does not work!
124 connect(findLE, SIGNAL(returnPressed()), this, SLOT(find()));
125 connect(logTypeCO, SIGNAL(activated(int)),
126 this, SLOT(typeChanged(int)));
128 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
130 // set syntax highlighting
131 highlighter = new LogHighlighter(logTB->document());
133 logTB->setReadOnly(true);
134 QFont font(guiApp->typewriterFontName());
135 font.setFixedPitch(true);
136 font.setStyleHint(QFont::TypeWriter);
137 logTB->setFont(font);
141 void GuiLog::updateContents()
143 setTitle(toqstr(title()));
148 logTB->setPlainText(toqstr(ss.str()));
150 nextErrorPB->setEnabled(contains(exprError));
151 nextWarningPB->setEnabled(contains(exprWarning));
155 void GuiLog::typeChanged(int i)
158 fromqstr(logTypeCO->itemData(i).toString());
162 else if (type == "bibtex")
164 else if (type == "index")
168 logfile_.changeExtension(ext);
176 logTB->find(findLE->text());
180 void GuiLog::on_nextErrorPB_clicked()
186 void GuiLog::on_nextWarningPB_clicked()
192 void GuiLog::goTo(QRegExp const & exp) const
194 QTextCursor const newc =
195 logTB->document()->find(exp, logTB->textCursor());
196 logTB->setTextCursor(newc);
200 bool GuiLog::contains(QRegExp const & exp) const
202 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
206 bool GuiLog::initialiseParams(string const & data)
208 istringstream is(data);
212 string logtype, logfile;
216 logfile = lex.getString();
219 // Parsing of the data failed.
222 logTypeCO->setEnabled(logtype == "latex");
225 FileName log(logfile);
227 if (logtype == "latex") {
229 logTypeCO->addItem(qt_("LaTeX"), toqstr(logtype));
231 tmp.changeExtension("blg");
233 logTypeCO->addItem(qt_("BibTeX"), QString("bibtex"));
234 tmp.changeExtension("ilg");
236 logTypeCO->addItem(qt_("Index"), QString("index"));
237 // FIXME: not sure "literate" still works.
238 } else if (logtype == "literate") {
240 logTypeCO->addItem(qt_("Literate"), toqstr(logtype));
241 } else if (logtype == "lyx2lyx") {
243 logTypeCO->addItem(qt_("LyX2LyX"), toqstr(logtype));
244 } else if (logtype == "vc") {
246 logTypeCO->addItem(qt_("Version Control"), toqstr(logtype));
258 void GuiLog::clearParams()
264 docstring GuiLog::title() const
268 return _("LaTeX Log");
270 return _("Literate Programming Build Log");
272 return _("lyx2lyx Error Log");
274 return _("Version Control Log");
281 void GuiLog::getContents(ostream & ss) const
283 ifstream in(logfile_.toFilesystemEncoding().c_str());
285 bool success = false;
288 // Our caller interprets the file contents as UTF8, but is that
300 ss << to_utf8(_("Log file not found."));
303 ss << to_utf8(_("No literate programming build log file found."));
306 ss << to_utf8(_("No lyx2lyx error log file found."));
309 ss << to_utf8(_("No version control log file found."));
315 void GuiLog::on_copyPB_clicked()
317 theClipboard().put(fromqstr(logTB->toPlainText()));
321 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
324 } // namespace frontend
327 #include "moc_GuiLog.cpp"