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/gettext.h"
25 #include "support/lstrings.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 QRegularExpression exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|.*> INFO - |\\(|\\\\).*$");
47 QRegularExpression exprWarning("^(## Warning|LaTeX Warning|LaTeX Font Warning|Package [\\w\\-\\.]+ Warning|Class \\w+ Warning|Warning--|Underfull|Overfull|.*> WARN - ).*$");
49 QRegularExpression exprError("^(ERROR: |!|.*---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) override;
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 QRegularExpressionMatch match = exprInfo.match(text);
87 int index = match.capturedStart(1);
89 int length = match.capturedEnd(1) - index;
90 setFormat(index, length, infoFormat);
91 match = exprInfo.match(text, index + length);
92 index = match.capturedStart(1);
95 match = exprWarning.match(text);
96 index = match.capturedStart(1);
98 int length = match.capturedEnd(1) - index;
99 setFormat(index, length, warningFormat);
100 match = exprWarning.match(text, index + length);
101 index = match.capturedStart(1);
104 match = exprError.match(text);
105 index = match.capturedStart(1);
107 int length = match.capturedEnd(1) - index;
108 setFormat(index, length, errorFormat);
109 match = exprError.match(text, index + length);
110 index = match.capturedStart(1);
115 /////////////////////////////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////
121 GuiLog::GuiLog(GuiView & lv)
122 : GuiDialog(lv, "log", qt_("LaTeX Log")), type_(LatexLog)
126 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
127 this, SLOT(slotButtonBox(QAbstractButton *)));
128 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
129 connect(findPB, SIGNAL(clicked()), this, SLOT(find()));
130 connect(findLE, SIGNAL(returnPressed()), this, SLOT(find()));
131 connect(logTypeCO, SIGNAL(activated(int)),
132 this, SLOT(typeChanged(int)));
134 bc().setPolicy(ButtonPolicy::OkCancelPolicy);
136 // set syntax highlighting
137 highlighter = new LogHighlighter(logTB->document());
139 logTB->setReadOnly(true);
140 logTB->setFont(guiApp->typewriterSystemFont());
142 QPushButton * closePB = buttonBox->button(QDialogButtonBox::Close);
143 closePB->setAutoDefault(false);
147 void GuiLog::updateContents()
149 setTitle(toqstr(title()));
154 logTB->setPlainText(toqstr(ss.str()));
156 nextErrorPB->setEnabled(contains(exprError));
157 nextWarningPB->setEnabled(contains(exprWarning));
161 void GuiLog::typeChanged(int i)
164 fromqstr(logTypeCO->itemData(i).toString());
168 else if (type == "bibtex")
170 else if (type == "index")
174 logfile_.changeExtension(ext);
182 logTB->find(findLE->text());
186 void GuiLog::on_nextErrorPB_clicked()
192 void GuiLog::on_nextWarningPB_clicked()
198 void GuiLog::on_openDirPB_clicked()
200 showDirectory(logfile_.onlyPath());
204 void GuiLog::goTo(QRegularExpression const & exp) const
206 QTextCursor const newc =
207 logTB->document()->find(exp, logTB->textCursor());
208 logTB->setTextCursor(newc);
212 bool GuiLog::contains(QRegularExpression const & exp) const
214 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
218 bool GuiLog::initialiseParams(string const & sdata)
220 istringstream is(sdata);
224 string logtype, logfile;
228 logfile = lex.getString();
231 // Parsing of the data failed.
234 logTypeCO->setEnabled(logtype == "latex");
237 FileName log(logfile);
239 if (logtype == "latex") {
241 logTypeCO->addItem(qt_("LaTeX"), toqstr(logtype));
243 tmp.changeExtension("blg");
245 if (support::contains(tmp.fileContents("UTF-8"), from_ascii("This is Biber")))
246 logTypeCO->addItem(qt_("Biber"), QString("bibtex"));
248 logTypeCO->addItem(qt_("BibTeX"), QString("bibtex"));
250 tmp.changeExtension("ilg");
252 logTypeCO->addItem(qt_("Index"), QString("index"));
253 // FIXME: not sure "literate" still works.
254 } else if (logtype == "literate") {
256 logTypeCO->addItem(qt_("Literate"), toqstr(logtype));
257 } else if (logtype == "lyx2lyx") {
259 logTypeCO->addItem(qt_("LyX2LyX"), toqstr(logtype));
260 } else if (logtype == "vc") {
262 logTypeCO->addItem(qt_("Version Control"), toqstr(logtype));
274 void GuiLog::clearParams()
280 docstring GuiLog::title() const
284 return _("LaTeX Log");
286 return _("Literate Programming Build Log");
288 return _("lyx2lyx Error Log");
290 return _("Version Control Log");
297 void GuiLog::getContents(ostream & ss) const
299 ifstream in(logfile_.toFilesystemEncoding().c_str());
301 bool success = false;
304 // Our caller interprets the file contents as UTF8, but is that
306 // spitz: No it isn't (generally). The log file encoding depends on the TeX
307 // _output_ encoding (T1 etc.). We should account for that. See #10728.
318 ss << to_utf8(_("Log file not found."));
321 ss << to_utf8(_("No literate programming build log file found."));
324 ss << to_utf8(_("No lyx2lyx error log file found."));
327 ss << to_utf8(_("No version control log file found."));
333 } // namespace frontend
336 #include "moc_GuiLog.cpp"