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 "support/FileName.h"
26 #include <boost/scoped_ptr.hpp>
33 class RenderMonitoredPreview;
36 /// for including tex/lyx files
37 class InsetInclude : public InsetCommand {
40 InsetInclude(InsetCommandParams const &);
42 /// Override these InsetButton methods if Previewing
43 void metrics(MetricsInfo & mi, Dimension & dim) const;
45 void draw(PainterInfo & pi, int x, int y) const;
47 virtual DisplayType display() const;
49 InsetCode lyxCode() const { return INCLUDE_CODE; }
51 * \param buffer the Buffer containing this inset.
52 * \param list the list of labels in the child buffer.
54 void getLabelList(Buffer const & buffer,
55 std::vector<docstring> & list) const;
57 * \param buffer the Buffer containing this inset.
58 * \param keys the list of bibkeys in the child buffer.
59 * \param it not used here
61 virtual void fillWithBibKeys(Buffer const & buffer,
62 BiblioInfo & keys, InsetIterator const & it) const;
64 /** Update the cache with all bibfiles in use of the child buffer
65 * (including bibfiles of grandchild documents).
66 * Does nothing if the child document is not loaded to prevent
67 * automatic loading of all child documents upon loading the master.
68 * \param buffer the Buffer containing this inset.
70 void updateBibfilesCache(Buffer const & buffer);
71 /** Return the cache with all bibfiles in use of the child buffer
72 * (including bibfiles of grandchild documents).
73 * Return an empty vector if the child doc is not loaded.
74 * \param buffer the Buffer containing this inset.
76 std::vector<support::FileName> const &
77 getBibfilesCache(Buffer const & buffer) const;
79 EDITABLE editable() const { return IS_EDITABLE; }
81 int latex(Buffer const &, odocstream &,
82 OutputParams const &) const;
84 int plaintext(Buffer const &, odocstream &,
85 OutputParams const &) const;
87 int docbook(Buffer const &, odocstream &,
88 OutputParams const &) const;
90 void validate(LaTeXFeatures &) const;
92 void addPreview(graphics::PreviewLoader &) const;
94 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
96 void updateLabels(Buffer const & buffer, ParIterator const &);
97 /// child document can be embedded
98 void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
100 static CommandInfo const * findInfo(std::string const &);
102 static std::string defaultCommand() { return "include"; };
104 static bool isCompatibleCommand(std::string const & s);
106 InsetInclude(InsetInclude const &);
108 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
110 virtual Inset * clone() const;
112 /** Slot receiving a signal that the external file has changed
113 * and the preview should be regenerated.
115 void fileChanged() const;
117 /// set the parameters
118 void set(InsetCommandParams const & params, Buffer const &);
119 /// get the text displayed on the button
120 docstring const getScreenLabel(Buffer const &) const;
121 /// holds the entity name that defines the file location (SGML)
122 docstring const include_label;
124 /// The pointer never changes although *preview_'s contents may.
125 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
128 mutable bool set_label_;
129 mutable RenderButton button_;
130 mutable docstring listings_label_;
134 /// return loaded Buffer or zero if the file loading did not proceed.
135 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
139 #endif // INSETINCLUDE_H