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 "output_xhtml.h"
37 #include "OutputParams.h"
38 #include "TextClass.h"
39 #include "TocBackend.h"
41 #include "frontends/alert.h"
42 #include "frontends/Painter.h"
44 #include "graphics/PreviewImage.h"
45 #include "graphics/PreviewLoader.h"
47 #include "insets/InsetLabel.h"
48 #include "insets/InsetListingsParams.h"
49 #include "insets/RenderPreview.h"
51 #include "support/convert.h"
52 #include "support/debug.h"
53 #include "support/docstream.h"
54 #include "support/FileNameList.h"
55 #include "support/filetools.h"
56 #include "support/gettext.h"
57 #include "support/lassert.h"
58 #include "support/lstrings.h" // contains
59 #include "support/lyxalgo.h"
61 #include <boost/bind.hpp>
64 using namespace lyx::support;
68 namespace Alert = frontend::Alert;
73 docstring const uniqueID()
75 static unsigned int seed = 1000;
76 return "file" + convert<docstring>(++seed);
80 /// the type of inclusion
82 INCLUDE, VERB, INPUT, VERBAST, LISTINGS, NONE
86 Types type(string const & s)
90 if (s == "verbatiminput")
92 if (s == "verbatiminput*")
94 if (s == "lstinputlisting")
102 Types type(InsetCommandParams const & params)
104 return type(params.getCmdName());
108 bool isListings(InsetCommandParams const & params)
110 return type(params) == LISTINGS;
114 bool isVerbatim(InsetCommandParams const & params)
116 Types const t = type(params);
117 return t == VERB || t == VERBAST;
121 bool isInputOrInclude(InsetCommandParams const & params)
123 Types const t = type(params);
124 return t == INPUT || t == INCLUDE;
128 FileName const masterFileName(Buffer const & buffer)
130 return buffer.masterBuffer()->fileName();
134 void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
137 string const parentFilename(Buffer const & buffer)
139 return buffer.absFileName();
143 FileName const includedFilename(Buffer const & buffer,
144 InsetCommandParams const & params)
146 return makeAbsPath(to_utf8(params["filename"]),
147 onlyPath(parentFilename(buffer)));
151 InsetLabel * createLabel(Buffer * buf, docstring const & label_str)
153 if (label_str.empty())
155 InsetCommandParams icp(LABEL_CODE);
156 icp["name"] = label_str;
157 return new InsetLabel(buf, icp);
163 InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
164 : InsetCommand(buf, p, "include"), include_label(uniqueID()),
165 preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
166 set_label_(false), label_(0), child_buffer_(0)
168 preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
170 if (isListings(params())) {
171 InsetListingsParams listing_params(to_utf8(p["lstparams"]));
172 label_ = createLabel(buffer_, from_utf8(listing_params.getParamValue("label")));
177 InsetInclude::InsetInclude(InsetInclude const & other)
178 : InsetCommand(other), include_label(other.include_label),
179 preview_(new RenderMonitoredPreview(this)), failedtoload_(false),
180 set_label_(false), label_(0), child_buffer_(0)
182 preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
185 label_ = new InsetLabel(*other.label_);
189 InsetInclude::~InsetInclude()
195 void InsetInclude::setBuffer(Buffer & buffer)
197 InsetCommand::setBuffer(buffer);
199 label_->setBuffer(buffer);
203 ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
206 // This is only correct for the case of listings, but it'll do for now.
207 // In the other cases, this second parameter should just be empty.
208 static ParamInfo param_info_;
209 if (param_info_.empty()) {
210 param_info_.add("filename", ParamInfo::LATEX_REQUIRED);
211 param_info_.add("lstparams", ParamInfo::LATEX_OPTIONAL);
217 bool InsetInclude::isCompatibleCommand(string const & s)
219 return type(s) != NONE;
223 void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
225 switch (cmd.action) {
227 case LFUN_INSET_EDIT: {
228 editIncluded(to_utf8(params()["filename"]));
232 case LFUN_INSET_MODIFY: {
233 // It should be OK just to invalidate the cache is setParams()
235 // child_buffer_ = 0;
236 InsetCommandParams p(INCLUDE_CODE);
237 if (cmd.getArg(0) == "changetype") {
238 InsetCommand::doDispatch(cur, cmd);
241 InsetCommand::string2params("include", to_utf8(cmd.argument()), p);
242 if (!p.getCmdName().empty()) {
244 InsetListingsParams new_params(to_utf8(p["lstparams"]));
245 docstring const new_label =
246 from_utf8(new_params.getParamValue("label"));
248 if (new_label.empty()) {
254 old_label = label_->getParam("name");
256 label_ = createLabel(buffer_, new_label);
257 label_->setBuffer(buffer());
260 if (new_label != old_label) {
261 label_->updateCommand(new_label);
262 // the label might have been adapted (duplicate)
263 if (new_label != label_->getParam("name")) {
264 new_params.addParam("label", "{" +
265 to_utf8(label_->getParam("name")) + "}", true);
266 p["lstparams"] = from_utf8(new_params.params());
277 //pass everything else up the chain
279 InsetCommand::doDispatch(cur, cmd);
285 void InsetInclude::editIncluded(string const & file)
287 string const ext = support::getExtension(file);
289 FuncRequest fr(LFUN_BUFFER_CHILD_OPEN, file);
292 // tex file or other text file in verbatim mode
293 formats.edit(buffer(),
294 support::makeAbsPath(file, support::onlyPath(buffer().absFileName())),
299 bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
300 FuncStatus & flag) const
302 switch (cmd.action) {
304 case LFUN_INSET_EDIT:
305 flag.setEnabled(true);
308 case LFUN_INSET_MODIFY:
309 if (cmd.getArg(0) == "changetype")
310 return InsetCommand::getStatus(cur, cmd, flag);
312 flag.setEnabled(true);
316 return InsetCommand::getStatus(cur, cmd, flag);
321 void InsetInclude::setParams(InsetCommandParams const & p)
323 // invalidate the cache
326 InsetCommand::setParams(p);
329 if (preview_->monitoring())
330 preview_->stopMonitoring();
332 if (type(params()) == INPUT)
333 add_preview(*preview_, *this, buffer());
335 buffer().updateBibfilesCache();
339 docstring InsetInclude::screenLabel() const
343 switch (type(params())) {
345 temp = buffer().B_("Input");
348 temp = buffer().B_("Verbatim Input");
351 temp = buffer().B_("Verbatim Input*");
354 temp = buffer().B_("Include");
357 temp = listings_label_;
360 LASSERT(false, /**/);
365 if (params()["filename"].empty())
368 temp += from_utf8(onlyFilename(to_utf8(params()["filename"])));
374 Buffer * InsetInclude::getChildBuffer() const
376 Buffer * childBuffer = loadIfNeeded();
378 // FIXME: recursive includes
379 return (childBuffer == &buffer()) ? 0 : childBuffer;
383 Buffer * InsetInclude::loadIfNeeded() const
385 // Don't try to load it again if we failed before.
386 if (failedtoload_ || isVerbatim(params()) || isListings(params()))
389 // Use cached Buffer if possible.
390 if (child_buffer_ != 0) {
391 if (theBufferList().isLoaded(child_buffer_))
392 return child_buffer_;
393 // Buffer vanished, so invalidate cache and try to reload.
397 string const parent_filename = buffer().absFileName();
398 FileName const included_file =
399 makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
401 if (!isLyXFilename(included_file.absFilename()))
404 Buffer * child = theBufferList().getBuffer(included_file);
406 // the readonly flag can/will be wrong, not anymore I think.
407 if (!included_file.exists())
410 child = theBufferList().newBuffer(included_file.absFilename());
412 // Buffer creation is not possible.
415 if (!child->loadLyXFile(included_file)) {
416 failedtoload_ = true;
417 //close the buffer we just opened
418 theBufferList().release(child);
422 if (!child->errorList("Parse").empty()) {
423 // FIXME: Do something.
426 child->setParent(&buffer());
427 // Cache the child buffer.
428 child_buffer_ = child;
433 int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const
435 string incfile = to_utf8(params()["filename"]);
437 // Do nothing if no file name has been specified
441 FileName const included_file = includedFilename(buffer(), params());
443 // Check we're not trying to include ourselves.
444 // FIXME RECURSIVE INCLUDE
445 // This isn't sufficient, as the inclusion could be downstream.
446 // But it'll have to do for now.
447 if (isInputOrInclude(params()) &&
448 buffer().absFileName() == included_file.absFilename())
450 Alert::error(_("Recursive input"),
451 bformat(_("Attempted to include file %1$s in itself! "
452 "Ignoring inclusion."), from_utf8(incfile)));
456 Buffer const * const masterBuffer = buffer().masterBuffer();
458 // if incfile is relative, make it relative to the master
460 if (!FileName::isAbsolute(incfile)) {
462 incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
463 from_utf8(masterBuffer->filePath())));
466 // write it to a file (so far the complete file)
470 if (type(params()) == LISTINGS) {
471 exportfile = incfile;
472 mangled = DocFileName(included_file).mangledFilename();
474 exportfile = changeExtension(incfile, ".tex");
475 mangled = DocFileName(changeExtension(included_file.absFilename(), ".tex")).
479 FileName const writefile(makeAbsPath(mangled, masterBuffer->temppath()));
483 else if (!isValidLaTeXFilename(incfile)) {
484 frontend::Alert::warning(_("Invalid filename"),
485 _("The following filename is likely to cause trouble "
486 "when running the exported file through LaTeX: ") +
489 LYXERR(Debug::LATEX, "incfile:" << incfile);
490 LYXERR(Debug::LATEX, "exportfile:" << exportfile);
491 LYXERR(Debug::LATEX, "writefile:" << writefile);
493 if (runparams.inComment || runparams.dryrun) {
494 //Don't try to load or copy the file if we're
495 //in a comment or doing a dryrun
496 } else if (isInputOrInclude(params()) &&
497 isLyXFilename(included_file.absFilename())) {
498 //if it's a LyX file and we're inputting or including,
499 //try to load it so we can write the associated latex
503 Buffer * tmp = theBufferList().getBuffer(included_file);
505 if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
507 docstring text = bformat(_("Included file `%1$s'\n"
508 "has textclass `%2$s'\n"
509 "while parent file has textclass `%3$s'."),
510 included_file.displayName(),
511 from_utf8(tmp->params().documentClass().name()),
512 from_utf8(masterBuffer->params().documentClass().name()));
513 Alert::warning(_("Different textclasses"), text, true);
516 // Make sure modules used in child are all included in master
517 // FIXME It might be worth loading the children's modules into the master
518 // over in BufferParams rather than doing this check.
519 LayoutModuleList const masterModules = masterBuffer->params().getModules();
520 LayoutModuleList const childModules = tmp->params().getModules();
521 LayoutModuleList::const_iterator it = childModules.begin();
522 LayoutModuleList::const_iterator end = childModules.end();
523 for (; it != end; ++it) {
524 string const module = *it;
525 LayoutModuleList::const_iterator found =
526 find(masterModules.begin(), masterModules.end(), module);
527 if (found == masterModules.end()) {
528 docstring text = bformat(_("Included file `%1$s'\n"
529 "uses module `%2$s'\n"
530 "which is not used in parent file."),
531 included_file.displayName(), from_utf8(module));
532 Alert::warning(_("Module not found"), text);
536 tmp->markDepClean(masterBuffer->temppath());
538 // FIXME: handle non existing files
539 // FIXME: Second argument is irrelevant!
540 // since only_body is true, makeLaTeXFile will not look at second
541 // argument. Should we set it to string(), or should makeLaTeXFile
542 // make use of it somehow? (JMarc 20031002)
543 // The included file might be written in a different encoding
545 Encoding const * const oldEnc = runparams.encoding;
546 Language const * const oldLang = runparams.master_language;
547 runparams.encoding = &tmp->params().encoding();
548 runparams.master_language = buffer().params().language;
549 tmp->makeLaTeXFile(writefile,
550 masterFileName(buffer()).onlyPath().absFilename(),
552 runparams.encoding = oldEnc;
553 runparams.master_language = oldLang;
555 // In this case, it's not a LyX file, so we copy the file
556 // to the temp dir, so that .aux files etc. are not created
557 // in the original dir. Files included by this file will be
558 // found via input@path, see ../Buffer.cpp.
559 unsigned long const checksum_in = included_file.checksum();
560 unsigned long const checksum_out = writefile.checksum();
562 if (checksum_in != checksum_out) {
563 if (!included_file.copyTo(writefile)) {
566 to_utf8(bformat(_("Could not copy the file\n%1$s\n"
567 "into the temporary directory."),
568 from_utf8(included_file.absFilename()))));
574 string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
575 "latex" : "pdflatex";
576 switch (type(params())) {
579 incfile = latex_path(incfile);
581 os << '\\' << from_ascii(params().getCmdName()) << '{'
582 << from_utf8(incfile) << '}';
586 runparams.exportdata->addExternalFile(tex_format, writefile,
589 // \input wants file with extension (default is .tex)
590 if (!isLyXFilename(included_file.absFilename())) {
591 incfile = latex_path(incfile);
593 os << '\\' << from_ascii(params().getCmdName())
594 << '{' << from_utf8(incfile) << '}';
596 incfile = changeExtension(incfile, ".tex");
597 incfile = latex_path(incfile);
599 os << '\\' << from_ascii(params().getCmdName())
600 << '{' << from_utf8(incfile) << '}';
605 os << '\\' << from_ascii(params().getCmdName());
606 string const opt = to_utf8(params()["lstparams"]);
607 // opt is set in QInclude dialog and should have passed validation.
608 InsetListingsParams params(opt);
609 if (!params.params().empty())
610 os << "[" << from_utf8(params.params()) << "]";
611 os << '{' << from_utf8(incfile) << '}';
615 runparams.exportdata->addExternalFile(tex_format, writefile,
618 // \include don't want extension and demands that the
619 // file really have .tex
620 incfile = changeExtension(incfile, string());
621 incfile = latex_path(incfile);
623 os << '\\' << from_ascii(params().getCmdName()) << '{'
624 << from_utf8(incfile) << '}';
635 docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const &rp) const
640 // For verbatim and listings, we just include the contents of the file as-is.
641 // In the case of listings, we wrap it in <pre>.
642 bool const listing = isListings(params());
643 if (listing || isVerbatim(params())) {
645 xs << StartTag("pre");
646 // FIXME: We don't know the encoding of the file, default to UTF-8.
647 xs << includedFilename(buffer(), params()).fileContents("UTF-8");
653 // We don't (yet) know how to Input or Include non-LyX files.
654 // (If we wanted to get really arcane, we could run some tex2html
655 // converter on the included file. But that's just masochistic.)
656 string const parent_filename = buffer().absFileName();
657 FileName const included_file =
658 makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
659 if (!isLyXFilename(included_file.absFilename())) {
660 frontend::Alert::warning(_("Unsupported Inclusion"),
661 bformat(_("LyX does not know how to include non-LyX files when "
662 "generating HTML output. Offending file:\n%1$s"),
663 params()["filename"]));
667 // In the other cases, we will generate the HTML and include it.
669 // Check we're not trying to include ourselves.
670 // FIXME RECURSIVE INCLUDE
671 if (buffer().absFileName() == included_file.absFilename()) {
672 Alert::error(_("Recursive input"),
673 bformat(_("Attempted to include file %1$s in itself! "
674 "Ignoring inclusion."), params()["filename"]));
678 Buffer const * const ibuf = loadIfNeeded();
681 ibuf->writeLyXHTMLSource(xs.os(), rp, true);
686 int InsetInclude::plaintext(odocstream & os, OutputParams const &) const
688 if (isVerbatim(params()) || isListings(params())) {
689 os << '[' << screenLabel() << '\n';
690 // FIXME: We don't know the encoding of the file, default to UTF-8.
691 os << includedFilename(buffer(), params()).fileContents("UTF-8");
693 return PLAINTEXT_NEWLINE + 1; // one char on a separate line
695 docstring const str = '[' + screenLabel() + ']';
702 int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
704 string incfile = to_utf8(params()["filename"]);
706 // Do nothing if no file name has been specified
710 string const included_file = includedFilename(buffer(), params()).absFilename();
712 // Check we're not trying to include ourselves.
713 // FIXME RECURSIVE INCLUDE
714 // This isn't sufficient, as the inclusion could be downstream.
715 // But it'll have to do for now.
716 if (buffer().absFileName() == included_file) {
717 Alert::error(_("Recursive input"),
718 bformat(_("Attempted to include file %1$s in itself! "
719 "Ignoring inclusion."), from_utf8(incfile)));
723 // write it to a file (so far the complete file)
724 string const exportfile = changeExtension(incfile, ".sgml");
725 DocFileName writefile(changeExtension(included_file, ".sgml"));
727 if (loadIfNeeded()) {
728 Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
730 string const mangled = writefile.mangledFilename();
731 writefile = makeAbsPath(mangled,
732 buffer().masterBuffer()->temppath());
736 LYXERR(Debug::LATEX, "incfile:" << incfile);
737 LYXERR(Debug::LATEX, "exportfile:" << exportfile);
738 LYXERR(Debug::LATEX, "writefile:" << writefile);
740 tmp->makeDocBookFile(writefile, runparams, true);
743 runparams.exportdata->addExternalFile("docbook", writefile,
745 runparams.exportdata->addExternalFile("docbook-xml", writefile,
748 if (isVerbatim(params()) || isListings(params())) {
749 os << "<inlinegraphic fileref=\""
750 << '&' << include_label << ';'
751 << "\" format=\"linespecific\">";
753 os << '&' << include_label << ';';
759 void InsetInclude::validate(LaTeXFeatures & features) const
761 string incfile = to_utf8(params()["filename"]);
764 LASSERT(&buffer() == &features.buffer(), /**/);
766 string const included_file =
767 includedFilename(buffer(), params()).absFilename();
769 if (isLyXFilename(included_file))
770 writefile = changeExtension(included_file, ".sgml");
772 writefile = included_file;
774 if (!features.runparams().nice && !isVerbatim(params()) && !isListings(params())) {
775 incfile = DocFileName(writefile).mangledFilename();
776 writefile = makeAbsPath(incfile,
777 buffer().masterBuffer()->temppath()).absFilename();
780 features.includeFile(include_label, writefile);
782 if (isVerbatim(params()))
783 features.require("verbatim");
784 else if (isListings(params()))
785 features.require("listings");
787 // Here we must do the fun stuff...
788 // Load the file in the include if it needs
790 if (loadIfNeeded()) {
792 Buffer * const tmp = theBufferList().getBuffer(FileName(included_file));
793 // make sure the buffer isn't us
794 // FIXME RECURSIVE INCLUDES
795 // This is not sufficient, as recursive includes could be
796 // more than a file away. But it will do for now.
797 if (tmp && tmp != &buffer()) {
798 // We must temporarily change features.buffer,
799 // otherwise it would always be the master buffer,
800 // and nested includes would not work.
801 features.setBuffer(*tmp);
802 tmp->validate(features);
803 features.setBuffer(buffer());
809 void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
810 InsetIterator const & /*di*/) const
812 if (loadIfNeeded()) {
813 string const included_file = includedFilename(buffer(), params()).absFilename();
814 Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
815 BiblioInfo const & newkeys = tmp->localBibInfo();
816 keys.mergeBiblioInfo(newkeys);
821 void InsetInclude::updateBibfilesCache()
823 Buffer const * const child = getChildBuffer();
825 child->updateBibfilesCache(Buffer::UpdateChildOnly);
829 support::FileNameList const &
830 InsetInclude::getBibfilesCache() const
832 Buffer const * const child = getChildBuffer();
834 return child->getBibfilesCache(Buffer::UpdateChildOnly);
836 static support::FileNameList const empty;
841 void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
843 LASSERT(mi.base.bv, /**/);
845 bool use_preview = false;
846 if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
847 graphics::PreviewImage const * pimage =
848 preview_->getPreviewImage(mi.base.bv->buffer());
849 use_preview = pimage && pimage->image();
853 preview_->metrics(mi, dim);
857 button_.update(screenLabel(), true);
859 button_.metrics(mi, dim);
862 Box b(0, dim.wid, -dim.asc, dim.des);
867 void InsetInclude::draw(PainterInfo & pi, int x, int y) const
869 LASSERT(pi.base.bv, /**/);
871 bool use_preview = false;
872 if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
873 graphics::PreviewImage const * pimage =
874 preview_->getPreviewImage(pi.base.bv->buffer());
875 use_preview = pimage && pimage->image();
879 preview_->draw(pi, x, y);
881 button_.draw(pi, x, y);
885 docstring InsetInclude::contextMenu(BufferView const &, int, int) const
887 return from_ascii("context-include");
891 Inset::DisplayType InsetInclude::display() const
893 return type(params()) == INPUT ? Inline : AlignCenter;
902 void InsetInclude::fileChanged() const
904 Buffer const * const buffer = updateFrontend();
908 preview_->removePreview(*buffer);
909 add_preview(*preview_.get(), *this, *buffer);
910 preview_->startLoading(*buffer);
916 bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
918 FileName const included_file = includedFilename(buffer, params);
920 return type(params) == INPUT && params.preview() &&
921 included_file.isReadableFile();
925 docstring latexString(InsetInclude const & inset)
928 // We don't need to set runparams.encoding since this will be done
929 // by latex() anyway.
930 OutputParams runparams(0);
931 runparams.flavor = OutputParams::LATEX;
932 inset.latex(os, runparams);
938 void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
939 Buffer const & buffer)
941 InsetCommandParams const & params = inset.params();
942 if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
943 preview_wanted(params, buffer)) {
944 renderer.setAbsFile(includedFilename(buffer, params));
945 docstring const snippet = latexString(inset);
946 renderer.addPreview(snippet, buffer);
953 void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
954 graphics::PreviewLoader & ploader) const
956 Buffer const & buffer = ploader.buffer();
957 if (!preview_wanted(params(), buffer))
959 preview_->setAbsFile(includedFilename(buffer, params()));
960 docstring const snippet = latexString(*this);
961 preview_->addPreview(snippet, ploader);
965 void InsetInclude::addToToc(DocIterator const & cpit)
967 TocBackend & backend = buffer().tocBackend();
969 if (isListings(params())) {
971 label_->addToToc(cpit);
973 InsetListingsParams p(to_utf8(params()["lstparams"]));
974 string caption = p.getParamValue("caption");
977 Toc & toc = backend.toc("listing");
978 docstring str = convert<docstring>(toc.size() + 1)
979 + ". " + from_utf8(caption);
980 DocIterator pit = cpit;
981 toc.push_back(TocItem(pit, 0, str));
984 Buffer const * const childbuffer = getChildBuffer();
988 Toc & toc = backend.toc("child");
989 docstring str = childbuffer->fileName().displayName();
990 toc.push_back(TocItem(cpit, 0, str));
992 TocList & toclist = backend.tocs();
993 childbuffer->tocBackend().update();
994 TocList const & childtoclist = childbuffer->tocBackend().tocs();
995 TocList::const_iterator it = childtoclist.begin();
996 TocList::const_iterator const end = childtoclist.end();
997 for(; it != end; ++it)
998 toclist[it->first].insert(toclist[it->first].end(),
999 it->second.begin(), it->second.end());
1003 void InsetInclude::updateCommand()
1008 docstring old_label = label_->getParam("name");
1009 label_->updateCommand(old_label, false);
1010 // the label might have been adapted (duplicate)
1011 docstring new_label = label_->getParam("name");
1012 if (old_label == new_label)
1015 // update listings parameters...
1016 InsetCommandParams p(INCLUDE_CODE);
1018 InsetListingsParams par(to_utf8(params()["lstparams"]));
1019 par.addParam("label", "{" + to_utf8(new_label) + "}", true);
1020 p["lstparams"] = from_utf8(par.params());
1024 void InsetInclude::updateLabels(ParIterator const & it)
1026 Buffer const * const childbuffer = getChildBuffer();
1028 childbuffer->updateLabels(Buffer::UpdateChildOnly);
1031 if (!isListings(params()))
1035 label_->updateLabels(it);
1037 InsetListingsParams const par(to_utf8(params()["lstparams"]));
1038 if (par.getParamValue("caption").empty()) {
1039 listings_label_ = buffer().B_("Program Listing");
1042 Buffer const & master = *buffer().masterBuffer();
1043 Counters & counters = master.params().documentClass().counters();
1044 docstring const cnt = from_ascii("listing");
1045 listings_label_ = master.B_("Program Listing");
1046 if (counters.hasCounter(cnt)) {
1048 listings_label_ += " " + convert<docstring>(counters.value(cnt));