]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
3264f5ccd382f8a9e3f4c61895b3c6927ff325da
[lyx.git] / src / insets / InsetInclude.h
1 // -*- C++ -*-
2 /**
3  * \file InsetInclude.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Richard Heck (conversion to InsetCommand)
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_INCLUDE_H
14 #define INSET_INCLUDE_H
15
16 #include "InsetCommand.h"
17
18 #include "BiblioInfo.h"
19 #include "Counters.h"
20 #include "InsetCommandParams.h"
21 #include "RenderButton.h"
22
23 #include "support/FileNameList.h"
24
25 #include <boost/scoped_ptr.hpp>
26
27 namespace lyx {
28
29 class Buffer;
30 class Dimension;
31 class InsetLabel;
32 class LaTeXFeatures;
33 class RenderMonitoredPreview;
34
35 /// for including tex/lyx files
36 class InsetInclude : public InsetCommand {
37 public:
38         ///
39         InsetInclude(Buffer * buf, InsetCommandParams const &);
40         ///
41         ~InsetInclude();
42
43         ///
44         void setChildBuffer(Buffer * buffer);
45         /// \return the child buffer if the file is a LyX doc and could be loaded
46         Buffer * getChildBuffer() const;
47
48         /** Update the cache with all bibfiles in use of the child buffer
49          *  (including bibfiles of grandchild documents).
50          *  Does nothing if the child document is not loaded to prevent
51          *  automatic loading of all child documents upon loading the master.
52          *  \param buffer the Buffer containing this inset.
53          */
54         void updateBibfilesCache();
55
56         /** Return the cache with all bibfiles in use of the child buffer
57          *  (including bibfiles of grandchild documents).
58          *  Return an empty vector if the child doc is not loaded.
59          *  \param buffer the Buffer containing this inset.
60          */
61         support::FileNameList const &
62                 getBibfilesCache() const;
63
64         ///
65         void updateCommand();
66
67         /// \name Public functions inherited from Inset class
68         //@{
69         ///
70         void setBuffer(Buffer & buffer);
71         ///
72         bool isLabeled() const { return true; }
73         /// Override these InsetButton methods if Previewing
74         void metrics(MetricsInfo & mi, Dimension & dim) const;
75         ///
76         void draw(PainterInfo & pi, int x, int y) const;
77         ///
78         DisplayType display() const;
79         ///
80         InsetCode lyxCode() const { return INCLUDE_CODE; }
81         /** Fills \c key
82          *  \param keys the list of bibkeys in the child buffer.
83          *  \param it not used here
84          */
85         void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
86         ///
87         bool hasSettings() const { return true; }
88         ///
89         int latex(odocstream &, OutputParams const &) const;
90         ///
91         int plaintext(odocstream &, OutputParams const &) const;
92         ///
93         int docbook(odocstream &, OutputParams const &) const;
94         ///
95         docstring xhtml(XHTMLStream &, OutputParams const &) const;
96         ///
97         void validate(LaTeXFeatures &) const;
98         ///
99         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
100         ///
101         void addToToc(DocIterator const &);
102         ///
103         void updateBuffer(ParIterator const &, UpdateType);
104         ///
105         docstring contextMenu(BufferView const & bv, int x, int y) const;
106         //@}
107
108         /// \name Static public methods obligated for InsetCommand derived classes
109         //@{
110         ///
111         static ParamInfo const & findInfo(std::string const &);
112         ///
113         static std::string defaultCommand() { return "include"; }
114         ///
115         static bool isCompatibleCommand(std::string const & s);
116         //@}
117
118 protected:
119         ///
120         InsetInclude(InsetInclude const &);
121
122 private:
123         /** Slot receiving a signal that the external file has changed
124          *  and the preview should be regenerated.
125          */
126         void fileChanged() const;
127         /// \return loaded Buffer or zero if the file loading did not proceed.
128         Buffer * loadIfNeeded() const;
129         /// launch external application
130         void editIncluded(std::string const & file);
131         ///
132         bool isChildIncluded() const;
133
134         /// \name Private functions inherited from Inset class
135         //@{
136         Inset * clone() const { return new InsetInclude(*this); }
137         ///
138         void doDispatch(Cursor & cur, FuncRequest & cmd);
139         ///
140         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
141         //@}
142
143         /// \name Private functions inherited from InsetCommand class
144         //@{
145         /// set the parameters
146         // FIXME:InsetCommmand::setParams is not virtual
147         void setParams(InsetCommandParams const & params);
148         /// get the text displayed on the button
149         docstring screenLabel() const;
150         //@}    
151         
152         /// holds the entity name that defines the file location (SGML)
153         docstring const include_label;
154
155         /// The pointer never changes although *preview_'s contents may.
156         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
157
158         /// 
159         mutable bool failedtoload_;
160         /// cache
161         mutable bool set_label_;
162         mutable RenderButton button_;
163         mutable docstring listings_label_;
164         InsetLabel * label_;
165         mutable Buffer * child_buffer_;
166 };
167
168
169 } // namespace lyx
170
171 #endif // INSET_INCLUDE_H