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 "BiblioInfo.h"
20 #include "InsetCommandParams.h"
21 #include "RenderButton.h"
23 #include "support/FileNameList.h"
25 #include <boost/scoped_ptr.hpp>
33 class RenderMonitoredPreview;
35 /// for including tex/lyx files
36 class InsetInclude : public InsetCommand {
39 InsetInclude(Buffer * buf, InsetCommandParams const &);
44 void setChildBuffer(Buffer * buffer);
45 /// \return the child buffer if the file is a LyX doc and could be loaded
46 Buffer * getChildBuffer() const;
48 /** Update the cache with all bibfiles in use of the child buffer
49 * (including bibfiles of grandchild documents).
50 * Does nothing if the child document is not loaded to prevent
51 * automatic loading of all child documents upon loading the master.
52 * \param buffer the Buffer containing this inset.
54 void updateBibfilesCache();
56 /** Return the cache with all bibfiles in use of the child buffer
57 * (including bibfiles of grandchild documents).
58 * Return an empty vector if the child doc is not loaded.
59 * \param buffer the Buffer containing this inset.
61 support::FileNameList const &
62 getBibfilesCache() const;
67 /// \name Public functions inherited from Inset class
70 void setBuffer(Buffer & buffer);
72 bool isLabeled() const { return true; }
73 /// Override these InsetButton methods if Previewing
74 void metrics(MetricsInfo & mi, Dimension & dim) const;
76 void draw(PainterInfo & pi, int x, int y) const;
78 DisplayType display() const;
80 InsetCode lyxCode() const { return INCLUDE_CODE; }
82 * \param keys the list of bibkeys in the child buffer.
83 * \param it not used here
85 void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
87 bool hasSettings() const { return true; }
89 int latex(odocstream &, OutputParams const &) const;
91 int plaintext(odocstream &, OutputParams const &) const;
93 int docbook(odocstream &, OutputParams const &) const;
95 docstring xhtml(XHTMLStream &, OutputParams const &) const;
97 void validate(LaTeXFeatures &) const;
99 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
101 void addToToc(DocIterator const &);
103 void updateBuffer(ParIterator const &, UpdateType);
105 docstring contextMenu(BufferView const & bv, int x, int y) const;
108 /// \name Static public methods obligated for InsetCommand derived classes
111 static ParamInfo const & findInfo(std::string const &);
113 static std::string defaultCommand() { return "include"; }
115 static bool isCompatibleCommand(std::string const & s);
120 InsetInclude(InsetInclude const &);
123 /** Slot receiving a signal that the external file has changed
124 * and the preview should be regenerated.
126 void fileChanged() const;
127 /// \return loaded Buffer or zero if the file loading did not proceed.
128 Buffer * loadIfNeeded() const;
129 /// launch external application
130 void editIncluded(std::string const & file);
132 bool isChildIncluded() const;
134 /// \name Private functions inherited from Inset class
136 Inset * clone() const { return new InsetInclude(*this); }
138 void doDispatch(Cursor & cur, FuncRequest & cmd);
140 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
143 /// \name Private functions inherited from InsetCommand class
145 /// set the parameters
146 // FIXME:InsetCommmand::setParams is not virtual
147 void setParams(InsetCommandParams const & params);
148 /// get the text displayed on the button
149 docstring screenLabel() const;
152 /// holds the entity name that defines the file location (SGML)
153 docstring const include_label;
155 /// The pointer never changes although *preview_'s contents may.
156 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
159 mutable bool failedtoload_;
161 mutable bool set_label_;
162 mutable RenderButton button_;
163 mutable docstring listings_label_;
165 mutable Buffer * child_buffer_;
171 #endif // INSET_INCLUDE_H