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 - ).*$");
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.setKerning(false);
136 font.setFixedPitch(true);
137 font.setStyleHint(QFont::TypeWriter);
138 logTB->setFont(font);
142 void GuiLog::updateContents()
144 setTitle(toqstr(title()));
149 logTB->setPlainText(toqstr(ss.str()));
151 nextErrorPB->setEnabled(contains(exprError));
152 nextWarningPB->setEnabled(contains(exprWarning));
156 void GuiLog::typeChanged(int i)
159 fromqstr(logTypeCO->itemData(i).toString());
163 else if (type == "bibtex")
165 else if (type == "index")
169 logfile_.changeExtension(ext);
177 logTB->find(findLE->text());
181 void GuiLog::on_nextErrorPB_clicked()
187 void GuiLog::on_nextWarningPB_clicked()
193 void GuiLog::goTo(QRegExp const & exp) const
195 QTextCursor const newc =
196 logTB->document()->find(exp, logTB->textCursor());
197 logTB->setTextCursor(newc);
201 bool GuiLog::contains(QRegExp const & exp) const
203 return !logTB->document()->find(exp, logTB->textCursor()).isNull();
207 bool GuiLog::initialiseParams(string const & data)
209 istringstream is(data);
213 string logtype, logfile;
217 logfile = lex.getString();
220 // Parsing of the data failed.
223 logTypeCO->setEnabled(logtype == "latex");
226 FileName log(logfile);
228 if (logtype == "latex") {
230 logTypeCO->addItem(qt_("LaTeX"), toqstr(logtype));
232 tmp.changeExtension("blg");
234 logTypeCO->addItem(qt_("BibTeX"), QString("bibtex"));
235 tmp.changeExtension("ilg");
237 logTypeCO->addItem(qt_("Index"), QString("index"));
238 // FIXME: not sure "literate" still works.
239 } else if (logtype == "literate") {
241 logTypeCO->addItem(qt_("Literate"), toqstr(logtype));
242 } else if (logtype == "lyx2lyx") {
244 logTypeCO->addItem(qt_("LyX2LyX"), toqstr(logtype));
245 } else if (logtype == "vc") {
247 logTypeCO->addItem(qt_("Version Control"), toqstr(logtype));
259 void GuiLog::clearParams()
265 docstring GuiLog::title() const
269 return _("LaTeX Log");
271 return _("Literate Programming Build Log");
273 return _("lyx2lyx Error Log");
275 return _("Version Control Log");
282 void GuiLog::getContents(ostream & ss) const
284 ifstream in(logfile_.toFilesystemEncoding().c_str());
286 bool success = false;
289 // Our caller interprets the file contents as UTF8, but is that
301 ss << to_utf8(_("Log file not found."));
304 ss << to_utf8(_("No literate programming build log file found."));
307 ss << to_utf8(_("No lyx2lyx error log file found."));
310 ss << to_utf8(_("No version control log file found."));
316 void GuiLog::on_copyPB_clicked()
318 theClipboard().put(fromqstr(logTB->toPlainText()));
322 Dialog * createGuiLog(GuiView & lv) { return new GuiLog(lv); }
325 } // namespace frontend
328 #include "moc_GuiLog.cpp"