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
15 #include "BiblioInfo.h"
17 #include "InsetCommandParams.h"
18 #include "RenderButton.h"
19 #include "MailInset.h"
21 #include "EmbeddedFiles.h"
23 #include "support/FileName.h"
25 #include <boost/scoped_ptr.hpp>
32 class RenderMonitoredPreview;
35 /// for including tex/lyx files
36 class InsetInclude : public Inset {
39 InsetInclude(InsetCommandParams const &);
42 /// Override these InsetButton methods if Previewing
43 bool metrics(MetricsInfo & mi, Dimension & dim) const;
45 void draw(PainterInfo & pi, int x, int y) const;
47 virtual DisplayType display() const;
49 /// get the parameters
50 InsetCommandParams const & params() const;
53 Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
55 * \param buffer the Buffer containing this inset.
56 * \param list the list of labels in the child buffer.
58 void getLabelList(Buffer const & buffer,
59 std::vector<docstring> & list) const;
61 * \param buffer the Buffer containing this inset.
62 * \param keys the list of bibkeys in the child buffer.
63 * \param it not used here
65 virtual void fillWithBibKeys(Buffer const & buffer,
66 BiblioInfo & keys, InsetIterator const & it) const;
68 /** Update the cache with all bibfiles in use of the child buffer
69 * (including bibfiles of grandchild documents).
70 * Does nothing if the child document is not loaded to prevent
71 * automatic loading of all child documents upon loading the master.
72 * \param buffer the Buffer containing this inset.
74 void updateBibfilesCache(Buffer const & buffer);
75 /** Return the cache with all bibfiles in use of the child buffer
76 * (including bibfiles of grandchild documents).
77 * Return an empty vector if the child doc is not loaded.
78 * \param buffer the Buffer containing this inset.
80 std::vector<support::FileName> const &
81 getBibfilesCache(Buffer const & buffer) const;
83 EDITABLE editable() const { return IS_EDITABLE; }
85 void write(Buffer const &, std::ostream &) const;
87 void read(Buffer const &, Lexer &);
89 int latex(Buffer const &, odocstream &,
90 OutputParams const &) const;
92 int plaintext(Buffer const &, odocstream &,
93 OutputParams const &) const;
95 int docbook(Buffer const &, odocstream &,
96 OutputParams const &) const;
98 void validate(LaTeXFeatures &) const;
100 void addPreview(graphics::PreviewLoader &) const;
102 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
104 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
106 void updateLabels(Buffer const & buffer, ParIterator const &);
107 /// child document can be embedded
108 void registerEmbeddedFiles(Buffer const &, EmbeddedFiles &) const;
110 InsetInclude(InsetInclude const &);
112 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
114 virtual Inset * clone() const;
116 /** Slot receiving a signal that the external file has changed
117 * and the preview should be regenerated.
119 void fileChanged() const;
121 friend class InsetIncludeMailer;
123 /// set the parameters
124 void set(InsetCommandParams const & params, Buffer const &);
125 /// get the text displayed on the button
126 docstring const getScreenLabel(Buffer const &) const;
128 void write(std::ostream &) const;
133 InsetCommandParams params_;
134 /// holds the entity name that defines the file location (SGML)
135 docstring const include_label;
137 /// The pointer never changes although *preview_'s contents may.
138 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
141 mutable bool set_label_;
142 mutable RenderButton button_;
143 mutable docstring listings_label_;
147 class InsetIncludeMailer : public MailInset {
150 InsetIncludeMailer(InsetInclude & inset);
152 virtual Inset & inset() const { return inset_; }
154 virtual std::string const & name() const { return name_; }
156 virtual std::string const inset2string(Buffer const &) const;
158 static void string2params(std::string const &, InsetCommandParams &);
160 static std::string const params2string(InsetCommandParams const &);
163 static std::string const name_;
165 InsetInclude & inset_;
168 /// return loaded Buffer or zero if the file loading did not proceed.
169 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
173 #endif // INSETINCLUDE_H