From dbd0f58ebc92454451c82a020ec86373de2e5ea9 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 5 Dec 2003 13:37:23 +0000 Subject: [PATCH] Rationalize the interface to the log dialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8204 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 ++ src/frontends/controllers/ChangeLog | 5 ++ src/frontends/controllers/ControlLog.C | 90 ++++++++++++++++++++++++-- src/frontends/controllers/ControlLog.h | 26 +++++--- src/frontends/qt2/ChangeLog | 7 ++ src/frontends/qt2/Dialogs.C | 12 +--- src/frontends/qt2/QLog.C | 51 ++++----------- src/frontends/xforms/ChangeLog | 7 ++ src/frontends/xforms/Dialogs.C | 12 +--- src/frontends/xforms/FormLog.C | 24 ++----- src/lyxfunc.C | 24 ++++++- 11 files changed, 176 insertions(+), 87 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 630da56e7d..b8e67ebaa0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-12-05 Angus Leeming + + * lyxfunc.C (dispatch): DIALOG_SHOW now handles "latexlog" and + "vclog" explicitly, passing the appropriate " " + data to the re-worked "log" dialog. 2003-12-03 André Pönitz diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index cb4b82c8b8..0d8ff120c3 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-12-05 Angus Leeming + + * ControlLog.[Ch]: re-worked so that it is passed the logtype and + filename rather than extracting them from the kernel. + 2003-12-04 Angus Leeming * ControlExternal.[Ch] (bbChanged): new accessor functions to a diff --git a/src/frontends/controllers/ControlLog.C b/src/frontends/controllers/ControlLog.C index 5cbbab2d30..f83803a29b 100644 --- a/src/frontends/controllers/ControlLog.C +++ b/src/frontends/controllers/ControlLog.C @@ -13,23 +13,105 @@ #include "ControlLog.h" +#include "gettext.h" +#include "lyxlex.h" +#include "support/std_sstream.h" + +#include + +using std::istringstream; +using std::ostream; using std::string; ControlLog::ControlLog(Dialog & parent) - : Dialog::Controller(parent) + : Dialog::Controller(parent), + type_(LatexLog) {} -bool ControlLog::initialiseParams(string const &) +bool ControlLog::initialiseParams(string const & data) { - logfile_ = kernel().buffer().getLogName(); + istringstream is(data); + LyXLex lex(0,0); + lex.setStream(is); + + string logtype, logfile; + lex >> logtype >> logfile; + 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_ = logfile; return true; } void ControlLog::clearParams() { - logfile_.second.erase(); + logfile_.erase(); +} + + +string const ControlLog::title() const +{ + string t; + switch (type_) { + case LatexLog: + t = _("LyX: LaTeX Log"); + break; + case LiterateLog: + t = _("LyX: Literate Programming Build Log"); + break; + case Lyx2lyxLog: + t = _("LyX: lyx2lyx error Log"); + break; + case VCLog: + t = _("Version Control Log"); + break; + } + return t; +} + + +void ControlLog::getContents(std::ostream & ss) const +{ + std::ifstream in(logfile_.c_str()); + + bool success = false; + + if (in) { + ss << in.rdbuf(); + success = ss.good(); + } + + if (success) + return; + + switch (type_) { + case LatexLog: + ss << _("No LaTeX log file found."); + break; + case LiterateLog: + ss << _("No literate programming build log file found."); + break; + case Lyx2lyxLog: + ss << _("No lyx2lyx error log file found."); + break; + case VCLog: + ss << _("No version control log file found."); + break; + } } diff --git a/src/frontends/controllers/ControlLog.h b/src/frontends/controllers/ControlLog.h index 0843d1e6c5..699cab0c25 100644 --- a/src/frontends/controllers/ControlLog.h +++ b/src/frontends/controllers/ControlLog.h @@ -14,8 +14,6 @@ #define CONTROLLOG_H #include "Dialog.h" -#include "buffer.h" // Buffer::LogType -#include /** * A controller for a read-only text browser. @@ -24,7 +22,9 @@ class ControlLog : public Dialog::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(); @@ -32,13 +32,23 @@ public: virtual void dispatchParams() {} /// virtual bool isBufferDependent() const { return true; } - /// - std::pair const & logfile() const { - return logfile_; - } + + /// The title displayed by the dialog reflects the \c LOGTYPE + std::string 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 + }; - std::pair logfile_; + LOGTYPE type_; + std::string logfile_; }; #endif // CONTROLLOG_H diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index b3fc62abbb..8959e82573 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,10 @@ +2003-12-05 Angus Leeming + + * QLog.C: much simplified, thanks to the more powerful interface + of ControlLog. + + * Dialogs.C: no need anymore to build a separate VCLog dialog. + 2003-12-05 Jürgen Spitzmüller * ui/QExternalDialogBase.ui: improved layout. diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 72d8d9dce5..f5b5eec404 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -34,7 +34,6 @@ #include "ControlTabular.h" #include "ControlTabularCreate.h" #include "ControlToc.h" -#include "ControlVCLog.h" #include "ControlVSpace.h" #include "ControlWrap.h" @@ -70,7 +69,6 @@ #include "QTexinfo.h" #include "QToc.h" #include "QURL.h" -#include "QVCLog.h" #include "QVSpace.h" #include "QWrap.h" @@ -88,7 +86,7 @@ namespace { char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "changes", "character", "citation", "error", "errorlist", "ert", "external", "file", -"float", "graphics", "include", "index", "label", "latexlog", +"float", "graphics", "include", "index", "label", "log", "mathpanel", "mathdelimiter", "mathmatrix", "minipage", "note", "paragraph", "ref", "tabular", "tabularcreate", "texinfo", @@ -96,7 +94,7 @@ char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "thesaurus", #endif -"toc", "url", "vclog", "vspace", "wrap" }; +"toc", "url", "vspace", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -197,7 +195,7 @@ Dialog * Dialogs::build(string const & name) _("LyX: Label"), qt_("&Label"))); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); - } else if (name == "latexlog") { + } else if (name == "log") { dialog->setController(new ControlLog(*dialog)); dialog->setView(new QLog(*dialog)); dialog->bc().bp(new OkCancelPolicy); @@ -255,10 +253,6 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlCommand(*dialog, name)); dialog->setView(new QURL(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); - } else if (name == "vclog") { - dialog->setController(new ControlVCLog(*dialog)); - dialog->setView(new QVCLog(*dialog)); - dialog->bc().bp(new OkCancelPolicy); } else if (name == "vspace") { dialog->setController(new ControlVSpace(*dialog)); dialog->setView(new QVSpace(*dialog)); diff --git a/src/frontends/qt2/QLog.C b/src/frontends/qt2/QLog.C index 843d3aa08d..64dabd1f66 100644 --- a/src/frontends/qt2/QLog.C +++ b/src/frontends/qt2/QLog.C @@ -10,63 +10,38 @@ #include -#include "debug.h" -#include "qt_helpers.h" -#include "ControlLog.h" -#include "support/std_sstream.h" +#include "controllers/ControlLog.h" -#include -#include +#include "support/std_sstream.h" -#include "QLogDialog.h" #include "QLog.h" -#include "Qt2BC.h" +#include "QLogDialog.h" -#include +#include "qt_helpers.h" + +#include +#include -using std::ifstream; -using std::ostringstream; -using std::string; typedef QController > base_class; QLog::QLog(Dialog & parent) - : base_class(parent, _("LyX: LaTeX Log")) -{ -} + : base_class(parent, "") +{} void QLog::build_dialog() { dialog_.reset(new QLogDialog(this)); - - bcview().setCancel(dialog_->closePB); } void QLog::update_contents() { - std::pair const & logfile = - controller().logfile(); - - if (logfile.first == Buffer::buildlog) - setTitle(_("Build log")); - else - setTitle(_("LaTeX log")); - - dialog_->logTV->setText(""); - - ifstream ifstr(logfile.second.c_str()); - if (!ifstr) { - if (logfile.first == Buffer::buildlog) - dialog_->logTV->setText(qt_("No build log file found.")); - else - dialog_->logTV->setText(qt_("No LaTeX log file found.")); - return; - } + setTitle(controller().title()); - ostringstream ost; - ost << ifstr.rdbuf(); + std::ostringstream ss; + controller().getContents(ss); - dialog_->logTV->setText(toqstr(ost.str())); + dialog_->logTV->setText(toqstr(ss.str())); } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index bb1b592802..55c96416ab 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,10 @@ +2003-12-05 Angus Leeming + + * FormLog.C: much simplified, thanks to the more powerful interface + of ControlLog. + + * Dialogs.C: no need anymore to build a separate VCLog dialog. + 2003-12-05 Angus Leeming * forms/form_external.fd: try and mimic Jürgen's changes to diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 5cafa29dd2..11444a3c1e 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -36,7 +36,6 @@ #include "ControlTabular.h" #include "ControlTabularCreate.h" #include "ControlToc.h" -#include "ControlVCLog.h" #include "ControlVSpace.h" #include "ControlWrap.h" @@ -72,7 +71,6 @@ #include "FormText.h" #include "FormToc.h" #include "FormUrl.h" -#include "FormVCLog.h" #include "FormVSpace.h" #include "FormWrap.h" @@ -116,7 +114,7 @@ FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title, char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "box", "changes", "character", "citation", "error", "errorlist" , "ert", "external", "file", -"float", "graphics", "include", "index", "label", "latexlog", "mathpanel", +"float", "graphics", "include", "index", "label", "log", "mathpanel", "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek", "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc", "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators", @@ -127,7 +125,7 @@ char const * const dialognames[] = { "thesaurus", #endif -"toc", "url", "vclog", "vspace", "wrap" }; +"toc", "url", "vspace", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -221,7 +219,7 @@ Dialog * Dialogs::build(string const & name) dialog->setView(new FormText(*dialog, _("Label"), _("Label:|#L"))); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); - } else if (name == "latexlog") { + } else if (name == "log") { dialog->setController(new ControlLog(*dialog)); dialog->setView(new FormLog(*dialog)); dialog->bc().bp(new OkCancelPolicy); @@ -457,10 +455,6 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlCommand(*dialog, name)); dialog->setView(new FormUrl(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); - } else if (name == "vclog") { - dialog->setController(new ControlVCLog(*dialog)); - dialog->setView(new FormVCLog(*dialog)); - dialog->bc().bp(new OkCancelPolicy); } else if (name == "vspace") { dialog->setController(new ControlVSpace(*dialog)); dialog->setView(new FormVSpace(*dialog)); diff --git a/src/frontends/xforms/FormLog.C b/src/frontends/xforms/FormLog.C index 8560d19ca9..bcbf7ffb38 100644 --- a/src/frontends/xforms/FormLog.C +++ b/src/frontends/xforms/FormLog.C @@ -14,35 +14,23 @@ #include "ControlLog.h" #include "forms/form_browser.h" -#include "xformsBC.h" +#include "support/std_sstream.h" #include "lyx_forms.h" -using std::string; - - FormLog::FormLog(Dialog & parent) - : FormController(parent, _("LaTeX Log")) + : FormController(parent, "") {} void FormLog::update() { - bool const buildlog = controller().logfile().first == Buffer::buildlog; + setTitle(controller().title()); - string const title = buildlog ? - _("LyX: LaTeX Log") : - _("LyX: Literate Programming Build Log"); - setTitle(title); + std::ostringstream ss; + controller().getContents(ss); fl_clear_browser(dialog_->browser); - int const valid = fl_load_browser(dialog_->browser, - controller().logfile().second.c_str()); - if (!valid) { - string const error = buildlog ? - _("No LaTeX log file found.") : - _("No Literate Programming build log file found."); - fl_add_browser_line(dialog_->browser, error.c_str()); - } + fl_add_browser_line(dialog_->browser, ss.str().c_str()); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 51fe3b7ae6..a2682d04a2 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -109,6 +109,7 @@ using lyx::support::os::getTmpDir; using std::endl; using std::make_pair; +using std::pair; using std::string; using std::istringstream; @@ -1195,7 +1196,8 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) data = freefont2string(); if (!data.empty()) owner->getDialogs().show("character", data); - } else if (name == "document") + } + else if (name == "document") owner->getDialogs().showDocument(); else if (name == "findreplace") owner->getDialogs().showSearch(); @@ -1209,6 +1211,26 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) owner->getDialogs().showPrint(); else if (name == "spellchecker") owner->getDialogs().showSpellchecker(); + + else if (name == "latexlog") { + pair const logfile = + owner->buffer()->getLogName(); + switch (logfile.first) { + case Buffer::latexlog: + data = "latex "; + break; + case Buffer::buildlog: + data = "literate "; + break; + } + data += logfile.second; + owner->getDialogs().show("log", data); + } + else if (name == "vclog") { + string const data = "vc " + + owner->buffer()->lyxvc().getLogFile(); + owner->getDialogs().show("log", data); + } else owner->getDialogs().show(name, data); break; -- 2.39.2