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 {
40 InsetInclude(Buffer * buf, InsetCommandParams const &);
45 void setChildBuffer(Buffer * buffer);
46 /// \return the child buffer if the file is a LyX doc and could be loaded
47 Buffer * getChildBuffer() const;
49 /** Update the cache with all bibfiles in use of the child buffer
50 * (including bibfiles of grandchild documents).
51 * Does nothing if the child document is not loaded to prevent
52 * automatic loading of all child documents upon loading the master.
53 * \param buffer the Buffer containing this inset.
55 void updateBibfilesCache();
57 /** Return the cache with all bibfiles in use of the child buffer
58 * (including bibfiles of grandchild documents).
59 * Return an empty vector if the child doc is not loaded.
60 * \param buffer the Buffer containing this inset.
62 support::FileNameList const &
63 getBibfilesCache() const;
68 void write(std::ostream &) const;
70 /// \name Public functions inherited from Inset class
73 void setBuffer(Buffer & buffer);
75 bool isLabeled() const { return true; }
76 /// Override these InsetButton methods if Previewing
77 void metrics(MetricsInfo & mi, Dimension & dim) const;
79 void draw(PainterInfo & pi, int x, int y) const;
81 DisplayType display() const;
83 InsetCode lyxCode() const { return INCLUDE_CODE; }
85 docstring layoutName() const;
87 * \param keys the list of bibkeys in the child buffer.
88 * \param it not used here
90 void collectBibKeys(InsetIterator const &) const;
92 bool hasSettings() const { return true; }
94 void latex(otexstream &, OutputParams const &) const;
96 int plaintext(odocstringstream & ods, OutputParams const & op,
97 size_t max_length = INT_MAX) const;
99 int docbook(odocstream &, OutputParams const &) const;
101 docstring xhtml(XHTMLStream &, OutputParams const &) const;
103 void validate(LaTeXFeatures &) const;
105 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
107 void addToToc(DocIterator const & di, bool output_active,
108 UpdateType utype) const;
110 void updateBuffer(ParIterator const &, UpdateType);
112 std::string contextMenuName() const;
115 /// \name Static public methods obligated for InsetCommand derived classes
118 static ParamInfo const & findInfo(std::string const &);
120 static std::string defaultCommand() { return "include"; }
122 static bool isCompatibleCommand(std::string const & s);
127 InsetInclude(InsetInclude const &);
130 /** Slot receiving a signal that the external file has changed
131 * and the preview should be regenerated.
133 void fileChanged() const;
134 /// \return loaded Buffer or zero if the file loading did not proceed.
135 Buffer * loadIfNeeded() const;
136 /// launch external application
137 void editIncluded(std::string const & file);
139 bool isChildIncluded() const;
141 /// \name Private functions inherited from Inset class
143 Inset * clone() const { return new InsetInclude(*this); }
145 void doDispatch(Cursor & cur, FuncRequest & cmd);
147 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
150 /// \name Private functions inherited from InsetCommand class
152 /// set the parameters
153 // FIXME:InsetCommmand::setParams is not virtual
154 void setParams(InsetCommandParams const & params);
155 /// get the text displayed on the button
156 docstring screenLabel() const;
159 /// holds the entity name that defines the file location (SGML)
160 docstring const include_label;
162 /// The pointer never changes although *preview_'s contents may.
163 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
166 mutable bool failedtoload_;
168 mutable bool set_label_;
169 mutable RenderButton button_;
170 mutable docstring listings_label_;
172 mutable Buffer * child_buffer_;
178 #endif // INSET_INCLUDE_H