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
9 * Full author contact details are available in file CREDITS.
12 #ifndef INSET_INCLUDE_H
13 #define INSET_INCLUDE_H
16 #include "InsetCommandParams.h"
17 #include "RenderButton.h"
18 #include "MailInset.h"
21 #include "support/FileName.h"
23 #include <boost/scoped_ptr.hpp>
30 class RenderMonitoredPreview;
33 /// for including tex/lyx files
34 class InsetInclude : public Inset {
37 InsetInclude(InsetCommandParams const &);
40 /// Override these InsetButton methods if Previewing
41 bool metrics(MetricsInfo & mi, Dimension & dim) const;
43 void draw(PainterInfo & pi, int x, int y) const;
45 virtual DisplayType display() const;
47 /// get the parameters
48 InsetCommandParams const & params() const;
51 Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
53 * \param buffer the Buffer containing this inset.
54 * \param list the list of labels in the child buffer.
56 void getLabelList(Buffer const & buffer,
57 std::vector<docstring> & list) const;
59 * \param buffer the Buffer containing this inset.
60 * \param keys the list of bibkeys in the child buffer.
62 virtual void fillWithBibKeys(Buffer const &,
63 std::vector<std::pair<std::string, docstring> > &,
64 InsetIterator const & /*di*/) 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 std::vector<support::FileName> const &
78 getBibfilesCache(Buffer const & buffer) const;
80 EDITABLE editable() const { return IS_EDITABLE; }
82 void write(Buffer const &, std::ostream &) const;
84 void read(Buffer const &, Lexer &);
86 int latex(Buffer const &, odocstream &,
87 OutputParams const &) const;
89 int plaintext(Buffer const &, odocstream &,
90 OutputParams const &) const;
92 int docbook(Buffer const &, odocstream &,
93 OutputParams const &) const;
95 void validate(LaTeXFeatures &) const;
97 void addPreview(graphics::PreviewLoader &) const;
99 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
101 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
103 void updateLabels(Buffer const & buffer, ParIterator const &) const;
105 InsetInclude(InsetInclude const &);
107 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
109 virtual std::auto_ptr<Inset> doClone() const;
111 /** Slot receiving a signal that the external file has changed
112 * and the preview should be regenerated.
114 void fileChanged() const;
116 friend class InsetIncludeMailer;
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;
123 void write(std::ostream &) const;
128 InsetCommandParams params_;
129 /// holds the entity name that defines the file location (SGML)
130 docstring const include_label;
132 /// The pointer never changes although *preview_'s contents may.
133 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
136 mutable bool set_label_;
137 mutable RenderButton button_;
138 mutable docstring listings_label_;
142 class InsetIncludeMailer : public MailInset {
145 InsetIncludeMailer(InsetInclude & inset);
147 virtual Inset & inset() const { return inset_; }
149 virtual std::string const & name() const { return name_; }
151 virtual std::string const inset2string(Buffer const &) const;
153 static void string2params(std::string const &, InsetCommandParams &);
155 static std::string const params2string(InsetCommandParams const &);
158 static std::string const name_;
160 InsetInclude & inset_;
163 /// return loaded Buffer or zero if the file loading did not proceed.
164 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
168 #endif // INSETINCLUDE_H