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 "BiblioInfo.h"
17 #include "InsetCommand.h"
18 #include "InsetCommandParams.h"
19 #include "RenderButton.h"
20 #include "MailInset.h"
22 #include "EmbeddedFiles.h"
24 #include <boost/scoped_ptr.hpp>
31 class RenderMonitoredPreview;
33 /// for including tex/lyx files
34 class InsetInclude : public InsetCommand {
37 InsetInclude(InsetCommandParams const &);
39 /// Override these InsetButton methods if Previewing
40 void metrics(MetricsInfo & mi, Dimension & dim) const;
42 void draw(PainterInfo & pi, int x, int y) const;
44 virtual DisplayType display() const;
46 InsetCode lyxCode() const { return INCLUDE_CODE; }
48 * \param buffer the Buffer containing this inset.
49 * \param list the list of labels in the child buffer.
51 void getLabelList(Buffer const & buffer,
52 std::vector<docstring> & list) const;
54 * \param buffer the Buffer containing this inset.
55 * \param keys the list of bibkeys in the child buffer.
56 * \param it not used here
58 virtual void fillWithBibKeys(Buffer const & buffer,
59 BiblioInfo & keys, InsetIterator const & it) const;
61 /** Update the cache with all bibfiles in use of the child buffer
62 * (including bibfiles of grandchild documents).
63 * Does nothing if the child document is not loaded to prevent
64 * automatic loading of all child documents upon loading the master.
65 * \param buffer the Buffer containing this inset.
67 void updateBibfilesCache(Buffer const & buffer);
68 /** Return the cache with all bibfiles in use of the child buffer
69 * (including bibfiles of grandchild documents).
70 * Return an empty vector if the child doc is not loaded.
71 * \param buffer the Buffer containing this inset.
73 EmbeddedFileList const &
74 getBibfilesCache(Buffer const & buffer) const;
76 EDITABLE editable() const { return IS_EDITABLE; }
78 int latex(Buffer const &, odocstream &,
79 OutputParams const &) const;
81 int plaintext(Buffer const &, odocstream &,
82 OutputParams const &) const;
84 int docbook(Buffer const &, odocstream &,
85 OutputParams const &) const;
87 void validate(LaTeXFeatures &) const;
89 void addPreview(graphics::PreviewLoader &) const;
91 void addToToc(TocList &, Buffer const &, ParConstIterator const &) const;
93 void updateLabels(Buffer const & buffer, ParIterator const &);
94 /// child document can be embedded
95 void registerEmbeddedFiles(Buffer const &, EmbeddedFileList &) const;
97 void updateEmbeddedFile(Buffer const & buf, EmbeddedFile const & file);
99 static CommandInfo const * findInfo(std::string const &);
101 static std::string defaultCommand() { return "include"; };
103 static bool isCompatibleCommand(std::string const & s);
105 InsetInclude(InsetInclude const &);
107 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
109 virtual Inset * clone() const;
111 /** Slot receiving a signal that the external file has changed
112 * and the preview should be regenerated.
114 void fileChanged() const;
116 /// set the parameters
117 void set(InsetCommandParams const & params, Buffer const &);
118 /// get the text displayed on the button
119 docstring const getScreenLabel(Buffer const &) const;
120 /// holds the entity name that defines the file location (SGML)
121 docstring const include_label;
123 /// The pointer never changes although *preview_'s contents may.
124 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
127 mutable bool set_label_;
128 mutable RenderButton button_;
129 mutable docstring listings_label_;
132 /// return the child buffer if the file is a LyX doc and is loaded
133 Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params);
135 /// return loaded Buffer or zero if the file loading did not proceed.
136 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params);
139 void resetParentBuffer(Buffer const * parent, InsetCommandParams const & params,
144 #endif // INSETINCLUDE_H