Silence unwanted error popup on copying

The new HTML clipboard export could cause error message boxes on copying
data to the clipboard (bug #8866). These are now suppressed, like all other
errors which might occur for preparing the clipboard data.
This commit is contained in:
Georg Baum 2013-11-12 20:52:35 +01:00
parent 70b0298fe2
commit be468136df
7 changed files with 92 additions and 68 deletions

View File

@ -323,7 +323,7 @@ public:
CloneList * clone_list_;
/// are we in the process of exporting this buffer?
mutable bool doing_export;
/// compute statistics
/// \p from initial position
/// \p to points to the end position
@ -1536,7 +1536,10 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
lyxerr << "File '" << fname << "' was not closed properly." << endl;
}
errors("Export");
if (runparams_in.silent)
errorList.clear();
else
errors("Export");
return !failed_export;
}
@ -1916,7 +1919,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
<< ";\n";
css << "}\n";
}
docstring const dstyles = css.str();
if (!dstyles.empty()) {
bool written = false;
@ -2000,7 +2003,10 @@ int Buffer::runChktex()
setBusy(false);
errors("ChkTeX");
if (runparams.silent)
d->errorLists["ChkTeX"].clear();
else
errors("ChkTeX");
return res;
}
@ -3439,7 +3445,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to)
string const paramName = "key";
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
if (it->lyxCode() != CITE_CODE)
if (it->lyxCode() != CITE_CODE)
continue;
InsetCommand * inset = it->asInsetCommand();
docstring const oldValue = inset->getParam(paramName);
@ -3968,17 +3974,21 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
// Emit the signal to show the error list or copy it back to the
// cloned Buffer so that it can be emitted afterwards.
if (format != backend_format) {
if (d->cloned_buffer_) {
if (runparams.silent)
error_list.clear();
else if (d->cloned_buffer_)
d->cloned_buffer_->d->errorLists[error_type] =
d->errorLists[error_type];
} else
else
errors(error_type);
// also to the children, in case of master-buffer-view
ListOfBuffers clist = getDescendents();
ListOfBuffers::const_iterator cit = clist.begin();
ListOfBuffers::const_iterator const cen = clist.end();
for (; cit != cen; ++cit) {
if (d->cloned_buffer_) {
if (runparams.silent)
(*cit)->d->errorLists[error_type].clear();
else if (d->cloned_buffer_) {
// Enable reverse search by copying back the
// texrow object to the cloned buffer.
// FIXME: this is not thread safe.
@ -4671,16 +4681,16 @@ void Buffer::Impl::updateStatistics(DocIterator & from, DocIterator & to, bool s
word_count_ = 0;
char_count_ = 0;
blank_count_ = 0;
for (DocIterator dit = from ; dit != to && !dit.atEnd(); ) {
if (!dit.inTexted()) {
dit.forwardPos();
continue;
}
Paragraph const & par = dit.paragraph();
pos_type const pos = dit.pos();
// Copied and adapted from isWordSeparator() in Paragraph
if (pos == dit.lastpos()) {
inword = false;
@ -4694,7 +4704,7 @@ void Buffer::Impl::updateStatistics(DocIterator & from, DocIterator & to, bool s
break;
continue;
} else if (!par.isDeleted(pos)) {
if (par.isWordSeparator(pos))
if (par.isWordSeparator(pos))
inword = false;
else if (!inword) {
++word_count_;

View File

@ -532,6 +532,8 @@ void putClipboard(ParagraphList const & paragraphs,
OutputParams runparams(encodings.fromLyXName("utf8"));
// We do not need to produce images, etc.
runparams.dryrun = true;
// We are not interested in errors (bug 8866)
runparams.silent = true;
buffer->writeLyXHTMLSource(oshtml, runparams, Buffer::FullSource);
theClipboard().put(lyx, oshtml.str(), plaintext);

View File

@ -28,13 +28,13 @@ OutputParams::OutputParams(Encoding const * enc)
inIndexEntry(false), inIPA(false), inDeletedInset(0),
changeOfDeletedInset(Change::UNCHANGED),
par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false),
dryrun(false), pass_thru(false),
dryrun(false), silent(false), pass_thru(false),
html_disable_captions(false), html_in_par(false),
html_make_pars(true), for_toc(false), for_tooltip(false),
for_search(false), includeall(false)
{
// Note: in PreviewLoader::Impl::dumpPreamble
// OutputParams runparams(0);
// OutputParams runparams(0);
if (enc && enc->package() == Encoding::japanese)
use_japanese = true;
}
@ -47,7 +47,7 @@ OutputParams::~OutputParams()
bool OutputParams::isLaTeX() const
{
return flavor == LATEX || flavor == LUATEX || flavor == DVILUATEX
|| flavor == PDFLATEX || flavor == XETEX;
|| flavor == PDFLATEX || flavor == XETEX;
}

View File

@ -38,7 +38,7 @@ public:
TEXT,
LYX
};
enum MathFlavor {
NotApplicable,
MathAsMathML,
@ -70,10 +70,10 @@ public:
bool isLaTeX() const;
/// does this flavour support full unicode?
bool isFullUnicode() const;
/// Same, but for math output, which only matter is XHTML output.
MathFlavor math_flavor;
/** Are we to write a 'nice' LaTeX file or not.
This esentially seems to mean whether InsetInclude, InsetGraphics
and InsetExternal should add the absolute path to any external
@ -217,7 +217,7 @@ public:
/** The change information of the outermost logically deleted inset.
* changeOfDeletedInset shall only be evaluated if inDeletedInset > 0.
*/
*/
Change changeOfDeletedInset;
/** allow output of only part of the top-level paragraphs
@ -239,28 +239,31 @@ public:
/// is this the last paragraph in the current buffer/inset?
bool isLastPar;
/** whether or not do actual file copying and image conversion
* This mode will be used to preview the source code
*/
bool dryrun;
/// whether to display output errors or not
bool silent;
/// Should we output verbatim or escape LaTeX's special chars?
bool pass_thru;
/// Should we output captions?
bool html_disable_captions;
/// Are we already in a paragraph?
bool html_in_par;
/// Does the present context even permit paragraphs?
bool html_make_pars;
/// Are we generating this material for inclusion in a TOC-like entity?
bool for_toc;
/// Are we generating this material for inclusion in a tooltip?
bool for_tooltip;

View File

@ -191,7 +191,7 @@ void InsetHyperlink::latex(otexstream & os,
pair<docstring, docstring> name_latexed =
runparams.encoding->latexString(name, runparams.dryrun);
name = name_latexed.first;
if (!name_latexed.second.empty()) {
if (!name_latexed.second.empty() && !runparams.silent) {
// issue a warning about omitted characters
// FIXME: should be passed to the error dialog
frontend::Alert::warning(_("Uncodable characters"),

View File

@ -536,6 +536,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
if (!runparams.nice)
incfile = mangled;
else if (!runparams.silent)
; // no warning wanted
else if (!isValidLaTeXFileName(incfile)) {
frontend::Alert::warning(_("Invalid filename"),
_("The following filename will cause troubles "
@ -626,42 +628,46 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
Buffer * tmp = loadIfNeeded();
if (!tmp) {
docstring text = bformat(_("Could not load included "
"file\n`%1$s'\n"
"Please, check whether it actually exists."),
included_file.displayName());
Alert::warning(_("Missing included file"), text);
if (!runparams.silent) {
docstring text = bformat(_("Could not load included "
"file\n`%1$s'\n"
"Please, check whether it actually exists."),
included_file.displayName());
Alert::warning(_("Missing included file"), text);
}
return;
}
if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
// FIXME UNICODE
docstring text = bformat(_("Included file `%1$s'\n"
"has textclass `%2$s'\n"
"while parent file has textclass `%3$s'."),
included_file.displayName(),
from_utf8(tmp->params().documentClass().name()),
from_utf8(masterBuffer->params().documentClass().name()));
Alert::warning(_("Different textclasses"), text, true);
}
// Make sure modules used in child are all included in master
// FIXME It might be worth loading the children's modules into the master
// over in BufferParams rather than doing this check.
LayoutModuleList const masterModules = masterBuffer->params().getModules();
LayoutModuleList const childModules = tmp->params().getModules();
LayoutModuleList::const_iterator it = childModules.begin();
LayoutModuleList::const_iterator end = childModules.end();
for (; it != end; ++it) {
string const module = *it;
LayoutModuleList::const_iterator found =
find(masterModules.begin(), masterModules.end(), module);
if (found == masterModules.end()) {
if (!runparams.silent) {
if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
// FIXME UNICODE
docstring text = bformat(_("Included file `%1$s'\n"
"uses module `%2$s'\n"
"which is not used in parent file."),
included_file.displayName(), from_utf8(module));
Alert::warning(_("Module not found"), text);
"has textclass `%2$s'\n"
"while parent file has textclass `%3$s'."),
included_file.displayName(),
from_utf8(tmp->params().documentClass().name()),
from_utf8(masterBuffer->params().documentClass().name()));
Alert::warning(_("Different textclasses"), text, true);
}
// Make sure modules used in child are all included in master
// FIXME It might be worth loading the children's modules into the master
// over in BufferParams rather than doing this check.
LayoutModuleList const masterModules = masterBuffer->params().getModules();
LayoutModuleList const childModules = tmp->params().getModules();
LayoutModuleList::const_iterator it = childModules.begin();
LayoutModuleList::const_iterator end = childModules.end();
for (; it != end; ++it) {
string const module = *it;
LayoutModuleList::const_iterator found =
find(masterModules.begin(), masterModules.end(), module);
if (found == masterModules.end()) {
docstring text = bformat(_("Included file `%1$s'\n"
"uses module `%2$s'\n"
"which is not used in parent file."),
included_file.displayName(), from_utf8(module));
Alert::warning(_("Module not found"), text);
}
}
}
@ -688,16 +694,18 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
runparams.is_child = true;
if (!tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()).
onlyPath().absFileName(), runparams, Buffer::OnlyBody)) {
docstring msg = bformat(_("Included file `%1$s' "
if (!runparams.silent) {
docstring msg = bformat(_("Included file `%1$s' "
"was not exported correctly.\nWarning: "
"LaTeX export is probably incomplete."),
included_file.displayName());
ErrorList const & el = tmp->errorList("Export");
if (!el.empty())
msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
ErrorList const & el = tmp->errorList("Export");
if (!el.empty())
msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
msg, el.begin()->error,
el.begin()->description);
Alert::warning(_("Export failure"), msg);
Alert::warning(_("Export failure"), msg);
}
}
runparams.encoding = oldEnc;
runparams.master_language = oldLang;
@ -711,7 +719,7 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
included_file,
inc_format, tex_format, el);
if (!success) {
if (!success && !runparams.silent) {
docstring msg = bformat(_("Included file `%1$s' "
"was not exported correctly.\nWarning: "
"LaTeX export is probably incomplete."),
@ -769,7 +777,8 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
// converter on the included file. But that's just masochistic.)
FileName const included_file = includedFileName(buffer(), params());
if (!isLyXFileName(included_file.absFileName())) {
frontend::Alert::warning(_("Unsupported Inclusion"),
if (!rp.silent)
frontend::Alert::warning(_("Unsupported Inclusion"),
bformat(_("LyX does not know how to include non-LyX files when "
"generating HTML output. Offending file:\n%1$s"),
params()["filename"]));

View File

@ -213,7 +213,7 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
+ _("no more lstline delimiters available") + ">";
code = subst(code, from_ascii("!"), delim_error);
delimiter = lstinline_delimiters;
if (!runparams.dryrun) {
if (!runparams.dryrun && !runparams.silent) {
// FIXME: warning should be passed to the error dialog
frontend::Alert::warning(_("Running out of delimiters"),
_("For inline program listings, one character must be reserved\n"
@ -253,7 +253,7 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
runparams.encoding = save_enc;
}
if (!uncodable.empty()) {
if (!uncodable.empty() && !runparams.silent) {
// issue a warning about omitted characters
// FIXME: should be passed to the error dialog
frontend::Alert::warning(_("Uncodable characters in listings inset"),