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 Kimberly 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 "support/unique_ptr.h"
25 class InsetCommandParams;
28 class RenderMonitoredPreview;
34 /// for including tex/lyx files
35 class InsetInclude : public InsetCommand {
36 // Disable assignment operator, since it is not used, and cannot be
37 // implemented consistently with the copy constructor, because
38 // include_label is const.
39 InsetInclude & operator=(InsetInclude const &);
42 InsetInclude(Buffer * buf, InsetCommandParams const &);
47 void setChildBuffer(Buffer * buffer);
49 /// \return loaded Buffer or zero if the file loading did not proceed.
50 Buffer * loadIfNeeded() const;
52 /** Update the cache with all bibfiles in use of the child buffer
53 * (including bibfiles of grandchild documents).
54 * Does nothing if the child document is not loaded to prevent
55 * automatic loading of all child documents upon loading the master.
56 * \param buffer the Buffer containing this inset.
58 void updateBibfilesCache();
63 void write(std::ostream &) const override;
65 /// \name Public functions inherited from Inset class
68 void setBuffer(Buffer & buffer) override;
70 bool isLabeled() const override { return true; }
72 bool inheritFont() const override;
73 /// Override these InsetButton methods if Previewing
74 void metrics(MetricsInfo & mi, Dimension & dim) const override;
76 void draw(PainterInfo & pi, int x, int y) const override;
78 int rowFlags() const override;
80 InsetCode lyxCode() const override { return INCLUDE_CODE; }
82 docstring layoutName() const override;
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 override;
89 bool hasSettings() const override { return true; }
91 void latex(otexstream &, OutputParams const &) const override;
93 int plaintext(odocstringstream & ods, OutputParams const & op,
94 size_t max_length = INT_MAX) const override;
96 void docbook(XMLStream &, OutputParams const &) const override;
98 docstring xhtml(XMLStream &, OutputParams const &) const override;
100 void validate(LaTeXFeatures &) const override;
102 void addPreview(DocIterator const &, graphics::PreviewLoader &) const override;
104 void addToToc(DocIterator const & di, bool output_active,
105 UpdateType utype, TocBackend & backend) const override;
107 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
109 std::string contextMenuName() const override;
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);
121 bool needsCProtection(bool const maintext = false,
122 bool const fragile = false) const override;
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 /// launch external application
135 void editIncluded(std::string const & file);
137 bool isChildIncluded() const;
138 /// check whether the included file exist
139 bool includedFileExist() const;
140 /// \return True if there is a recursive include
141 /// Also issues appropriate warning, etc
142 bool checkForRecursiveInclude(Buffer const * cbuf, bool silent = false) const;
144 /// \name Private functions inherited from Inset class
146 Inset * clone() const override { return new InsetInclude(*this); }
148 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
150 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
153 /// \name Private functions inherited from InsetCommand class
155 /// set the parameters
156 // FIXME:InsetCommmand::setParams is not virtual
157 void setParams(InsetCommandParams const & params);
158 /// get the text displayed on the button
159 docstring screenLabel() const override;
162 /// holds the entity name that defines the file location (XML)
163 docstring const include_label;
165 /// The pointer never changes although *preview_'s contents may.
166 unique_ptr<RenderMonitoredPreview> const preview_;
169 mutable bool failedtoload_;
171 mutable docstring listings_label_;
173 mutable Buffer * child_buffer_;
174 mutable bool file_exist_;
175 mutable bool recursion_error_;
181 #endif // INSET_INCLUDE_H