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;
37 /// for including tex/lyx files
38 class InsetInclude : public InsetCommand {
41 InsetInclude(InsetCommandParams const &);
43 /// Override these InsetButton methods if Previewing
44 void metrics(MetricsInfo & mi, Dimension & dim) const;
46 void draw(PainterInfo & pi, int x, int y) const;
48 virtual DisplayType display() const;
50 InsetCode lyxCode() const { return INCLUDE_CODE; }
52 * \param buffer the Buffer containing this inset.
53 * \param list the list of labels in the child buffer.
55 void getLabelList(Buffer const & buffer,
56 std::vector<docstring> & list) const;
58 * \param buffer the Buffer containing this inset.
59 * \param keys the list of bibkeys in the child buffer.
60 * \param it not used here
62 virtual void fillWithBibKeys(Buffer const & buffer,
63 BiblioInfo & keys, InsetIterator const & it) const;
65 /** Update the cache with all bibfiles in use of the child buffer
66 * (including bibfiles of grandchild documents).
67 * Does nothing if the child document is not loaded to prevent
68 * automatic loading of all child documents upon loading the master.
69 * \param buffer the Buffer containing this inset.
71 void updateBibfilesCache(Buffer const & buffer);
72 /** Return the cache with all bibfiles in use of the child buffer
73 * (including bibfiles of grandchild documents).
74 * Return an empty vector if the child doc is not loaded.
75 * \param buffer the Buffer containing this inset.
77 support::FileNameList const &
78 getBibfilesCache(Buffer const & buffer) const;
80 EDITABLE editable() const { return IS_EDITABLE; }
82 int latex(Buffer const &, odocstream &,
83 OutputParams const &) const;
85 int plaintext(Buffer const &, odocstream &,
86 OutputParams const &) const;
88 int docbook(Buffer const &, odocstream &,
89 OutputParams const &) const;
91 void validate(LaTeXFeatures &) const;
93 void addPreview(graphics::PreviewLoader &) const;
95 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
97 void updateLabels(Buffer const & buffer, ParIterator const &);
98 /// child document can be embedded
99 void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
101 static CommandInfo const * findInfo(std::string const &);
103 static std::string defaultCommand() { return "include"; };
105 static bool isCompatibleCommand(std::string const & s);
107 InsetInclude(InsetInclude const &);
109 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
111 virtual Inset * clone() const;
113 /** Slot receiving a signal that the external file has changed
114 * and the preview should be regenerated.
116 void fileChanged() const;
118 /// set the parameters
119 void set(InsetCommandParams const & params, Buffer const &);
120 /// get the text displayed on the button
121 docstring const getScreenLabel(Buffer const &) const;
122 /// holds the entity name that defines the file location (SGML)
123 docstring const include_label;
125 /// The pointer never changes although *preview_'s contents may.
126 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
129 mutable bool set_label_;
130 mutable RenderButton button_;
131 mutable docstring listings_label_;
134 /// return the child buffer if the file is a LyX doc and is loaded
135 Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params);
137 /// return loaded Buffer or zero if the file loading did not proceed.
138 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
141 void resetParentBuffer(Buffer const * parent, InsetCommandParams const & params,
146 #endif // INSETINCLUDE_H