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 "InsetCommand.h"
18 #include "RenderButton.h"
20 #include <boost/scoped_ptr.hpp>
27 class InsetCommandParams;
30 class RenderMonitoredPreview;
36 /// for including tex/lyx files
37 class InsetInclude : public InsetCommand {
38 // Disable assignment operator, since it is not used, and cannot be
39 // implemented consistently with the copy constructor, because
40 // include_label is const.
41 InsetInclude & operator=(InsetInclude const &);
44 InsetInclude(Buffer * buf, InsetCommandParams const &);
49 void setChildBuffer(Buffer * buffer);
50 /// \return the child buffer if the file is a LyX doc and could be loaded
51 Buffer * getChildBuffer() const;
53 /** Update the cache with all bibfiles in use of the child buffer
54 * (including bibfiles of grandchild documents).
55 * Does nothing if the child document is not loaded to prevent
56 * automatic loading of all child documents upon loading the master.
57 * \param buffer the Buffer containing this inset.
59 void updateBibfilesCache();
61 /** Return the cache with all bibfiles in use of the child buffer
62 * (including bibfiles of grandchild documents).
63 * Return an empty vector if the child doc is not loaded.
64 * \param buffer the Buffer containing this inset.
66 support::FileNameList const &
67 getBibfilesCache() const;
72 void write(std::ostream &) const;
74 /// \name Public functions inherited from Inset class
77 void setBuffer(Buffer & buffer);
79 bool isLabeled() const { return true; }
80 /// Override these InsetButton methods if Previewing
81 void metrics(MetricsInfo & mi, Dimension & dim) const;
83 void draw(PainterInfo & pi, int x, int y) const;
85 DisplayType display() const;
87 InsetCode lyxCode() const { return INCLUDE_CODE; }
89 docstring layoutName() const;
91 * \param keys the list of bibkeys in the child buffer.
92 * \param it not used here
94 void collectBibKeys(InsetIterator const &) const;
96 bool hasSettings() const { return true; }
98 void latex(otexstream &, OutputParams const &) const;
100 int plaintext(odocstringstream & ods, OutputParams const & op,
101 size_t max_length = INT_MAX) const;
103 int docbook(odocstream &, OutputParams const &) const;
105 docstring xhtml(XHTMLStream &, OutputParams const &) const;
107 void validate(LaTeXFeatures &) const;
109 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
111 void addToToc(DocIterator const & di, bool output_active,
112 UpdateType utype) const;
114 void updateBuffer(ParIterator const &, UpdateType);
116 std::string contextMenuName() const;
119 /// \name Static public methods obligated for InsetCommand derived classes
122 static ParamInfo const & findInfo(std::string const &);
124 static std::string defaultCommand() { return "include"; }
126 static bool isCompatibleCommand(std::string const & s);
131 InsetInclude(InsetInclude const &);
134 /** Slot receiving a signal that the external file has changed
135 * and the preview should be regenerated.
137 void fileChanged() const;
138 /// \return loaded Buffer or zero if the file loading did not proceed.
139 Buffer * loadIfNeeded() const;
140 /// launch external application
141 void editIncluded(std::string const & file);
143 bool isChildIncluded() const;
145 /// \name Private functions inherited from Inset class
147 Inset * clone() const { return new InsetInclude(*this); }
149 void doDispatch(Cursor & cur, FuncRequest & cmd);
151 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
154 /// \name Private functions inherited from InsetCommand class
156 /// set the parameters
157 // FIXME:InsetCommmand::setParams is not virtual
158 void setParams(InsetCommandParams const & params);
159 /// get the text displayed on the button
160 docstring screenLabel() const;
163 /// holds the entity name that defines the file location (SGML)
164 docstring const include_label;
166 /// The pointer never changes although *preview_'s contents may.
167 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
170 mutable bool failedtoload_;
172 mutable bool set_label_;
173 mutable RenderButton button_;
174 mutable docstring listings_label_;
176 mutable Buffer * child_buffer_;
182 #endif // INSET_INCLUDE_H