]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
Make script inset much tighter in texted.
[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 "RenderButton.h"
19
20 #include "support/unique_ptr.h"
21
22
23 namespace lyx {
24
25 class BiblioInfo;
26 class Buffer;
27 class Dimension;
28 class InsetCommandParams;
29 class InsetLabel;
30 class LaTeXFeatures;
31 class RenderMonitoredPreview;
32
33 namespace support {
34         class FileNameList;
35 }
36
37 /// for including tex/lyx files
38 class InsetInclude : public InsetCommand {
39         // Disable assignment operator, since it is not used, and cannot be
40         // implemented consistently with the copy constructor, because
41         // include_label is const.
42         InsetInclude & operator=(InsetInclude const &);
43 public:
44         ///
45         InsetInclude(Buffer * buf, InsetCommandParams const &);
46         ///
47         ~InsetInclude();
48
49         ///
50         void setChildBuffer(Buffer * buffer);
51         /// \return the child buffer if the file is a LyX doc and could be loaded
52         Buffer * getChildBuffer() const;
53
54         /** Update the cache with all bibfiles in use of the child buffer
55          *  (including bibfiles of grandchild documents).
56          *  Does nothing if the child document is not loaded to prevent
57          *  automatic loading of all child documents upon loading the master.
58          *  \param buffer the Buffer containing this inset.
59          */
60         void updateBibfilesCache();
61
62         ///
63         void updateCommand();
64         ///
65         void write(std::ostream &) const;
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         ///
82         docstring layoutName() const;
83         /** Fills \c key
84          *  \param keys the list of bibkeys in the child buffer.
85          *  \param it not used here
86          */
87         void collectBibKeys(InsetIterator const &, support::FileNameList &) const;
88         ///
89         bool hasSettings() const { return true; }
90         ///
91         void latex(otexstream &, OutputParams const &) const;
92         ///
93         int plaintext(odocstringstream & ods, OutputParams const & op,
94                       size_t max_length = INT_MAX) const;
95         ///
96         int docbook(odocstream &, OutputParams const &) const;
97         ///
98         docstring xhtml(XHTMLStream &, OutputParams const &) const;
99         ///
100         void validate(LaTeXFeatures &) const;
101         ///
102         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
103         ///
104         void addToToc(DocIterator const & di, bool output_active,
105                                   UpdateType utype, TocBackend & backend) const;
106         ///
107         void updateBuffer(ParIterator const &, UpdateType);
108         ///
109         std::string contextMenuName() const;
110         //@}
111
112         /// \name Static public methods obligated for InsetCommand derived classes
113         //@{
114         ///
115         static ParamInfo const & findInfo(std::string const &);
116         ///
117         static std::string defaultCommand() { return "include"; }
118         ///
119         static bool isCompatibleCommand(std::string const & s);
120         ///
121         bool needsCProtection(bool const maintext = false,
122                               bool const fragile = false) const;
123         //@}
124
125 protected:
126         ///
127         InsetInclude(InsetInclude const &);
128
129 private:
130         /** Slot receiving a signal that the external file has changed
131          *  and the preview should be regenerated.
132          */
133         void fileChanged() const;
134         /// \return loaded Buffer or zero if the file loading did not proceed.
135         Buffer * loadIfNeeded() const;
136         /// launch external application
137         void editIncluded(std::string const & file);
138         ///
139         bool isChildIncluded() const;
140         /// check whether the included file exist
141         bool includedFileExist() const;
142
143         /// \name Private functions inherited from Inset class
144         //@{
145         Inset * clone() const { return new InsetInclude(*this); }
146         ///
147         void doDispatch(Cursor & cur, FuncRequest & cmd);
148         ///
149         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
150         //@}
151
152         /// \name Private functions inherited from InsetCommand class
153         //@{
154         /// set the parameters
155         // FIXME:InsetCommmand::setParams is not virtual
156         void setParams(InsetCommandParams const & params);
157         /// get the text displayed on the button
158         docstring screenLabel() const;
159         //@}
160
161         /// holds the entity name that defines the file location (SGML)
162         docstring const include_label;
163
164         /// The pointer never changes although *preview_'s contents may.
165         unique_ptr<RenderMonitoredPreview> const preview_;
166
167         ///
168         mutable bool failedtoload_;
169         /// cache
170         mutable bool set_label_;
171         mutable RenderButton button_;
172         mutable docstring listings_label_;
173         InsetLabel * label_;
174         mutable Buffer * child_buffer_;
175         mutable bool file_exist_;
176 };
177
178
179 } // namespace lyx
180
181 #endif // INSET_INCLUDE_H