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 QRegExp exprInfo("^(Document Class:|LaTeX Font Info:|File:|Package:|Language:|.*> INFO - |\\(|\\\\).*$");
47 QRegExp exprWarning("^(## Warning|LaTeX Warning|LaTeX Font Warning|Package [\\w\\.]+ Warning|Class \\w+ Warning|Warning--|Underfull|Overfull|.*> WARN - ).*$");
49 QRegExp 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 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(buttonBox, SIGNAL(clicked(QAbstractButton *)),
121 this, SLOT(slotButtonBox(QAbstractButton *)));
122 connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents()));
123 connect(findPB, SIGNAL(clicked()), this, SLOT(find()));
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 logTB->setFont(guiApp->typewriterSystemFont());
136 QPushButton * closePB = buttonBox->button(QDialogButtonBox::Close);
137 closePB->setAutoDefault(false);
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::on_openDirPB_clicked()
194 showDirectory(logfile_.onlyPath());
198 void GuiLog::goTo(QRegExp const & exp) const
200 QTextCursor const newc =
201 logTB->document()->find(exp, logTB->textCursor());
202 logTB->setTextCursor(newc);
206 bool GuiLog::contains(QRegExp const & exp) const
208 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
212 bool GuiLog::initialiseParams(string const & sdata)
214 istringstream is(sdata);
218 string logtype, logfile;
222 logfile = lex.getString();
225 // Parsing of the data failed.
228 logTypeCO->setEnabled(logtype == "latex");
231 FileName log(logfile);
233 if (logtype == "latex") {
235 logTypeCO->addItem(qt_("LaTeX"), toqstr(logtype));
237 tmp.changeExtension("blg");
239 if (support::contains(tmp.fileContents("UTF-8"), from_ascii("This is Biber")))
240 logTypeCO->addItem(qt_("Biber"), QString("bibtex"));
242 logTypeCO->addItem(qt_("BibTeX"), QString("bibtex"));
244 tmp.changeExtension("ilg");
246 logTypeCO->addItem(qt_("Index"), QString("index"));
247 // FIXME: not sure "literate" still works.
248 } else if (logtype == "literate") {
250 logTypeCO->addItem(qt_("Literate"), toqstr(logtype));
251 } else if (logtype == "lyx2lyx") {
253 logTypeCO->addItem(qt_("LyX2LyX"), toqstr(logtype));
254 } else if (logtype == "vc") {
256 logTypeCO->addItem(qt_("Version Control"), toqstr(logtype));
268 void GuiLog::clearParams()
274 docstring GuiLog::title() const
278 return _("LaTeX Log");
280 return _("Literate Programming Build Log");
282 return _("lyx2lyx Error Log");
284 return _("Version Control Log");
291 void GuiLog::getContents(ostream & ss) const
293 ifstream in(logfile_.toFilesystemEncoding().c_str());
295 bool success = false;
298 // Our caller interprets the file contents as UTF8, but is that
300 // spitz: No it isn't (generally). The log file encoding depends on the TeX
301 // _output_ encoding (T1 etc.). We should account for that. See #10728.
312 ss << to_utf8(_("Log file not found."));
315 ss << to_utf8(_("No literate programming build log file found."));
318 ss << to_utf8(_("No lyx2lyx error log file found."));
321 ss << to_utf8(_("No version control log file found."));
327 } // namespace frontend
330 #include "moc_GuiLog.cpp"