]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
Fix bug #12795
[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 Kimberly 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 "support/unique_ptr.h"
19
20
21 namespace lyx {
22
23 class Buffer;
24 class Dimension;
25 class InsetCommandParams;
26 class InsetLabel;
27 class LaTeXFeatures;
28 class RenderMonitoredPreview;
29
30 namespace support {
31         class FileNameList;
32 }
33
34 /// for including tex/lyx files
35 class InsetInclude : public InsetCommand {
36         // Disable assignment operator, since it is not used, and cannot be
37         // implemented consistently with the copy constructor, because
38         // include_label is const.
39         InsetInclude & operator=(InsetInclude const &);
40 public:
41         ///
42         InsetInclude(Buffer * buf, InsetCommandParams const &);
43         ///
44         ~InsetInclude();
45
46         ///
47         void setChildBuffer(Buffer * buffer);
48
49         /// \return loaded Buffer or zero if the file loading did not proceed.
50         Buffer * loadIfNeeded() const;
51
52         /** Update the cache with all bibfiles in use of the child buffer
53          *  (including bibfiles of grandchild documents).
54          *  Does nothing if the child document is not loaded to prevent
55          *  automatic loading of all child documents upon loading the master.
56          *  \param buffer the Buffer containing this inset.
57          */
58         void updateBibfilesCache();
59
60         ///
61         void updateCommand();
62         ///
63         void write(std::ostream &) const override;
64
65         /// \name Public functions inherited from Inset class
66         //@{
67         ///
68         void setBuffer(Buffer & buffer) override;
69         ///
70         bool isLabeled() const override { return true; }
71         ///
72         bool inheritFont() const override;
73         /// Override these InsetButton methods if Previewing
74         void metrics(MetricsInfo & mi, Dimension & dim) const override;
75         ///
76         void draw(PainterInfo & pi, int x, int y) const override;
77         ///
78         int rowFlags() const override;
79         ///
80         InsetCode lyxCode() const override { return INCLUDE_CODE; }
81         ///
82         docstring layoutName() const override;
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 override;
88         ///
89         bool hasSettings() const override { return true; }
90         ///
91         void latex(otexstream &, OutputParams const &) const override;
92         ///
93         int plaintext(odocstringstream & ods, OutputParams const & op,
94                       size_t max_length = INT_MAX) const override;
95         ///
96         void docbook(XMLStream &, OutputParams const &) const override;
97         ///
98         docstring xhtml(XMLStream &, OutputParams const &) const override;
99         ///
100         void validate(LaTeXFeatures &) const override;
101         ///
102         void addPreview(DocIterator const &, graphics::PreviewLoader &) const override;
103         ///
104         void addToToc(DocIterator const & di, bool output_active,
105                                   UpdateType utype, TocBackend & backend) const override;
106         ///
107         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
108         ///
109         std::string contextMenuName() const override;
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 override;
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         /// launch external application
135         void editIncluded(std::string const & file);
136         ///
137         bool isChildIncluded() const;
138         /// check whether the included file exist
139         bool includedFileExist() const;
140         /// \return True if there is a recursive include
141         /// Also issues appropriate warning, etc
142         bool checkForRecursiveInclude(Buffer const * cbuf, bool silent = false) const;
143
144         /// \name Private functions inherited from Inset class
145         //@{
146         Inset * clone() const override { return new InsetInclude(*this); }
147         ///
148         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
149         ///
150         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
151         //@}
152
153         /// \name Private functions inherited from InsetCommand class
154         //@{
155         /// set the parameters
156         // FIXME:InsetCommmand::setParams is not virtual
157         void setParams(InsetCommandParams const & params);
158         /// get the text displayed on the button
159         docstring screenLabel() const override;
160         //@}
161
162         /// holds the entity name that defines the file location (XML)
163         docstring const include_label;
164
165         /// The pointer never changes although *preview_'s contents may.
166         unique_ptr<RenderMonitoredPreview> const preview_;
167
168         ///
169         mutable bool failedtoload_;
170         /// cache
171         mutable docstring listings_label_;
172         InsetLabel * label_;
173         mutable Buffer * child_buffer_;
174         mutable bool file_exist_;
175         mutable bool recursion_error_;
176 };
177
178
179 } // namespace lyx
180
181 #endif // INSET_INCLUDE_H