From a5f7d951d15a4955ce8fff66643e86d7769c7adb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 6 Oct 2007 11:45:53 +0000 Subject: [PATCH] next one git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20779 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlLog.cpp | 131 ----------------------- src/frontends/controllers/ControlLog.h | 62 ----------- src/frontends/controllers/Makefile.am | 2 - src/frontends/qt4/Dialogs.cpp | 3 +- src/frontends/qt4/GuiLog.cpp | 123 ++++++++++++++++++--- src/frontends/qt4/GuiLog.h | 48 +++++++-- 6 files changed, 147 insertions(+), 222 deletions(-) delete mode 100644 src/frontends/controllers/ControlLog.cpp delete mode 100644 src/frontends/controllers/ControlLog.h diff --git a/src/frontends/controllers/ControlLog.cpp b/src/frontends/controllers/ControlLog.cpp deleted file mode 100644 index 437cd969aa..0000000000 --- a/src/frontends/controllers/ControlLog.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** - * \file ControlLog.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "ControlLog.h" - -#include "gettext.h" -#include "Lexer.h" - -#include -#include - -using std::istringstream; -using std::ostream; -using std::string; - -namespace lyx { - -using support::FileName; - -namespace frontend { - -ControlLog::ControlLog(Dialog & parent) - : Controller(parent), - type_(LatexLog) -{} - - -bool ControlLog::initialiseParams(string const & data) -{ - istringstream is(data); - Lexer lex(0,0); - lex.setStream(is); - - string logtype, logfile; - lex >> logtype; - if (lex) { - lex.next(true); - logfile = lex.getString(); - } - if (!lex) - // Parsing of the data failed. - return false; - - if (logtype == "latex") - type_ = LatexLog; - else if (logtype == "literate") - type_ = LiterateLog; - else if (logtype == "lyx2lyx") - type_ = Lyx2lyxLog; - else if (logtype == "vc") - type_ = VCLog; - else - return false; - - logfile_ = FileName(logfile); - return true; -} - - -void ControlLog::clearParams() -{ - logfile_.erase(); -} - - -docstring const ControlLog::title() const -{ - docstring t; - switch (type_) { - case LatexLog: - t = _("LaTeX Log"); - break; - case LiterateLog: - t = _("Literate Programming Build Log"); - break; - case Lyx2lyxLog: - t = _("lyx2lyx Error Log"); - break; - case VCLog: - t = _("Version Control Log"); - break; - } - return t; -} - - -void ControlLog::getContents(std::ostream & ss) const -{ - std::ifstream in(logfile_.toFilesystemEncoding().c_str()); - - bool success = false; - - // FIXME UNICODE - // Our caller interprets the file contents as UTF8, but is that - // correct? - if (in) { - ss << in.rdbuf(); - success = ss.good(); - } - - if (success) - return; - - switch (type_) { - case LatexLog: - ss << lyx::to_utf8(_("No LaTeX log file found.")); - break; - case LiterateLog: - ss << lyx::to_utf8(_("No literate programming build log file found.")); - break; - case Lyx2lyxLog: - ss << lyx::to_utf8(_("No lyx2lyx error log file found.")); - break; - case VCLog: - ss << lyx::to_utf8(_("No version control log file found.")); - break; - } -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/controllers/ControlLog.h b/src/frontends/controllers/ControlLog.h deleted file mode 100644 index de76eafdae..0000000000 --- a/src/frontends/controllers/ControlLog.h +++ /dev/null @@ -1,62 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlLog.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef CONTROLLOG_H -#define CONTROLLOG_H - -#include "Dialog.h" - -#include "support/FileName.h" - -namespace lyx { -namespace frontend { - -/** - * A controller for a read-only text browser. - */ -class ControlLog : public Controller { -public: - /// - ControlLog(Dialog &); - /** \param data should contain " " - * where is one of "latex", "literate", "lyx2lyx", "vc". - */ - virtual bool initialiseParams(std::string const & data); - /// - virtual void clearParams(); - /// - virtual void dispatchParams() {} - /// - virtual bool isBufferDependent() const { return true; } - - /// The title displayed by the dialog reflects the \c LOGTYPE - docstring const title() const; - /// put the log file into the ostream - void getContents(std::ostream & ss) const; - -private: - /// Recognized log file-types - enum LOGTYPE { - LatexLog, - LiterateLog, - Lyx2lyxLog, - VCLog - }; - - LOGTYPE type_; - support::FileName logfile_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // CONTROLLOG_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index b3b357d0ff..8e14c96335 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -17,7 +17,6 @@ SOURCEFILES = \ ControlExternal.cpp \ ControlGraphics.cpp \ ControlInclude.cpp \ - ControlLog.cpp \ ControlViewSource.cpp \ ControlMath.cpp \ ControlParagraph.cpp \ @@ -40,7 +39,6 @@ HEADERFILES = \ ControlExternal.h \ ControlGraphics.h \ ControlInclude.h \ - ControlLog.h \ ControlViewSource.h \ ControlMath.h \ ControlParagraph.h \ diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 326e45fa27..6e4a1c1758 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -27,7 +27,6 @@ #include "GuiIndex.h" #include "GuiMathMatrix.h" #include "GuiNomencl.h" -#include "GuiLog.h" #include "GuiParagraph.h" #include "GuiPrefs.h" #include "GuiPrint.h" @@ -191,7 +190,7 @@ Dialog * Dialogs::build(string const & name) } else if (name == "label") { dialog = new GuiLabelDialog(lyxview_); } else if (name == "log") { - dialog = new GuiLogDialog(lyxview_); + createGuiLog(lyxview_); } else if (name == "view-source") { dialog = new DockView( guiview, name, Qt::BottomDockWidgetArea); diff --git a/src/frontends/qt4/GuiLog.cpp b/src/frontends/qt4/GuiLog.cpp index 290015ff16..67609d9fb4 100644 --- a/src/frontends/qt4/GuiLog.cpp +++ b/src/frontends/qt4/GuiLog.cpp @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ @@ -12,8 +13,9 @@ #include "GuiLog.h" -#include "ControlLog.h" #include "qt_helpers.h" +#include "gettext.h" +#include "Lexer.h" #include "frontends/Application.h" @@ -21,12 +23,18 @@ #include #include +#include #include +using std::istringstream; +using std::ostream; +using std::string; + namespace lyx { namespace frontend { +using support::FileName; ///////////////////////////////////////////////////////////////////// // @@ -94,14 +102,14 @@ void LogHighlighter::highlightBlock(QString const & text) // ///////////////////////////////////////////////////////////////////// -GuiLogDialog::GuiLogDialog(LyXView & lv) - : GuiDialog(lv, "log") +GuiLog::GuiLog(LyXView & lv) + : GuiDialog(lv, "log"), Controller(this), type_(LatexLog) { setupUi(this); - setController(new ControlLog(*this)); + setController(this, false); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(updatePB, SIGNAL(clicked()), this, SLOT(updateClicked())); + connect(updatePB, SIGNAL(clicked()), this, SLOT(updateContents())); bc().setPolicy(ButtonPolicy::OkCancelPolicy); @@ -117,35 +125,116 @@ GuiLogDialog::GuiLogDialog(LyXView & lv) } -ControlLog & GuiLogDialog::controller() +void GuiLog::closeEvent(QCloseEvent * e) { - return static_cast(GuiDialog::controller()); + slotClose(); + e->accept(); } -void GuiLogDialog::closeEvent(QCloseEvent * e) +void GuiLog::updateContents() { - slotClose(); - e->accept(); + setViewTitle(title()); + + std::ostringstream ss; + getContents(ss); + + logTB->setPlainText(toqstr(ss.str())); } -void GuiLogDialog::updateClicked() +bool GuiLog::initialiseParams(string const & data) { - updateContents(); + istringstream is(data); + Lexer lex(0,0); + lex.setStream(is); + + string logtype, logfile; + lex >> logtype; + if (lex) { + lex.next(true); + logfile = lex.getString(); + } + if (!lex) + // Parsing of the data failed. + return false; + + if (logtype == "latex") + type_ = LatexLog; + else if (logtype == "literate") + type_ = LiterateLog; + else if (logtype == "lyx2lyx") + type_ = Lyx2lyxLog; + else if (logtype == "vc") + type_ = VCLog; + else + return false; + + logfile_ = FileName(logfile); + return true; } -void GuiLogDialog::updateContents() +void GuiLog::clearParams() { - setViewTitle(controller().title()); + logfile_.erase(); +} - std::ostringstream ss; - controller().getContents(ss); - logTB->setPlainText(toqstr(ss.str())); +docstring GuiLog::title() const +{ + switch (type_) { + case LatexLog: + return _("LaTeX Log"); + case LiterateLog: + return _("Literate Programming Build Log"); + case Lyx2lyxLog: + return _("lyx2lyx Error Log"); + case VCLog: + return _("Version Control Log"); + default: + return docstring(); + } } + +void GuiLog::getContents(std::ostream & ss) const +{ + std::ifstream in(logfile_.toFilesystemEncoding().c_str()); + + bool success = false; + + // FIXME UNICODE + // Our caller interprets the file contents as UTF8, but is that + // correct? + if (in) { + ss << in.rdbuf(); + success = ss.good(); + } + + if (success) + return; + + switch (type_) { + case LatexLog: + ss << to_utf8(_("No LaTeX log file found.")); + break; + case LiterateLog: + ss << to_utf8(_("No literate programming build log file found.")); + break; + case Lyx2lyxLog: + ss << to_utf8(_("No lyx2lyx error log file found.")); + break; + case VCLog: + ss << to_utf8(_("No version control log file found.")); + break; + } +} + + +Dialog * createGuiLog(LyXView & lv) { return new GuiLog(lv); } + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiLog.h b/src/frontends/qt4/GuiLog.h index 07940d94ff..6be299386a 100644 --- a/src/frontends/qt4/GuiLog.h +++ b/src/frontends/qt4/GuiLog.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ @@ -13,36 +14,67 @@ #define GUILOG_H #include "GuiDialog.h" -#include "ControlLog.h" #include "ui_LogUi.h" +#include "support/FileName.h" + + namespace lyx { namespace frontend { class LogHighlighter; -class GuiLogDialog : public GuiDialog, public Ui::LogUi +class GuiLog : public GuiDialog, public Ui::LogUi, public Controller { Q_OBJECT + public: - GuiLogDialog(LyXView & lv); + GuiLog(LyXView & lv); + private Q_SLOTS: - void updateClicked(); + void updateContents(); + private: void closeEvent(QCloseEvent * e); /// parent controller - ControlLog & controller(); + Controller & controller() { return *this; } /// Apply changes void applyView() {} - /// update - void updateContents(); /// log syntax highlighter LogHighlighter * highlighter; + + /** \param data should contain " " + * where is one of "latex", "literate", "lyx2lyx", "vc". + */ + bool initialiseParams(std::string const & data); + /// + void clearParams(); + /// + void dispatchParams() {} + /// + bool isBufferDependent() const { return true; } + + /// The title displayed by the dialog reflects the \c LogType + docstring title() const; + /// put the log file into the ostream + void getContents(std::ostream & ss) const; + +private: + /// Recognized log file-types + enum LogType { + LatexLog, + LiterateLog, + Lyx2lyxLog, + VCLog + }; + + LogType type_; + support::FileName logfile_; }; } // namespace frontend } // namespace lyx -#endif // QLOG_H +#endif // GUILOG_H -- 2.39.5