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"
22 #include "support/FileName.h"
24 #include <boost/scoped_ptr.hpp>
31 class RenderMonitoredPreview;
34 /// for including tex/lyx files
35 class InsetInclude : public Inset {
38 InsetInclude(InsetCommandParams const &);
41 /// Override these InsetButton methods if Previewing
42 bool metrics(MetricsInfo & mi, Dimension & dim) const;
44 void draw(PainterInfo & pi, int x, int y) const;
46 virtual DisplayType display() const;
48 /// get the parameters
49 InsetCommandParams const & params() const;
52 Inset::Code lyxCode() const { return Inset::INCLUDE_CODE; }
54 * \param buffer the Buffer containing this inset.
55 * \param list the list of labels in the child buffer.
57 void getLabelList(Buffer const & buffer,
58 std::vector<docstring> & list) const;
60 * \param buffer the Buffer containing this inset.
61 * \param keys the list of bibkeys in the child buffer.
62 * \param it not used here
64 virtual void fillWithBibKeys(Buffer const & buffer,
65 BiblioInfo & keys, InsetIterator const & it) const;
67 /** Update the cache with all bibfiles in use of the child buffer
68 * (including bibfiles of grandchild documents).
69 * Does nothing if the child document is not loaded to prevent
70 * automatic loading of all child documents upon loading the master.
71 * \param buffer the Buffer containing this inset.
73 void updateBibfilesCache(Buffer const & buffer);
74 /** Return the cache with all bibfiles in use of the child buffer
75 * (including bibfiles of grandchild documents).
76 * Return an empty vector if the child doc is not loaded.
77 * \param buffer the Buffer containing this inset.
79 std::vector<support::FileName> const &
80 getBibfilesCache(Buffer const & buffer) const;
82 EDITABLE editable() const { return IS_EDITABLE; }
84 void write(Buffer const &, std::ostream &) const;
86 void read(Buffer const &, Lexer &);
88 int latex(Buffer const &, odocstream &,
89 OutputParams const &) const;
91 int plaintext(Buffer const &, odocstream &,
92 OutputParams const &) const;
94 int docbook(Buffer const &, odocstream &,
95 OutputParams const &) const;
97 void validate(LaTeXFeatures &) const;
99 void addPreview(graphics::PreviewLoader &) const;
101 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
103 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
105 void updateLabels(Buffer const & buffer, ParIterator const &);
107 InsetInclude(InsetInclude const &);
109 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
111 virtual std::auto_ptr<Inset> doClone() const;
113 /** Slot receiving a signal that the external file has changed
114 * and the preview should be regenerated.
116 void fileChanged() const;
118 friend class InsetIncludeMailer;
120 /// set the parameters
121 void set(InsetCommandParams const & params, Buffer const &);
122 /// get the text displayed on the button
123 docstring const getScreenLabel(Buffer const &) const;
125 void write(std::ostream &) const;
130 InsetCommandParams params_;
131 /// holds the entity name that defines the file location (SGML)
132 docstring const include_label;
134 /// The pointer never changes although *preview_'s contents may.
135 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
138 mutable bool set_label_;
139 mutable RenderButton button_;
140 mutable docstring listings_label_;
144 class InsetIncludeMailer : public MailInset {
147 InsetIncludeMailer(InsetInclude & inset);
149 virtual Inset & inset() const { return inset_; }
151 virtual std::string const & name() const { return name_; }
153 virtual std::string const inset2string(Buffer const &) const;
155 static void string2params(std::string const &, InsetCommandParams &);
157 static std::string const params2string(InsetCommandParams const &);
160 static std::string const name_;
162 InsetInclude & inset_;
165 /// return loaded Buffer or zero if the file loading did not proceed.
166 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
170 #endif // INSETINCLUDE_H