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

View File

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

View File

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

View File

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

View File

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

View File

@ -536,6 +536,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
if (!runparams.nice) if (!runparams.nice)
incfile = mangled; incfile = mangled;
else if (!runparams.silent)
; // no warning wanted
else if (!isValidLaTeXFileName(incfile)) { else if (!isValidLaTeXFileName(incfile)) {
frontend::Alert::warning(_("Invalid filename"), frontend::Alert::warning(_("Invalid filename"),
_("The following filename will cause troubles " _("The following filename will cause troubles "
@ -626,42 +628,46 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
Buffer * tmp = loadIfNeeded(); Buffer * tmp = loadIfNeeded();
if (!tmp) { if (!tmp) {
docstring text = bformat(_("Could not load included " if (!runparams.silent) {
"file\n`%1$s'\n" docstring text = bformat(_("Could not load included "
"Please, check whether it actually exists."), "file\n`%1$s'\n"
included_file.displayName()); "Please, check whether it actually exists."),
Alert::warning(_("Missing included file"), text); included_file.displayName());
Alert::warning(_("Missing included file"), text);
}
return; return;
} }
if (tmp->params().baseClass() != masterBuffer->params().baseClass()) { if (!runparams.silent) {
// FIXME UNICODE if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
docstring text = bformat(_("Included file `%1$s'\n" // FIXME UNICODE
"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" docstring text = bformat(_("Included file `%1$s'\n"
"uses module `%2$s'\n" "has textclass `%2$s'\n"
"which is not used in parent file."), "while parent file has textclass `%3$s'."),
included_file.displayName(), from_utf8(module)); included_file.displayName(),
Alert::warning(_("Module not found"), text); 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; runparams.is_child = true;
if (!tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()). if (!tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()).
onlyPath().absFileName(), runparams, Buffer::OnlyBody)) { 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: " "was not exported correctly.\nWarning: "
"LaTeX export is probably incomplete."), "LaTeX export is probably incomplete."),
included_file.displayName()); included_file.displayName());
ErrorList const & el = tmp->errorList("Export"); ErrorList const & el = tmp->errorList("Export");
if (!el.empty()) if (!el.empty())
msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"), msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
msg, el.begin()->error, msg, el.begin()->error,
el.begin()->description); el.begin()->description);
Alert::warning(_("Export failure"), msg); Alert::warning(_("Export failure"), msg);
}
} }
runparams.encoding = oldEnc; runparams.encoding = oldEnc;
runparams.master_language = oldLang; runparams.master_language = oldLang;
@ -711,7 +719,7 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
included_file, included_file,
inc_format, tex_format, el); inc_format, tex_format, el);
if (!success) { if (!success && !runparams.silent) {
docstring msg = bformat(_("Included file `%1$s' " docstring msg = bformat(_("Included file `%1$s' "
"was not exported correctly.\nWarning: " "was not exported correctly.\nWarning: "
"LaTeX export is probably incomplete."), "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.) // converter on the included file. But that's just masochistic.)
FileName const included_file = includedFileName(buffer(), params()); FileName const included_file = includedFileName(buffer(), params());
if (!isLyXFileName(included_file.absFileName())) { 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 " bformat(_("LyX does not know how to include non-LyX files when "
"generating HTML output. Offending file:\n%1$s"), "generating HTML output. Offending file:\n%1$s"),
params()["filename"])); params()["filename"]));

View File

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