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);
52 /// \return loaded Buffer or zero if the file loading did not proceed.
53 Buffer * loadIfNeeded() const;
55 /** Update the cache with all bibfiles in use of the child buffer
56 * (including bibfiles of grandchild documents).
57 * Does nothing if the child document is not loaded to prevent
58 * automatic loading of all child documents upon loading the master.
59 * \param buffer the Buffer containing this inset.
61 void updateBibfilesCache();
66 void write(std::ostream &) const;
68 /// \name Public functions inherited from Inset class
71 void setBuffer(Buffer & buffer);
73 bool isLabeled() const { return true; }
74 /// Override these InsetButton methods if Previewing
75 void metrics(MetricsInfo & mi, Dimension & dim) const;
77 void draw(PainterInfo & pi, int x, int y) const;
79 RowFlags rowFlags() const;
81 InsetCode lyxCode() const { return INCLUDE_CODE; }
83 docstring layoutName() const;
85 * \param keys the list of bibkeys in the child buffer.
86 * \param it not used here
88 void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
90 bool hasSettings() const { return true; }
92 void latex(otexstream &, OutputParams const &) const;
94 int plaintext(odocstringstream & ods, OutputParams const & op,
95 size_t max_length = INT_MAX) const;
97 void docbook(XMLStream &, OutputParams const &) const;
99 docstring xhtml(XMLStream &, OutputParams const &) const;
101 void validate(LaTeXFeatures &) const;
103 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
105 void addToToc(DocIterator const & di, bool output_active,
106 UpdateType utype, TocBackend & backend) const;
108 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
110 std::string contextMenuName() const;
113 /// \name Static public methods obligated for InsetCommand derived classes
116 static ParamInfo const & findInfo(std::string const &);
118 static std::string defaultCommand() { return "include"; }
120 static bool isCompatibleCommand(std::string const & s);
122 bool needsCProtection(bool const maintext = false,
123 bool const fragile = false) const;
128 InsetInclude(InsetInclude const &);
131 /** Slot receiving a signal that the external file has changed
132 * and the preview should be regenerated.
134 void fileChanged() const;
135 /// launch external application
136 void editIncluded(std::string const & file);
138 bool isChildIncluded() const;
139 /// check whether the included file exist
140 bool includedFileExist() const;
141 /// \return True if there is a recursive include
142 /// Also issues appropriate warning, etc
143 bool checkForRecursiveInclude(Buffer const * cbuf, bool silent = false) 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 (XML)
164 docstring const include_label;
166 /// The pointer never changes although *preview_'s contents may.
167 unique_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_;
177 mutable bool file_exist_;
178 mutable bool recursion_error_;
184 #endif // INSET_INCLUDE_H