On Wed, Mar 25, 2015 at 2:27 PM, Scott Kostyshak <skost...@lyx.org> wrote:
> On Wed, Mar 25, 2015 at 4:18 AM, Jürgen Spitzmüller <sp...@lyx.org> wrote:

>> A separate error dialog would probably be easier to implement. It would be
>> somewhat more elegant to have it in the LaTeX error dialog, but I am fine
>> with both solutions.
>
> OK. So it seems like ideally we would have a button in the LaTeX error
> dialog if that dialog is shown. And if that dialog is not shown, then
> a separate dialog saying there was an error and then also having a
> button. I don't know how long this will take me to implement.

Attached is a patch. Any comments?

Scott
From 26362d929b9e979bbd76fb480350e4f21cdde269 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Tue, 31 Mar 2015 18:54:49 -0400
Subject: [PATCH] Button for showing PDF if compilation error

Building on cd8be655, we still allow viewing a produced PDF even if
there were compilation errors. However, now the user must click the
"Show Output Anyway" button in the LaTeX Errors dialog. The reason
is that before, there was a chance that the user would not realize
there was an error (because the PDF would be shown over the error
dialog). The approach in this commit makes it more clear that there
is an error.

A new LFUN is introduced, LFUN_BUFFER_VIEW_CACHE. It is useful not
just for the implementation of the "Show Output Anyway" button, but
also to show the last compiled version of a document, which can save
time if a document takes a long time to compile (e.g. heavy use of
knitr).
---
 src/Buffer.cpp                      | 27 ++++++++++++++++++++++++---
 src/FuncCode.h                      |  1 +
 src/LyXAction.cpp                   | 11 +++++++++++
 src/frontends/qt4/GuiErrorList.cpp  |  8 ++++++++
 src/frontends/qt4/GuiErrorList.h    |  2 ++
 src/frontends/qt4/ui/ErrorListUi.ui | 19 +++++++++++++++----
 6 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 10e6727..7022139 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -285,6 +285,10 @@ public:
 	/// we ran updateBuffer(), i.e., whether citation labels may need
 	/// to be updated.
 	mutable bool cite_labels_valid_;
+	/// these hold the file name and format, written to by Buffer::preview
+	/// and read from by LFUN_BUFFER_VIEW_CACHE.
+	FileName preview_file_;
+	string preview_format_;
 
 	mutable RefCache ref_cache_;
 
@@ -420,6 +424,8 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
 	cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
 	unnamed = cloned_buffer_->d->unnamed;
 	internal_buffer = cloned_buffer_->d->internal_buffer;
+	preview_file_ = cloned_buffer_->d->preview_file_;
+	preview_format_ = cloned_buffer_->d->preview_format_;
 }
 
 
@@ -2420,6 +2426,10 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 		enable = !isReadonly();
 		break;
 
+	case LFUN_BUFFER_VIEW_CACHE:
+		enable = (d->preview_file_).exists();
+		break;
+
 	default:
 		return false;
 	}
@@ -2759,6 +2769,12 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 		break;
 	}
 
+	case LFUN_BUFFER_VIEW_CACHE:
+		if (!formats.view(*this, d->preview_file_,
+				  d->preview_format_))
+			dr.setMessage(_("Error viewing the output file."));
+		break;
+
 	default:
 		dispatched = false;
 		break;
@@ -4212,13 +4228,18 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
 	// (2) export with included children only
 	ExportStatus const status = doExport(format, true, false, result_file);
 	FileName const previewFile(result_file);
