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"
23 #include "support/FileNameList.h"
25 #include <boost/scoped_ptr.hpp>
33 class RenderMonitoredPreview;
35 /// for including tex/lyx files
36 class InsetInclude : public InsetCommand {
39 InsetInclude(InsetCommandParams const &);
42 void setBuffer(Buffer & buffer);
43 bool isLabeled() const { return true; }
45 /// Override these InsetButton methods if Previewing
46 void metrics(MetricsInfo & mi, Dimension & dim) const;
48 void draw(PainterInfo & pi, int x, int y) const;
50 DisplayType display() const;
52 InsetCode lyxCode() const { return INCLUDE_CODE; }
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 void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
60 /** Update the cache with all bibfiles in use of the child buffer
61 * (including bibfiles of grandchild documents).
62 * Does nothing if the child document is not loaded to prevent
63 * automatic loading of all child documents upon loading the master.
64 * \param buffer the Buffer containing this inset.
66 void updateBibfilesCache();
67 /** Return the cache with all bibfiles in use of the child buffer
68 * (including bibfiles of grandchild documents).
69 * Return an empty vector if the child doc is not loaded.
70 * \param buffer the Buffer containing this inset.
72 support::FileNameList const &
73 getBibfilesCache(Buffer const & buffer) const;
75 EDITABLE editable() const { return IS_EDITABLE; }
77 int latex(odocstream &, OutputParams const &) const;
79 int plaintext(odocstream &, OutputParams const &) const;
81 int docbook(odocstream &, OutputParams const &) const;
83 void validate(LaTeXFeatures &) const;
85 void addPreview(graphics::PreviewLoader &) const;
87 void addToToc(DocIterator const &);
91 void updateLabels(ParIterator const &);
93 static ParamInfo const & findInfo(std::string const &);
95 static std::string defaultCommand() { return "include"; }
97 static bool isCompatibleCommand(std::string const & s);
99 docstring contextMenu(BufferView const & bv, int x, int y) const;
100 /// \return the child buffer if the file is a LyX doc and is loaded
101 Buffer * getChildBuffer(Buffer const & buffer) const;
102 /// \return loaded Buffer or zero if the file loading did not proceed.
103 Buffer * loadIfNeeded(Buffer const & parent) const;
105 InsetInclude(InsetInclude const &);
107 void doDispatch(Cursor & cur, FuncRequest & cmd);
109 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
111 Inset * clone() const { return new InsetInclude(*this); }
113 /** Slot receiving a signal that the external file has changed
114 * and the preview should be regenerated.
116 void fileChanged() const;
118 /// launch external application
119 void editIncluded(std::string const & file);
120 /// set the parameters
121 void setParams(InsetCommandParams const & params);
122 /// get the text displayed on the button
123 docstring screenLabel() const;
124 /// holds the entity name that defines the file location (SGML)
125 docstring const include_label;
127 /// The pointer never changes although *preview_'s contents may.
128 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
131 mutable bool failedtoload_;
133 mutable bool set_label_;
134 mutable RenderButton button_;
135 mutable docstring listings_label_;
137 mutable Buffer * child_buffer_;
143 #endif // INSET_INCLUDE_H