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 &);
39 /// Override these InsetButton methods if Previewing
40 void metrics(MetricsInfo & mi, Dimension & dim) const;
42 void draw(PainterInfo & pi, int x, int y) const;
44 virtual DisplayType display() const;
46 InsetCode lyxCode() const { return INCLUDE_CODE; }
48 * \param buffer the Buffer containing this inset.
49 * \param list the list of labels in the child buffer.
51 void getLabelList(std::vector<docstring> & list) const;
53 * \param buffer the Buffer containing this inset.
54 * \param keys the list of bibkeys in the child buffer.
55 * \param it not used here
57 void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
59 /** Update the cache with all bibfiles in use of the child buffer
60 * (including bibfiles of grandchild documents).
61 * Does nothing if the child document is not loaded to prevent
62 * automatic loading of all child documents upon loading the master.
63 * \param buffer the Buffer containing this inset.
65 void updateBibfilesCache();
66 /** Return the cache with all bibfiles in use of the child buffer
67 * (including bibfiles of grandchild documents).
68 * Return an empty vector if the child doc is not loaded.
69 * \param buffer the Buffer containing this inset.
71 EmbeddedFileList const &
72 getBibfilesCache(Buffer const & buffer) const;
74 EDITABLE editable() const { return IS_EDITABLE; }
76 int latex(odocstream &, OutputParams const &) const;
78 int plaintext(odocstream &, OutputParams const &) const;
80 int docbook(odocstream &, OutputParams const &) const;
82 void validate(LaTeXFeatures &) const;
84 void addPreview(graphics::PreviewLoader &) const;
86 void addToToc(ParConstIterator const &) const;
88 void updateLabels(ParIterator const &);
89 /// child document can be embedded
90 void registerEmbeddedFiles(EmbeddedFileList &) const;
92 void updateEmbeddedFile(EmbeddedFile const & file);
94 static ParamInfo const & findInfo(std::string const &);
96 static std::string defaultCommand() { return "include"; };
98 static bool isCompatibleCommand(std::string const & s);
100 InsetInclude(InsetInclude const &);
102 void doDispatch(Cursor & cur, FuncRequest & cmd);
104 Inset * clone() const;
106 /** Slot receiving a signal that the external file has changed
107 * and the preview should be regenerated.
109 void fileChanged() const;
111 /// set the parameters
112 void setParams(InsetCommandParams const & params);
113 /// get the text displayed on the button
114 docstring screenLabel() const;
115 /// holds the entity name that defines the file location (SGML)
116 docstring const include_label;
118 /// The pointer never changes although *preview_'s contents may.
119 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
122 mutable bool set_label_;
123 mutable RenderButton button_;
124 mutable docstring listings_label_;
127 /// return the child buffer if the file is a LyX doc and is loaded
128 Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params);
130 /// return loaded Buffer or zero if the file loading did not proceed.
131 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
134 void resetParentBuffer(Buffer const * parent, InsetCommandParams const & params,
139 #endif // INSETINCLUDE_H