+
+	LATTEST (isClone());
+	d->cloned_buffer_->d->preview_file_ = previewFile;
+	d->cloned_buffer_->d->preview_format_ = format;
+
+	if (status != ExportSuccess)
+		return status;
 	if (previewFile.exists()) {
 		if (!formats.view(*this, previewFile, format))
 			return PreviewError;
-		else if (status == ExportSuccess)
-			return PreviewSuccess;
 		else
-			return status;
+			return PreviewSuccess;
 	}
 	else {
 		// Successful export but no output file?
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 3bd0cd0..b590b38 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -459,6 +459,7 @@ enum FuncCode
 	LFUN_SPELLING_CONTINUOUSLY,     // vfr, 20130324
 	LFUN_SEPARATOR_INSERT,          // ef 20140502
 	LFUN_SERVER_GET_STATISTICS,     // brokenclock 20141010
+	LFUN_BUFFER_VIEW_CACHE,         // skostysh 20150401
 	LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 4ac1a0e..1ba2ef8 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1578,6 +1578,17 @@ void LyXAction::init()
  */
 		{ LFUN_LAYOUT_RELOAD, "layout-reload", NoInternal, Layout },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_VIEW_CACHE
+ * \li Action: Opens the file that was created from last preview of this buffer.
+ * \li Notion: This LFUN is called by the "Show Output Anyway" button in the LaTeX
+ *             Errors dialog. It can also be called by the user, which is useful
+ *             if the document takes a long time to compile, and you just
+ *             want to see the last previewed version.
+ * \li Syntax: buffer-view-cache
+ * \endvar
+ */
+		{ LFUN_BUFFER_VIEW_CACHE, "buffer-view-cache", ReadOnly, Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_TEXTCLASS_APPLY
  * \li Action: Sets the text class for the current buffer.
  * \li Syntax: textclass-apply <TEXTCLASS>
diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp
index af83be6..d6cc3e2 100644
--- a/src/frontends/qt4/GuiErrorList.cpp
+++ b/src/frontends/qt4/GuiErrorList.cpp
@@ -63,6 +63,8 @@ GuiErrorList::GuiErrorList(GuiView & lv)
 		this, SLOT(slotClose()));
 	connect(viewLogPB, SIGNAL(clicked()),
 		this, SLOT(viewLog()));
+	connect(showAnywayPB, SIGNAL(clicked()),
+		this, SLOT(showAnyway()));
 	connect(errorsLW, SIGNAL(currentRowChanged(int)),
 		this, SLOT(select()));
 
@@ -102,6 +104,12 @@ void GuiErrorList::viewLog()
 }
 
 
+void GuiErrorList::showAnyway()
+{
+	dispatch(FuncRequest(LFUN_BUFFER_VIEW_CACHE));
+}
+
+
 void GuiErrorList::paramsToDialog()
 {
 	setTitle(toqstr(name_));
diff --git a/src/frontends/qt4/GuiErrorList.h b/src/frontends/qt4/GuiErrorList.h
index 5ceb9f0..fe4393d 100644
--- a/src/frontends/qt4/GuiErrorList.h
+++ b/src/frontends/qt4/GuiErrorList.h
@@ -33,6 +33,8 @@ public Q_SLOTS:
 	void select();
 	/// open the LaTeX log
 	void viewLog();
+	/// show the output file despite compilation errors
+	void showAnyway();
 
 private:
 	///
diff --git a/src/frontends/qt4/ui/ErrorListUi.ui b/src/frontends/qt4/ui/ErrorListUi.ui
index 9c51af7..9775a9f 100644
--- a/src/frontends/qt4/ui/ErrorListUi.ui
+++ b/src/frontends/qt4/ui/ErrorListUi.ui
@@ -22,7 +22,7 @@
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item row="3" column="0" colspan="3" >
+   <item row="3" column="0" colspan="4" >
     <widget class="QTextBrowser" name="descriptionTB" >
      <property name="sizePolicy" >
       <sizepolicy>
@@ -54,14 +54,14 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="2" >
+   <item row="4" column="3" >
     <widget class="QPushButton" name="closePB" >
      <property name="text" >
       <string>&amp;Close</string>
      </property>
     </widget>
    </item>
-   <item row="4" column="1" >
+   <item row="4" column="2" >
     <spacer>
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
@@ -87,7 +87,18 @@
      </property>
     </widget>
    </item>
-   <item row="1" column="0" colspan="3" >
+   <item row="4" column="1" >
+    <widget class="QPushButton" name="showAnywayPB" >
+     <property name="toolTip" >
+       <string>Attempt to show the output even if there were
+compilation errors</string>
+     </property>
+     <property name="text" >
+      <string>Show Output &amp;Anyway</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="4" >
     <widget class="QListWidget" name="errorsLW" >
      <property name="toolTip" >
       <string>Selecting an error will show the error message in the panel below, 
-- 
2.1.0

Reply via email to