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).
This commit is contained in:
Scott Kostyshak 2015-03-31 18:54:49 -04:00
parent 8c1a484cd2
commit 09700d5b71
6 changed files with 64 additions and 7 deletions

View File

@ -285,6 +285,10 @@ public:
/// we ran updateBuffer(), i.e., whether citation labels may need /// we ran updateBuffer(), i.e., whether citation labels may need
/// to be updated. /// to be updated.
mutable bool cite_labels_valid_; 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_; 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_; cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
unnamed = cloned_buffer_->d->unnamed; unnamed = cloned_buffer_->d->unnamed;
internal_buffer = cloned_buffer_->d->internal_buffer; 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(); enable = !isReadonly();
break; break;
case LFUN_BUFFER_VIEW_CACHE:
enable = (d->preview_file_).exists();
break;
default: default:
return false; return false;
} }
@ -2759,6 +2769,12 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
break; 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: default:
dispatched = false; dispatched = false;
break; break;
@ -4212,13 +4228,18 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
// (2) export with included children only // (2) export with included children only
ExportStatus const status = doExport(format, true, false, result_file); ExportStatus const status = doExport(format, true, false, result_file);
FileName const previewFile(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 (previewFile.exists()) {
if (!formats.view(*this, previewFile, format)) if (!formats.view(*this, previewFile, format))
return PreviewError; return PreviewError;
else if (status == ExportSuccess)
return PreviewSuccess;
else else
return status; return PreviewSuccess;
} }
else { else {
// Successful export but no output file? // Successful export but no output file?

View File

@ -459,6 +459,7 @@ enum FuncCode
LFUN_SPELLING_CONTINUOUSLY, // vfr, 20130324 LFUN_SPELLING_CONTINUOUSLY, // vfr, 20130324
LFUN_SEPARATOR_INSERT, // ef 20140502 LFUN_SEPARATOR_INSERT, // ef 20140502
LFUN_SERVER_GET_STATISTICS, // brokenclock 20141010 LFUN_SERVER_GET_STATISTICS, // brokenclock 20141010
LFUN_BUFFER_VIEW_CACHE, // skostysh 20150401
LFUN_LASTACTION // end of the table LFUN_LASTACTION // end of the table
}; };

View File

@ -1577,6 +1577,17 @@ void LyXAction::init()
* \endvar * \endvar
*/ */
{ LFUN_LAYOUT_RELOAD, "layout-reload", NoInternal, Layout }, { 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 * \var lyx::FuncCode lyx::LFUN_TEXTCLASS_APPLY
* \li Action: Sets the text class for the current buffer. * \li Action: Sets the text class for the current buffer.

View File

@ -18,7 +18,9 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferView.h" #include "BufferView.h"
#include "FuncRequest.h" #include "FuncRequest.h"
#include "FuncStatus.h"
#include "BufferList.h" #include "BufferList.h"
#include "LyX.h"
#include "ParIterator.h" #include "ParIterator.h"
#include "Text.h" #include "Text.h"
@ -63,11 +65,14 @@ GuiErrorList::GuiErrorList(GuiView & lv)
this, SLOT(slotClose())); this, SLOT(slotClose()));
connect(viewLogPB, SIGNAL(clicked()), connect(viewLogPB, SIGNAL(clicked()),
this, SLOT(viewLog())); this, SLOT(viewLog()));
connect(showAnywayPB, SIGNAL(clicked()),
this, SLOT(showAnyway()));
connect(errorsLW, SIGNAL(currentRowChanged(int)), connect(errorsLW, SIGNAL(currentRowChanged(int)),
this, SLOT(select())); this, SLOT(select()));
bc().setPolicy(ButtonPolicy::OkCancelPolicy); bc().setPolicy(ButtonPolicy::OkCancelPolicy);
bc().setCancel(closePB); bc().setCancel(closePB);
showAnywayPB->setEnabled(lyx::getStatus(FuncRequest(LFUN_BUFFER_VIEW_CACHE)).enabled());
} }
@ -102,6 +107,12 @@ void GuiErrorList::viewLog()
} }
void GuiErrorList::showAnyway()
{
dispatch(FuncRequest(LFUN_BUFFER_VIEW_CACHE));
}
void GuiErrorList::paramsToDialog() void GuiErrorList::paramsToDialog()
{ {
setTitle(toqstr(name_)); setTitle(toqstr(name_));

View File

@ -33,6 +33,8 @@ public Q_SLOTS:
void select(); void select();
/// open the LaTeX log /// open the LaTeX log
void viewLog(); void viewLog();
/// show the output file despite compilation errors
void showAnyway();
private: private:
/// ///

View File

@ -22,7 +22,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<item row="3" column="0" colspan="3" > <item row="3" column="0" colspan="4" >
<widget class="QTextBrowser" name="descriptionTB" > <widget class="QTextBrowser" name="descriptionTB" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy>
@ -54,14 +54,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="2" > <item row="4" column="3" >
<widget class="QPushButton" name="closePB" > <widget class="QPushButton" name="closePB" >
<property name="text" > <property name="text" >
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1" > <item row="4" column="2" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -87,7 +87,18 @@
</property> </property>
</widget> </widget>
</item> </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" > <widget class="QListWidget" name="errorsLW" >
<property name="toolTip" > <property name="toolTip" >
<string>Selecting an error will show the error message in the panel below, <string>Selecting an error will show the error message in the panel below,