]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetInclude.cpp
s/updateLabels/updateBuffer/g, per a suggestion of Abdel's.
[features.git] / src / insets / InsetInclude.cpp
index a652dbdbc4b7f843e3df63b0c14a121f08343ce4..ccd0dda6ac97c6b0251e92c265609d6011c319e9 100644 (file)
 #include "LayoutFile.h"
 #include "LayoutModuleList.h"
 #include "LyX.h"
-#include "LyXFunc.h"
 #include "LyXRC.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
+#include "output_xhtml.h"
 #include "OutputParams.h"
 #include "TextClass.h"
 #include "TocBackend.h"
@@ -147,20 +147,20 @@ FileName const includedFilename(Buffer const & buffer,
 }
 
 
-InsetLabel * createLabel(docstring const & label_str)
+InsetLabel * createLabel(Buffer * buf, docstring const & label_str)
 {
        if (label_str.empty())
                return 0;
        InsetCommandParams icp(LABEL_CODE);
        icp["name"] = label_str;
-       return new InsetLabel(icp);
+       return new InsetLabel(buf, icp);
 }
 
 } // namespace anon
 
 
-InsetInclude::InsetInclude(InsetCommandParams const & p)
-       : InsetCommand(p, "include"), include_label(uniqueID()),
+InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
+       : InsetCommand(buf, p, "include"), include_label(uniqueID()),
          preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
          set_label_(false), label_(0), child_buffer_(0)
 {
@@ -168,7 +168,7 @@ InsetInclude::InsetInclude(InsetCommandParams const & p)
 
        if (isListings(params())) {
                InsetListingsParams listing_params(to_utf8(p["lstparams"]));
-               label_ = createLabel(from_utf8(listing_params.getParamValue("label")));
+               label_ = createLabel(buffer_, from_utf8(listing_params.getParamValue("label")));
        }
 }
 
@@ -199,6 +199,12 @@ void InsetInclude::setBuffer(Buffer & buffer)
 }
 
 
