4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Richard Heck (conversion to InsetCommand)
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSET_INCLUDE_H
14 #define INSET_INCLUDE_H
16 #include "BiblioInfo.h"
17 #include "InsetCommand.h"
18 #include "InsetCommandParams.h"
19 #include "RenderButton.h"
20 #include "MailInset.h"
22 #include "EmbeddedFiles.h"
24 #include <boost/scoped_ptr.hpp>
31 class RenderMonitoredPreview;
33 /// for including tex/lyx files
34 class InsetInclude : public InsetCommand {
37 InsetInclude(InsetCommandParams const &);
40 /// Override these InsetButton methods if Previewing
41 void metrics(MetricsInfo & mi, Dimension & dim) const;
43 void draw(PainterInfo & pi, int x, int y) const;
45 DisplayType display() const;
47 InsetCode lyxCode() const { return INCLUDE_CODE; }
49 * \param buffer the Buffer containing this inset.
50 * \param list the list of labels in the child buffer.
52 void getLabelList(std::vector<docstring> & list) const;
54 * \param buffer the Buffer containing this inset.
55 * \param keys the list of bibkeys in the child buffer.
56 * \param it not used here
58 void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
60 /** Update the cache with all bibfiles in use of the child buffer
61 * (including bibfiles of grandchild documents).
62 * Does nothing if the child document is not loaded to prevent
63 * automatic loading of all child documents upon loading the master.
64 * \param buffer the Buffer containing this inset.
66 void updateBibfilesCache();
67 /** Return the cache with all bibfiles in use of the child buffer
68 * (including bibfiles of grandchild documents).
69 * Return an empty vector if the child doc is not loaded.
70 * \param buffer the Buffer containing this inset.
72 EmbeddedFileList const &
73 getBibfilesCache(Buffer const & buffer) const;
75 EDITABLE editable() const { return IS_EDITABLE; }
77 int latex(odocstream &, OutputParams const &) const;
79 int plaintext(odocstream &, OutputParams const &) const;
81 int docbook(odocstream &, OutputParams const &) const;
83 void validate(LaTeXFeatures &) const;
85 void addPreview(graphics::PreviewLoader &) const;
87 void addToToc(ParConstIterator const &) const;
89 void updateLabels(ParIterator const &);
90 /// child document can be embedded
91 void registerEmbeddedFiles(EmbeddedFileList &) const;
93 void updateEmbeddedFile(EmbeddedFile const & file);
95 static ParamInfo const & findInfo(std::string const &);
97 static std::string defaultCommand() { return "include"; };
99 static bool isCompatibleCommand(std::string const & s);
101 InsetInclude(InsetInclude const &);
103 void doDispatch(Cursor & cur, FuncRequest & cmd);
105 Inset * clone() const { return new InsetInclude(*this); }
107 /** Slot receiving a signal that the external file has changed
108 * and the preview should be regenerated.
110 void fileChanged() const;
112 /// set the parameters
113 void setParams(InsetCommandParams const & params);
114 /// get the text displayed on the button
115 docstring screenLabel() const;
116 /// holds the entity name that defines the file location (SGML)
117 docstring const include_label;
119 /// The pointer never changes although *preview_'s contents may.
120 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
123 mutable bool set_label_;
124 mutable RenderButton button_;
125 mutable docstring listings_label_;
128 /// return loaded Buffer or zero if the file loading did not proceed.
129 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
133 #endif // INSETINCLUDE_H