2 * \file InsetInclude.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Richard Heck (conversion to InsetCommand)
9 * Full author contact details are available in file CREDITS.
14 #include "InsetInclude.h"
17 #include "buffer_funcs.h"
18 #include "BufferList.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
22 #include "DispatchResult.h"
23 #include "ErrorList.h"
26 #include "FuncRequest.h"
27 #include "FuncStatus.h"
28 #include "LaTeXFeatures.h"
29 #include "LayoutFile.h"
30 #include "LayoutModuleList.h"
35 #include "MetricsInfo.h"
36 #include "OutputParams.h"
37 #include "TextClass.h"
38 #include "TocBackend.h"
40 #include "frontends/alert.h"
41 #include "frontends/Painter.h"
43 #include "graphics/PreviewImage.h"
44 #include "graphics/PreviewLoader.h"
46 #include "insets/InsetLabel.h"
47 #include "insets/InsetListingsParams.h"
48 #include "insets/RenderPreview.h"
50 #include "support/convert.h"
51 #include "support/debug.h"
52 #include "support/docstream.h"
53 #include "support/FileNameList.h"
54 #include "support/filetools.h"
55 #include "support/gettext.h"
56 #include "support/lassert.h"
57 #include "support/lstrings.h" // contains
58 #include "support/lyxalgo.h"
60 #include <boost/bind.hpp>
63 using namespace lyx::support;
67 namespace Alert = frontend::Alert;
72 docstring const uniqueID()
74 static unsigned int seed = 1000;
75 return "file" + convert<docstring>(++seed);
79 /// the type of inclusion
81 INCLUDE, VERB, INPUT, VERBAST, LISTINGS, NONE
85 Types type(string const & s)
89 if (s == "verbatiminput")
91 if (s == "verbatiminput*")
93 if (s == "lstinputlisting")
101 Types type(InsetCommandParams const & params)
103 return type(params.getCmdName());
107 bool isListings(InsetCommandParams const & params)
109 return type(params) == LISTINGS;
113 bool isVerbatim(InsetCommandParams const & params)
115 Types const t = type(params);
116 return t == VERB || t == VERBAST;
120 bool isInputOrInclude(InsetCommandParams const & params)
122 Types const t = type(params);
123 return t == INPUT || t == INCLUDE;
127 FileName const masterFileName(Buffer const & buffer)
129 return buffer.masterBuffer()->fileName();
133 void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
136 string const parentFilename(Buffer const & buffer)
138 return buffer.absFileName();
142 FileName const includedFilename(Buffer const & buffer,
143 InsetCommandParams const & params)
145 return makeAbsPath(to_utf8(params["filename"]),
146 onlyPath(parentFilename(buffer)));
150 InsetLabel * createLabel(docstring const & label_str)
152 if (label_str.empty())
154 InsetCommandParams icp(LABEL_CODE);
155 icp["name"] = label_str;
156 return new InsetLabel(icp);
162 InsetInclude::InsetInclude(InsetCommandParams const & p)
163 : InsetCommand(p, "include"), include_label(uniqueID()),
164 preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
165 set_label_(false), label_(0), child_buffer_(0)
167 preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
169 if (isListings(params())) {
170 InsetListingsParams listing_params(to_utf8(p["lstparams"]));
171 label_ = createLabel(from_utf8(listing_params.getParamValue("label")));
176 InsetInclude::InsetInclude(InsetInclude const & other)
177 : InsetCommand(other), include_label(other.include_label),
178 preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
179 set_label_(false), label_(0), child_buffer_(0)
181 preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
184 label_ = new InsetLabel(*other.label_);
188 InsetInclude::~InsetInclude()
194 void InsetInclude::setBuffer(Buffer & buffer)
196 InsetCommand::setBuffer(buffer);
198 label_->setBuffer(buffer);
202 ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
205 // This is only correct for the case of listings, but it'll do for now.
206 // In the other cases, this second parameter should just be empty.
207 static ParamInfo param_info_;
208 if (param_info_.empty()) {
209 param_info_.add("filename", ParamInfo::LATEX_REQUIRED);
210 param_info_.add("lstparams", ParamInfo::LATEX_OPTIONAL);
216 bool InsetInclude::isCompatibleCommand(string const & s)
218 return type(s) != NONE;
222 void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
224 switch (cmd.action) {
226 case LFUN_INSET_EDIT: {
227 editIncluded(to_utf8(params()["filename"]));
231 case LFUN_INSET_MODIFY: {
232 // It should be OK just to invalidate the cache is setParams()
234 // child_buffer_ = 0;
235 InsetCommandParams p(INCLUDE_CODE);
236 if (cmd.getArg(0) == "changetype") {
237 InsetCommand::doDispatch(cur, cmd);
240 InsetCommand::string2params("include", to_utf8(cmd.argument()), p);
241 if (!p.getCmdName().empty()) {
243 InsetListingsParams new_params(to_utf8(p["lstparams"]));
244 docstring const new_label =
245 from_utf8(new_params.getParamValue("label"));
247 if (new_label.empty()) {
253 old_label = label_->getParam("name");
255 label_ = createLabel(new_label);
256 label_->setBuffer(buffer());
259 if (new_label != old_label) {
260 label_->updateCommand(new_label);
261 // the label might have been adapted (duplicate)
262 if (new_label != label_->getParam("name")) {
263 new_params.addParam("label", "{" +
264 to_utf8(label_->getParam("name")) + "}", true);
265 p["lstparams"] = from_utf8(new_params.params());
276 //pass everything else up the chain
278 InsetCommand::doDispatch(cur, cmd);
284 void InsetInclude::editIncluded(string const & file)
286 string const ext = support::getExtension(file);
288 FuncRequest fr(LFUN_BUFFER_CHILD_OPEN, file);
291 // tex file or other text file in verbatim mode
292 formats.edit(buffer(),
293 support::makeAbsPath(file, support::onlyPath(buffer().absFileName())),
298 bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
299 FuncStatus & flag) const
301 switch (cmd.action) {
303 case LFUN_INSET_EDIT:
304 flag.setEnabled(true);
307 case LFUN_INSET_MODIFY:
308 if (cmd.getArg(0) == "changetype")
309 return InsetCommand::getStatus(cur, cmd, flag);
311 flag.setEnabled(true);
315 return InsetCommand::getStatus(cur, cmd, flag);
320 void InsetInclude::setParams(InsetCommandParams const & p)
322 // invalidate the cache
325 InsetCommand::setParams(p);
328 if (preview_->monitoring())
329 preview_->stopMonitoring();
331 if (type(params()) == INPUT)
332 add_preview(*preview_, *this, buffer());
334 buffer().updateBibfilesCache();
338 docstring InsetInclude::screenLabel() const
342 switch (type(params())) {
344 temp = buffer().B_("Input");
347 temp = buffer().B_("Verbatim Input");
350 temp = buffer().B_("Verbatim Input*");
353 temp = buffer().B_("Include");
356 temp = listings_label_;
359 LASSERT(false, /**/);
364 if (params()["filename"].empty())
367 temp += from_utf8(onlyFilename(to_utf8(params()["filename"])));
373 Buffer * InsetInclude::getChildBuffer() const
375 Buffer * childBuffer = loadIfNeeded();
377 // FIXME: recursive includes
378 return (childBuffer == &buffer()) ? 0 : childBuffer;
382 Buffer * InsetInclude::loadIfNeeded() const
384 // Don't try to load it again if we failed before.
385 if (failedtoload_ || isVerbatim(params()) || isListings(params()))
388 // Use cached Buffer if possible.
389 if (child_buffer_ != 0) {
390 if (theBufferList().isLoaded(child_buffer_))
391 return child_buffer_;
392 // Buffer vanished, so invalidate cache and try to reload.
396 string const parent_filename = buffer().absFileName();
397 FileName const included_file =
398 makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
400 if (!isLyXFilename(included_file.absFilename()))
403 Buffer * child = theBufferList().getBuffer(included_file);
405 // the readonly flag can/will be wrong, not anymore I think.
406 if (!included_file.exists())
409 child = theBufferList().newBuffer(included_file.absFilename());
411 // Buffer creation is not possible.
414 if (!child->loadLyXFile(included_file)) {
415 failedtoload_ = true;
416 //close the buffer we just opened
417 theBufferList().release(child);
421 if (!child->errorList("Parse").empty()) {
422 // FIXME: Do something.
425 child->setParent(&buffer());
426 // Cache the child buffer.
427 child_buffer_ = child;
432 int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
434 string incfile = to_utf8(params()["filename"]);
436 // Do nothing if no file name has been specified
440 FileName const included_file = includedFilename(buffer(), params());
442 // Check we're not trying to include ourselves.
443 // FIXME RECURSIVE INCLUDE
444 // This isn't sufficient, as the inclusion could be downstream.
445 // But it'll have to do for now.
446 if (isInputOrInclude(params()) &&
447 buffer().absFileName() == included_file.absFilename())
449 Alert::error(_("Recursive input"),
450 bformat(_("Attempted to include file %1$s in itself! "
451 "Ignoring inclusion."), from_utf8(incfile)));
455 Buffer const * const masterBuffer = buffer().masterBuffer();
457 // if incfile is relative, make it relative to the master
459 if (!FileName::isAbsolute(incfile)) {
461 incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
462 from_utf8(masterBuffer->filePath())));
465 // write it to a file (so far the complete file)
469 if (type(params()) == LISTINGS) {
470 exportfile = incfile;
471 mangled = DocFileName(included_file).mangledFilename();
473 exportfile = changeExtension(incfile, ".tex");
474 mangled = DocFileName(changeExtension(included_file.absFilename(), ".tex")).
478 FileName const writefile(makeAbsPath(mangled, masterBuffer->temppath()));
482 else if (!isValidLaTeXFilename(incfile)) {
483 frontend::Alert::warning(_("Invalid filename"),
484 _("The following filename is likely to cause trouble "
485 "when running the exported file through LaTeX: ") +
488 LYXERR(Debug::LATEX, "incfile:" << incfile);
489 LYXERR(Debug::LATEX, "exportfile:" << exportfile);
490 LYXERR(Debug::LATEX, "writefile:" << writefile);
492 if (runparams.inComment || runparams.dryrun) {
493 //Don't try to load or copy the file if we're
494 //in a comment or doing a dryrun
495 } else if (isInputOrInclude(params()) &&
496 isLyXFilename(included_file.absFilename())) {
497 //if it's a LyX file and we're inputting or including,
498 //try to load it so we can write the associated latex
502 Buffer * tmp = theBufferList().getBuffer(included_file);
504 if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
506 docstring text = bformat(_("Included file `%1$s'\n"
507 "has textclass `%2$s'\n"
508 "while parent file has textclass `%3$s'."),
509 included_file.displayName(),
510 from_utf8(tmp->params().documentClass().name()),
511 from_utf8(masterBuffer->params().documentClass().name()));
512 Alert::warning(_("Different textclasses"), text, true);
515 // Make sure modules used in child are all included in master
516 // FIXME It might be worth loading the children's modules into the master
517 // over in BufferParams rather than doing this check.
518 LayoutModuleList const masterModules = masterBuffer->params().getModules();
519 LayoutModuleList const childModules = tmp->params().getModules();
520 LayoutModuleList::const_iterator it = childModules.begin();
521 LayoutModuleList::const_iterator end = childModules.end();
522 for (; it != end; ++it) {
523 string const module = *it;
524 LayoutModuleList::const_iterator found =
525 find(masterModules.begin(), masterModules.end(), module);
526 if (found == masterModules.end()) {
527 docstring text = bformat(_("Included file `%1$s'\n"
528 "uses module `%2$s'\n"
529 "which is not used in parent file."),
530 included_file.displayName(), from_utf8(module));
531 Alert::warning(_("Module not found"), text);
535 tmp->markDepClean(masterBuffer->temppath());
537 // FIXME: handle non existing files
538 // FIXME: Second argument is irrelevant!
539 // since only_body is true, makeLaTeXFile will not look at second
540 // argument. Should we set it to string(), or should makeLaTeXFile
541 // make use of it somehow? (JMarc 20031002)
542 // The included file might be written in a different encoding
543 Encoding const * const oldEnc = runparams.encoding;
544 runparams.encoding = &tmp->params().encoding();
545 tmp->makeLaTeXFile(writefile,
546 masterFileName(buffer()).onlyPath().absFilename(),
548 runparams.encoding = oldEnc;
550 // In this case, it's not a LyX file, so we copy the file
551 // to the temp dir, so that .aux files etc. are not created
552 // in the original dir. Files included by this file will be
553 // found via input@path, see ../Buffer.cpp.
554 unsigned long const checksum_in = included_file.checksum();
555 unsigned long const checksum_out = writefile.checksum();
557 if (checksum_in != checksum_out) {
558 if (!included_file.copyTo(writefile)) {
561 to_utf8(bformat(_("Could not copy the file\n%1$s\n"
562 "into the temporary directory."),
563 from_utf8(included_file.absFilename()))));
569 string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
570 "latex" : "pdflatex";
571 switch (type(params())) {
574 incfile = latex_path(incfile);
576 os << '\\' << from_ascii(params().getCmdName()) << '{'
577 << from_utf8(incfile) << '}';
581 runparams.exportdata->addExternalFile(tex_format, writefile,
584 // \input wants file with extension (default is .tex)
585 if (!isLyXFilename(included_file.absFilename())) {
586 incfile = latex_path(incfile);
588 os << '\\' << from_ascii(params().getCmdName())
589 << '{' << from_utf8(incfile) << '}';
591 incfile = changeExtension(incfile, ".tex");
592 incfile = latex_path(incfile);
594 os << '\\' << from_ascii(params().getCmdName())
595 << '{' << from_utf8(incfile) << '}';
600 os << '\\' << from_ascii(params().getCmdName());
601 string const opt = to_utf8(params()["lstparams"]);
602 // opt is set in QInclude dialog and should have passed validation.
603 InsetListingsParams params(opt);
604 if (!params.params().empty())
605 os << "[" << from_utf8(params.params()) << "]";
606 os << '{' << from_utf8(incfile) << '}';
610 runparams.exportdata->addExternalFile(tex_format, writefile,
613 // \include don't want extension and demands that the
614 // file really have .tex
615 incfile = changeExtension(incfile, string());
616 incfile = latex_path(incfile);
618 os << '\\' << from_ascii(params().getCmdName()) << '{'
619 << from_utf8(incfile) << '}';
630 docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
635 // For verbatim and listings, we just include the contents of the file as-is.
636 // In the case of listings, we wrap it in <pre>.
637 bool const listing = isListings(params());
638 if (listing || isVerbatim(params())) {
641 // FIXME: We don't know the encoding of the file, default to UTF-8.
642 os << includedFilename(buffer(), params()).fileContents("UTF-8");
648 // We don't (yet) know how to Input or Include non-LyX files.
649 // (If we wanted to get really arcane, we could run some tex2html
650 // converter on the included file. But that's just masochistic.)
651 string const parent_filename = buffer().absFileName();
652 FileName const included_file =
653 makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
654 if (!isLyXFilename(included_file.absFilename())) {
655 frontend::Alert::warning(_("Unsupported Inclusion"),
656 bformat(_("LyX does not know how to include non-LyX files when "
657 "generating HTML output. Offending file:\n%1$s"),
658 params()["filename"]));
662 // In the other cases, we will generate the HTML and include it.
664 // Check we're not trying to include ourselves.
665 // FIXME RECURSIVE INCLUDE
666 if (buffer().absFileName() == included_file.absFilename()) {
667 Alert::error(_("Recursive input"),
668 bformat(_("Attempted to include file %1$s in itself! "
669 "Ignoring inclusion."), params()["filename"]));
673 Buffer const * const ibuf = loadIfNeeded();
676 ibuf->writeLyXHTMLSource(os, rp, true);
681 int InsetInclude::plaintext(odocstream & os, OutputParams const &) const
683 if (isVerbatim(params()) || isListings(params())) {
684 os << '[' << screenLabel() << '\n';
685 // FIXME: We don't know the encoding of the file, default to UTF-8.
686 os << includedFilename(buffer(), params()).fileContents("UTF-8");
688 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
690 docstring const str = '[' + screenLabel() + ']';
697 int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
699 string incfile = to_utf8(params()["filename"]);
701 // Do nothing if no file name has been specified
705 string const included_file = includedFilename(buffer(), params()).absFilename();
707 // Check we're not trying to include ourselves.
708 // FIXME RECURSIVE INCLUDE
709 // This isn't sufficient, as the inclusion could be downstream.
710 // But it'll have to do for now.
711 if (buffer().absFileName() == included_file) {
712 Alert::error(_("Recursive input"),
713 bformat(_("Attempted to include file %1$s in itself! "
714 "Ignoring inclusion."), from_utf8(incfile)));
718 // write it to a file (so far the complete file)
719 string const exportfile = changeExtension(incfile, ".sgml");
720 DocFileName writefile(changeExtension(included_file, ".sgml"));
722 if (loadIfNeeded()) {
723 Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
725 string const mangled = writefile.mangledFilename();
726 writefile = makeAbsPath(mangled,
727 buffer().masterBuffer()->temppath());
731 LYXERR(Debug::LATEX, "incfile:" << incfile);
732 LYXERR(Debug::LATEX, "exportfile:" << exportfile);
733 LYXERR(Debug::LATEX, "writefile:" << writefile);
735 tmp->makeDocBookFile(writefile, runparams, true);
738 runparams.exportdata->addExternalFile("docbook", writefile,
740 runparams.exportdata->addExternalFile("docbook-xml", writefile,
743 if (isVerbatim(params()) || isListings(params())) {
744 os << "<inlinegraphic fileref=\""
745 << '&' << include_label << ';'
746 << "\" format=\"linespecific\">";
748 os << '&' << include_label << ';';
754 void InsetInclude::validate(LaTeXFeatures & features) const
756 string incfile = to_utf8(params()["filename"]);
759 LASSERT(&buffer() == &features.buffer(), /**/);
761 string const included_file =
762 includedFilename(buffer(), params()).absFilename();
764 if (isLyXFilename(included_file))
765 writefile = changeExtension(included_file, ".sgml");
767 writefile = included_file;
769 if (!features.runparams().nice && !isVerbatim(params()) && !isListings(params())) {
770 incfile = DocFileName(writefile).mangledFilename();
771 writefile = makeAbsPath(incfile,
772 buffer().masterBuffer()->temppath()).absFilename();
775 features.includeFile(include_label, writefile);
777 if (isVerbatim(params()))
778 features.require("verbatim");
779 else if (isListings(params()))
780 features.require("listings");
782 // Here we must do the fun stuff...
783 // Load the file in the include if it needs
785 if (loadIfNeeded()) {
787 Buffer * const tmp = theBufferList().getBuffer(FileName(included_file));
788 // make sure the buffer isn't us
789 // FIXME RECURSIVE INCLUDES
790 // This is not sufficient, as recursive includes could be
791 // more than a file away. But it will do for now.
792 if (tmp && tmp != &buffer()) {
793 // We must temporarily change features.buffer,
794 // otherwise it would always be the master buffer,
795 // and nested includes would not work.
796 features.setBuffer(*tmp);
797 tmp->validate(features);
798 features.setBuffer(buffer());
804 void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
805 InsetIterator const & /*di*/) const
807 if (loadIfNeeded()) {
808 string const included_file = includedFilename(buffer(), params()).absFilename();
809 Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
810 BiblioInfo const & newkeys = tmp->localBibInfo();
811 keys.mergeBiblioInfo(newkeys);
816 void InsetInclude::updateBibfilesCache()
818 Buffer const * const child = getChildBuffer();
820 child->updateBibfilesCache(Buffer::UpdateChildOnly);
824 support::FileNameList const &
825 InsetInclude::getBibfilesCache() const
827 Buffer const * const child = getChildBuffer();
829 return child->getBibfilesCache(Buffer::UpdateChildOnly);
831 static support::FileNameList const empty;
836 void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
838 LASSERT(mi.base.bv, /**/);
840 bool use_preview = false;
841 if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
842 graphics::PreviewImage const * pimage =
843 preview_->getPreviewImage(mi.base.bv->buffer());
844 use_preview = pimage && pimage->image();
848 preview_->metrics(mi, dim);
852 button_.update(screenLabel(), true);
854 button_.metrics(mi, dim);
857 Box b(0, dim.wid, -dim.asc, dim.des);
862 void InsetInclude::draw(PainterInfo & pi, int x, int y) const
864 LASSERT(pi.base.bv, /**/);
866 bool use_preview = false;
867 if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
868 graphics::PreviewImage const * pimage =
869 preview_->getPreviewImage(pi.base.bv->buffer());
870 use_preview = pimage && pimage->image();
874 preview_->draw(pi, x, y);
876 button_.draw(pi, x, y);
880 docstring InsetInclude::contextMenu(BufferView const &, int, int) const
882 return from_ascii("context-include");
886 Inset::DisplayType InsetInclude::display() const
888 return type(params()) == INPUT ? Inline : AlignCenter;
897 void InsetInclude::fileChanged() const
899 Buffer const * const buffer = updateFrontend();
903 preview_->removePreview(*buffer);
904 add_preview(*preview_.get(), *this, *buffer);
905 preview_->startLoading(*buffer);
911 bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
913 FileName const included_file = includedFilename(buffer, params);
915 return type(params) == INPUT && params.preview() &&
916 included_file.isReadableFile();
920 docstring latexString(InsetInclude const & inset)
923 // We don't need to set runparams.encoding since this will be done
924 // by latex() anyway.
925 OutputParams runparams(0);
926 runparams.flavor = OutputParams::LATEX;
927 inset.latex(os, runparams);
933 void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
934 Buffer const & buffer)
936 InsetCommandParams const & params = inset.params();
937 if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
938 preview_wanted(params, buffer)) {
939 renderer.setAbsFile(includedFilename(buffer, params));
940 docstring const snippet = latexString(inset);
941 renderer.addPreview(snippet, buffer);
948 void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
950 Buffer const & buffer = ploader.buffer();
951 if (!preview_wanted(params(), buffer))
953 preview_->setAbsFile(includedFilename(buffer, params()));
954 docstring const snippet = latexString(*this);
955 preview_->addPreview(snippet, ploader);
959 void InsetInclude::addToToc(DocIterator const & cpit)
961 TocBackend & backend = buffer().tocBackend();
963 if (isListings(params())) {
965 label_->addToToc(cpit);
967 InsetListingsParams p(to_utf8(params()["lstparams"]));
968 string caption = p.getParamValue("caption");
971 Toc & toc = backend.toc("listing");
972 docstring str = convert<docstring>(toc.size() + 1)
973 + ". " + from_utf8(caption);
974 DocIterator pit = cpit;
975 toc.push_back(TocItem(pit, 0, str));
978 Buffer const * const childbuffer = getChildBuffer();
982 Toc & toc = backend.toc("child");
983 docstring str = childbuffer->fileName().displayName();
984 toc.push_back(TocItem(cpit, 0, str));
986 TocList & toclist = backend.tocs();
987 childbuffer->tocBackend().update();
988 TocList const & childtoclist = childbuffer->tocBackend().tocs();
989 TocList::const_iterator it = childtoclist.begin();
990 TocList::const_iterator const end = childtoclist.end();
991 for(; it != end; ++it)
992 toclist[it->first].insert(toclist[it->first].end(),
993 it->second.begin(), it->second.end());
997 void InsetInclude::updateCommand()
1002 docstring old_label = label_->getParam("name");
1003 label_->updateCommand(old_label, false);
1004 // the label might have been adapted (duplicate)
1005 docstring new_label = label_->getParam("name");
1006 if (old_label == new_label)
1009 // update listings parameters...
1010 InsetCommandParams p(INCLUDE_CODE);
1012 InsetListingsParams par(to_utf8(params()["lstparams"]));
1013 par.addParam("label", "{" + to_utf8(new_label) + "}", true);
1014 p["lstparams"] = from_utf8(par.params());
1018 void InsetInclude::updateLabels(ParIterator const & it)
1020 Buffer const * const childbuffer = getChildBuffer();
1022 childbuffer->updateLabels(Buffer::UpdateChildOnly);
1025 if (!isListings(params()))
1029 label_->updateLabels(it);
1031 InsetListingsParams const par(to_utf8(params()["lstparams"]));
1032 if (par.getParamValue("caption").empty()) {
1033 listings_label_ = buffer().B_("Program Listing");
1036 Buffer const & master = *buffer().masterBuffer();
1037 Counters & counters = master.params().documentClass().counters();
1038 docstring const cnt = from_ascii("listing");
1039 listings_label_ = master.B_("Program Listing");
1040 if (counters.hasCounter(cnt)) {
1042 listings_label_ += " " + convert<docstring>(counters.value(cnt));