+void InsetInclude::setChildBuffer(Buffer * buffer)
+{
+       child_buffer_ = buffer;
+}
+
+
 ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
 {
        // FIXME
@@ -221,7 +227,6 @@ bool InsetInclude::isCompatibleCommand(string const & s)
 
 void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       LASSERT(cur.buffer() == &buffer(), return);
        switch (cmd.action) {
 
        case LFUN_INSET_EDIT: {
@@ -253,7 +258,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
                                        if (label_) 
                                                old_label = label_->getParam("name");
                                        else {
-                                               label_ = createLabel(new_label);
+                                               label_ = createLabel(buffer_, new_label);
                                                label_->setBuffer(buffer());
                                        }                                       
 
@@ -336,6 +341,18 @@ void InsetInclude::setParams(InsetCommandParams const & p)
 }
 
 
+bool InsetInclude::isChildIncluded() const
+{
+       std::list<std::string> includeonlys =
+               buffer().params().getIncludedChildren();
+       if (includeonlys.empty())
+               return true;
+       return (std::find(includeonlys.begin(),
+                         includeonlys.end(),
+                         to_utf8(params()["filename"])) != includeonlys.end());
+}
+
+
 docstring InsetInclude::screenLabel() const
 {
        docstring temp;
@@ -351,7 +368,10 @@ docstring InsetInclude::screenLabel() const
                        temp = buffer().B_("Verbatim Input*");
                        break;
                case INCLUDE:
-                       temp = buffer().B_("Include");
+                       if (isChildIncluded())
+                               temp = buffer().B_("Include");
+                       else
+                               temp += buffer().B_("Include (excluded)");
                        break;
                case LISTINGS:
                        temp = listings_label_;
@@ -382,6 +402,12 @@ Buffer * InsetInclude::getChildBuffer() const
 
 Buffer * InsetInclude::loadIfNeeded() const
 {
+       // This is for background export and preview. We don't want to load the
+       // cloned child document again.
+       if (child_buffer_ && theBufferList().isLoaded(child_buffer_)
+                 && child_buffer_->isClone())
+               return child_buffer_;
+
        // Don't try to load it again if we failed before.
        if (failedtoload_ || isVerbatim(params()) || isListings(params()))
                return 0;
@@ -541,12 +567,16 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
                // argument. Should we set it to string(), or should makeLaTeXFile
                // make use of it somehow? (JMarc 20031002)
                // The included file might be written in a different encoding
+               // and language.
                Encoding const * const oldEnc = runparams.encoding;
+               Language const * const oldLang = runparams.master_language;
                runparams.encoding = &tmp->params().encoding();
+               runparams.master_language = buffer().params().language;
                tmp->makeLaTeXFile(writefile,
                                   masterFileName(buffer()).onlyPath().absFilename(),
                                   runparams, false);
                runparams.encoding = oldEnc;
+               runparams.master_language = oldLang;
        } else {
                // In this case, it's not a LyX file, so we copy the file
                // to the temp dir, so that .aux files etc. are not created
@@ -628,7 +658,7 @@ int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
 }
 
 
-docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
+docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const &rp) const
 {
        if (rp.inComment)
                 return docstring();
@@ -638,11 +668,11 @@ docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
        bool const listing = isListings(params());
        if (listing || isVerbatim(params())) {
                if (listing)
-                       os << "<pre>\n";
+                       xs << html::StartTag("pre");
                // FIXME: We don't know the encoding of the file, default to UTF-8.
-               os << includedFilename(buffer(), params()).fileContents("UTF-8");
+               xs << includedFilename(buffer(), params()).fileContents("UTF-8");
                if (listing)
-                       os << "</pre>\n";
+                       xs << html::EndTag("pre");
                return docstring();
        }
 
@@ -654,9 +684,9 @@ docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
                makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
        if (!isLyXFilename(included_file.absFilename())) {
                frontend::Alert::warning(_("Unsupported Inclusion"),
-                                        _("LyX does not know how to include non-LyX files when "
-                                          "generating HTML output. Offending file: ") +
-                                           params()["filename"]);
+                                        bformat(_("LyX does not know how to include non-LyX files when "
+                                                  "generating HTML output. Offending file:\n%1$s"),
+                                                   params()["filename"]));
                return docstring();
        }
 
@@ -674,7 +704,7 @@ docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
        Buffer const * const ibuf = loadIfNeeded();
        if (!ibuf)
                return docstring();
-       ibuf->writeLyXHTMLSource(os, rp, true);
+       ibuf->writeLyXHTMLSource(xs.os(), rp, true);
        return docstring();
 }
 
@@ -946,7 +976,8 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
 } // namespace anon
 
 
-void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
+void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
+       graphics::PreviewLoader & ploader) const
 {
        Buffer const & buffer = ploader.buffer();
        if (!preview_wanted(params(), buffer))
@@ -1016,18 +1047,18 @@ void InsetInclude::updateCommand()
        setParams(p);   
 }
 
-void InsetInclude::updateLabels(ParIterator const & it)
+void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype)
 {
        Buffer const * const childbuffer = getChildBuffer();
        if (childbuffer) {
-               childbuffer->updateLabels(Buffer::UpdateChildOnly);
+               childbuffer->updateBuffer(Buffer::UpdateChildOnly, utype);
                return;
        }
        if (!isListings(params()))
                return;
 
        if (label_)
-               label_->updateLabels(it);
+               label_->updateBuffer(it, utype);
 
        InsetListingsParams const par(to_utf8(params()["lstparams"]));
        if (par.getParamValue("caption").empty()) {
@@ -1039,7 +1070,7 @@ void InsetInclude::updateLabels(ParIterator const & it)
        docstring const cnt = from_ascii("listing");
        listings_label_ = master.B_("Program Listing");
        if (counters.hasCounter(cnt)) {
-               counters.step(cnt);
+               counters.step(cnt, utype);
                listings_label_ += " " + convert<docstring>(counters.value(cnt));
        }
 }