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 "support/unique_ptr.h"
28 class InsetCommandParams;
31 class RenderMonitoredPreview;
37 /// for including tex/lyx files
38 class InsetInclude : public InsetCommand {
39 // Disable assignment operator, since it is not used, and cannot be
40 // implemented consistently with the copy constructor, because
41 // include_label is const.
42 InsetInclude & operator=(InsetInclude const &);
45 InsetInclude(Buffer * buf, InsetCommandParams const &);
50 void setChildBuffer(Buffer * buffer);
51 /// \return the child buffer if the file is a LyX doc and could be loaded
52 Buffer * getChildBuffer() const;
54 /** Update the cache with all bibfiles in use of the child buffer
55 * (including bibfiles of grandchild documents).
56 * Does nothing if the child document is not loaded to prevent
57 * automatic loading of all child documents upon loading the master.
58 * \param buffer the Buffer containing this inset.
60 void updateBibfilesCache();
65 void write(std::ostream &) 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 docstring layoutName() const;
84 * \param keys the list of bibkeys in the child buffer.
85 * \param it not used here
87 void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
89 bool hasSettings() const { return true; }
91 void latex(otexstream &, OutputParams const &) const;
93 int plaintext(odocstringstream & ods, OutputParams const & op,
94 size_t max_length = INT_MAX) const;
96 int docbook(odocstream &, OutputParams const &) const;
98 docstring xhtml(XHTMLStream &, OutputParams const &) const;
100 void validate(LaTeXFeatures &) const;
102 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
104 void addToToc(DocIterator const & di, bool output_active,
105 UpdateType utype, TocBackend & backend) const;
107 void updateBuffer(ParIterator const &, UpdateType);
109 std::string contextMenuName() const;
112 /// \name Static public methods obligated for InsetCommand derived classes
115 static ParamInfo const & findInfo(std::string const &);
117 static std::string defaultCommand() { return "include"; }
119 static bool isCompatibleCommand(std::string const & s);
124 InsetInclude(InsetInclude const &);
127 /** Slot receiving a signal that the external file has changed
128 * and the preview should be regenerated.
130 void fileChanged() const;
131 /// \return loaded Buffer or zero if the file loading did not proceed.
132 Buffer * loadIfNeeded() const;
133 /// launch external application
134 void editIncluded(std::string const & file);
136 bool isChildIncluded() const;
138 /// \name Private functions inherited from Inset class
140 Inset * clone() const { return new InsetInclude(*this); }
142 void doDispatch(Cursor & cur, FuncRequest & cmd);
144 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
147 /// \name Private functions inherited from InsetCommand class
149 /// set the parameters
150 // FIXME:InsetCommmand::setParams is not virtual
151 void setParams(InsetCommandParams const & params);
152 /// get the text displayed on the button
153 docstring screenLabel() const;
156 /// holds the entity name that defines the file location (SGML)
157 docstring const include_label;
159 /// The pointer never changes although *preview_'s contents may.
160 unique_ptr<RenderMonitoredPreview> const preview_;
163 mutable bool failedtoload_;
165 mutable bool set_label_;
166 mutable RenderButton button_;
167 mutable docstring listings_label_;
169 mutable Buffer * child_buffer_;
175 #endif // INSET_INCLUDE_H