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 void fillWithBibKeys(Buffer const & buffer,
63 std::vector<std::pair<std::string, docstring> > & keys) 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 void write(Buffer const &, std::ostream &) const;
83 void read(Buffer const &, Lexer &);
85 int latex(Buffer const &, odocstream &,
86 OutputParams const &) const;
88 int plaintext(Buffer const &, odocstream &,
89 OutputParams const &) const;
91 int docbook(Buffer const &, odocstream &,
92 OutputParams const &) const;
94 void validate(LaTeXFeatures &) const;
96 void addPreview(graphics::PreviewLoader &) const;
98 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
100 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
102 void updateLabels(Buffer const & buffer, ParIterator const &) const;
104 InsetInclude(InsetInclude const &);
106 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
108 virtual std::auto_ptr<Inset> doClone() const;
110 /** Slot receiving a signal that the external file has changed
111 * and the preview should be regenerated.
113 void fileChanged() const;
115 friend class InsetIncludeMailer;
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;
122 void write(std::ostream &) const;
127 InsetCommandParams params_;
128 /// holds the entity name that defines the file location (SGML)
129 docstring const include_label;
131 /// The pointer never changes although *preview_'s contents may.
132 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
135 mutable bool set_label_;
136 mutable RenderButton button_;
137 mutable docstring listings_label_;
141 class InsetIncludeMailer : public MailInset {
144 InsetIncludeMailer(InsetInclude & inset);
146 virtual Inset & inset() const { return inset_; }
148 virtual std::string const & name() const { return name_; }
150 virtual std::string const inset2string(Buffer const &) const;
152 static void string2params(std::string const &, InsetCommandParams &);
154 static std::string const params2string(InsetCommandParams const &);
157 static std::string const name_;
159 InsetInclude & inset_;
165 #endif // INSETINCLUDE_H