]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInclude.cpp
#7379 avoid the wrap spell check question when buffer is empty
[lyx.git] / src / insets / InsetInclude.cpp
index bdb332d9d6947cc081f4eea4b6c504124058a124..d62f4ccb6ed29c231082db811aaa40c60eb371df 100644 (file)
@@ -463,7 +463,7 @@ Buffer * InsetInclude::loadIfNeeded() const
        } else {
                // The file was already loaded, so, simply
                // inform parent buffer about local macros.
-               Buffer * parent = const_cast<Buffer *>(&buffer());
+               Buffer const * parent = &buffer();
                child->setParent(parent);
                MacroNameSet macros;
                child->listMacroNames(macros);
@@ -479,13 +479,13 @@ Buffer * InsetInclude::loadIfNeeded() const
 }
 
 
-int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
+void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
 {
        string incfile = to_utf8(params()["filename"]);
 
        // Do nothing if no file name has been specified
        if (incfile.empty())
-               return 0;
+               return;
 
        FileName const included_file = includedFileName(buffer(), params());
 
@@ -499,7 +499,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                Alert::error(_("Recursive input"),
                               bformat(_("Attempted to include file %1$s in itself! "
                               "Ignoring inclusion."), from_utf8(incfile)));
-               return 0;
+               return;
        }
 
        Buffer const * const masterBuffer = buffer().masterBuffer();
@@ -555,8 +555,14 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                // try to load it so we can write the associated latex
                
                Buffer * tmp = loadIfNeeded();
-               if (!tmp)
-                       return false;
+               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);
+                       return;
+               }
 
                if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
                        // FIXME UNICODE
@@ -608,9 +614,19 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                runparams.master_language = buffer().params().language;
                runparams.par_begin = 0;
                runparams.par_end = tmp->paragraphs().size();
-               tmp->makeLaTeXFile(writefile,
-                                  masterFileName(buffer()).onlyPath().absFileName(),
-                                  runparams, false);
+               if (!tmp->makeLaTeXFile(writefile, masterFileName(buffer()).
+                               onlyPath().absFileName(), runparams, false)) {
+                       docstring msg = bformat(_("Included file `%1$s' "
+                                       "was not exported correctly.\nWarning: "
+                                       "LaTeX export is probably incomplete."),
+                                       included_file.displayName());
+                       ErrorList & 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);
+               }
                runparams.encoding = oldEnc;
                runparams.master_language = oldLang;
        } else {
@@ -628,7 +644,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                                        to_utf8(bformat(_("Could not copy the file\n%1$s\n"
                                                                  "into the temporary directory."),
                                                   from_utf8(included_file.absFileName()))));
-                               return 0;
+                               return;
                        }
                }
        }
@@ -689,8 +705,6 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
        case NONE:
                break;
        }
-
-       return 0;
 }
 
 
@@ -960,14 +974,16 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
 
 docstring latexString(InsetInclude const & inset)
 {
-       odocstringstream os;
+       TexRow texrow;
+       odocstringstream ods;
+       otexstream os(ods, texrow);
        // We don't need to set runparams.encoding since this will be done
        // by latex() anyway.
        OutputParams runparams(0);
        runparams.flavor = OutputParams::LATEX;
        inset.latex(os, runparams);
 
-       return os.str();
+       return ods.str();
 }
 
 
@@ -998,7 +1014,7 @@ void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
 }
 
 
-void InsetInclude::addToToc(DocIterator const & cpit)
+void InsetInclude::addToToc(DocIterator const & cpit) const
 {
        TocBackend & backend = buffer().tocBackend();