Angus Leeming wrote:
>> I like that solution, too, but I have no clue how to implement
>> that.
> 
> Invoke lyx2lyx as:
> 
>                 string command = LibFileSearch("lyx2lyx",
>                 "lyx2lyx"); command += " -t"
>                         + tostr(LYX_FORMAT)
>                         + " -o " + tmpfile + ' '
> +                       + " -err " + logile + ' '
>                         + QuoteName(filename);
> 
> Thereafter, if logfile is not empty, invoke
> 
>         void Dialogs::show("log", logfile);
> 
> We would have to consolidate ControlLog and ControlVCLog into one,
> reading the name of the logfile from the data passed to it rather
> than their current (nasty) hard coding, but hey! That ain't so
> baaaddd...

Ok, José, the attached patch should make your life easy. You'll need 
to invoke the dialog as
        <lyxview>.getDialogs().show("log", "lyx2lyx <errorfile>");
where <lyxview> is the LyXView variable ('*owner') in 
LyXFunc::dispatch.

As a nice side effect, the patch also means we can get rid of 
ControlVCLog.[Ch], FormVCLog.[Ch] and QVCLog.[Ch].

-- 
Angus
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.548
diff -u -p -r1.548 lyxfunc.C
--- src/lyxfunc.C	1 Dec 2003 13:35:38 -0000	1.548
+++ src/lyxfunc.C	5 Dec 2003 13:03:56 -0000
@@ -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
 				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
 				owner->getDialogs().showPrint();
 			else if (name == "spellchecker")
 				owner->getDialogs().showSpellchecker();
+
+			else if (name == "latexlog") {
+				pair<Buffer::LogType, string> 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;
Index: src/frontends/controllers/ControlLog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlLog.C,v
retrieving revision 1.21
diff -u -p -r1.21 ControlLog.C
--- src/frontends/controllers/ControlLog.C	6 Oct 2003 15:42:45 -0000	1.21
+++ src/frontends/controllers/ControlLog.C	5 Dec 2003 13:03:56 -0000
@@ -13,23 +13,105 @@
 
 #include "ControlLog.h"
 
+#include "gettext.h"
+#include "lyxlex.h"
 
+#include "support/std_sstream.h"
+
+#include <fstream>
+
+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;
+	}
 }
Index: src/frontends/controllers/ControlLog.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlLog.h,v
retrieving revision 1.14
diff -u -p -r1.14 ControlLog.h
--- src/frontends/controllers/ControlLog.h	6 Oct 2003 15:42:45 -0000	1.14
+++ src/frontends/controllers/ControlLog.h	5 Dec 2003 13:03:56 -0000
@@ -14,8 +14,6 @@
 #define CONTROLLOG_H
 
 #include "Dialog.h"
-#include "buffer.h" // Buffer::LogType
-#include <utility>
 
 /**
  * A controller for a read-only text browser.
@@ -24,7 +22,9 @@ class ControlLog : public Dialog::Contro
 public:
 	///
 	ControlLog(Dialog &);
-	///
+	/** \param data should contain "<logtype> <logfile>"
+	 *  where <logtype> 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<Buffer::LogType, std::string> 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<Buffer::LogType, std::string> logfile_;
+	LOGTYPE type_;
+	std::string logfile_;
 };
 
 #endif // CONTROLLOG_H
Index: src/frontends/qt2/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Dialogs.C,v
retrieving revision 1.98
diff -u -p -r1.98 Dialogs.C
--- src/frontends/qt2/Dialogs.C	29 Nov 2003 09:39:35 -0000	1.98
+++ src/frontends/qt2/Dialogs.C	5 Dec 2003 13:03:57 -0000
@@ -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[] = { "ab
 "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 & n
 					   _("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 & n
 		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));
Index: src/frontends/qt2/QLog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLog.C,v
retrieving revision 1.22
diff -u -p -r1.22 QLog.C
--- src/frontends/qt2/QLog.C	6 Oct 2003 15:42:50 -0000	1.22
+++ src/frontends/qt2/QLog.C	5 Dec 2003 13:03:57 -0000
@@ -10,63 +10,38 @@
 
 #include <config.h>
 
-#include "debug.h"
-#include "qt_helpers.h"
-#include "ControlLog.h"
-#include "support/std_sstream.h"
+#include "controllers/ControlLog.h"
 
-#include <qtextview.h>
-#include <qpushbutton.h>
+#include "support/std_sstream.h"
 
-#include "QLogDialog.h"
 #include "QLog.h"
-#include "Qt2BC.h"
+#include "QLogDialog.h"
 
-#include <fstream>
+#include "qt_helpers.h"
+
+#include <qtextview.h>
+#include <qpushbutton.h>
 
-using std::ifstream;
-using std::ostringstream;
-using std::string;
 
 typedef QController<ControlLog, QView<QLogDialog> > 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<Buffer::LogType, string> 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()));
 }
Index: src/frontends/xforms/Dialogs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Dialogs.C,v
retrieving revision 1.120
diff -u -p -r1.120 Dialogs.C
--- src/frontends/xforms/Dialogs.C	28 Nov 2003 15:53:33 -0000	1.120
+++ src/frontends/xforms/Dialogs.C	5 Dec 2003 13:04:00 -0000
@@ -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(Dialo
 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 & n
 		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 & n
 		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));
Index: src/frontends/xforms/FormLog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormLog.C,v
retrieving revision 1.23
diff -u -p -r1.23 FormLog.C
--- src/frontends/xforms/FormLog.C	6 Oct 2003 15:42:55 -0000	1.23
+++ src/frontends/xforms/FormLog.C	5 Dec 2003 13:04:00 -0000
@@ -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<ControlLog, FormBrowser>(parent, _("LaTeX Log"))
+	: FormController<ControlLog, FormBrowser>(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());
 }

Reply via email to