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"
22 #include "EmbeddedFiles.h"
24 #include <boost/scoped_ptr.hpp>
32 class RenderMonitoredPreview;
38 /// for including tex/lyx files
39 class InsetInclude : public InsetCommand {
42 InsetInclude(InsetCommandParams const &);
45 void setBuffer(Buffer & buffer);
46 bool isLabeled() const { return true; }
48 /// Override these InsetButton methods if Previewing
49 void metrics(MetricsInfo & mi, Dimension & dim) const;
51 void draw(PainterInfo & pi, int x, int y) const;
53 DisplayType display() const;
55 InsetCode lyxCode() const { return INCLUDE_CODE; }
57 * \param buffer the Buffer containing this inset.
58 * \param keys the list of bibkeys in the child buffer.
59 * \param it not used here
61 void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
63 /** Update the cache with all bibfiles in use of the child buffer
64 * (including bibfiles of grandchild documents).
65 * Does nothing if the child document is not loaded to prevent
66 * automatic loading of all child documents upon loading the master.
67 * \param buffer the Buffer containing this inset.
69 void updateBibfilesCache();
70 /** Return the cache with all bibfiles in use of the child buffer
71 * (including bibfiles of grandchild documents).
72 * Return an empty vector if the child doc is not loaded.
73 * \param buffer the Buffer containing this inset.
75 EmbeddedFileList const &
76 getBibfilesCache(Buffer const & buffer) const;
78 EDITABLE editable() const { return IS_EDITABLE; }
80 int latex(odocstream &, OutputParams const &) const;
82 int plaintext(odocstream &, OutputParams const &) const;
84 int docbook(odocstream &, OutputParams const &) const;
86 void validate(LaTeXFeatures &) const;
88 void addPreview(graphics::PreviewLoader &) const;
90 void addToToc(ParConstIterator const &) const;
92 void updateLabels(ParIterator const &);
94 static ParamInfo const & findInfo(std::string const &);
96 static std::string defaultCommand() { return "include"; }
98 static bool isCompatibleCommand(std::string const & s);
100 InsetInclude(InsetInclude const &);
102 void doDispatch(Cursor & cur, FuncRequest & cmd);
104 Inset * clone() const { return new InsetInclude(*this); }
106 /** Slot receiving a signal that the external file has changed
107 * and the preview should be regenerated.
109 void fileChanged() const;
111 /// set the parameters
112 void setParams(InsetCommandParams const & params);
113 /// get the text displayed on the button
114 docstring screenLabel() const;
115 /// holds the entity name that defines the file location (SGML)
116 docstring const include_label;
118 /// The pointer never changes although *preview_'s contents may.
119 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
122 mutable bool set_label_;
123 mutable RenderButton button_;
124 mutable docstring listings_label_;
128 /// return loaded Buffer or zero if the file loading did not proceed.
129 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
133 #endif // INSET_INCLUDE_H