]> git.lyx.org Git - lyx.git/blob - src/insets/InsetInclude.h
Fix some bugs in the bibinfo caching mechanism. Comments to follow.
[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         ~InsetInclude();
41
42         void setBuffer(Buffer & buffer);
43         bool isLabeled() const { return true; }
44
45         /// Override these InsetButton methods if Previewing
46         void metrics(MetricsInfo & mi, Dimension & dim) const;
47         ///
48         void draw(PainterInfo & pi, int x, int y) const;
49         ///
50         DisplayType display() const;
51         ///
52         InsetCode lyxCode() const { return INCLUDE_CODE; }
53
54         ///
55         void setChildBuffer(Buffer * buffer);
56
57         /** Fills \c keys
58          *  \param buffer the Buffer containing this inset.
59          *  \param keys the list of bibkeys in the child buffer.
60          *  \param it not used here
61          */
62         void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
63         
64         ///
65         bool hasSettings() const { return true; }
66         ///
67         int latex(odocstream &, OutputParams const &) const;
68         ///
69         int plaintext(odocstream &, OutputParams const &) const;
70         ///
71         int docbook(odocstream &, OutputParams const &) const;
72         ///
73         docstring xhtml(XHTMLStream &, OutputParams const &) const;
74         ///
75         void validate(LaTeXFeatures &) const;
76         ///
77         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
78         ///
79         void addToToc(DocIterator const &);
80         ///
81         void updateCommand();
82         ///
83         void updateBuffer(ParIterator const &, UpdateType);
84         ///
85         static ParamInfo const & findInfo(std::string const &);
86         ///
87         static std::string defaultCommand() { return "include"; }
88         ///
89         static bool isCompatibleCommand(std::string const & s);
90         ///
91         docstring contextMenu(BufferView const & bv, int x, int y) const;
92         /// \return the child buffer if the file is a LyX doc and could be loaded
93         Buffer * getChildBuffer() const;
94 protected:
95         InsetInclude(InsetInclude const &);
96         ///
97         void doDispatch(Cursor & cur, FuncRequest & cmd);
98         ///
99         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
100 private:
101         Inset * clone() const { return new InsetInclude(*this); }
102
103         /** Slot receiving a signal that the external file has changed
104          *  and the preview should be regenerated.
105          */
106         void fileChanged() const;
107
108         /// \return loaded Buffer or zero if the file loading did not proceed.
109         Buffer * loadIfNeeded() const;
110         /// launch external application
111         void editIncluded(std::string const & file);
112         /// set the parameters
113         void setParams(InsetCommandParams const & params);
114         /// get the text displayed on the button
115         docstring screenLabel() const;
116         /// holds the entity name that defines the file location (SGML)
117         docstring const include_label;
118         ///
119         bool isChildIncluded() const;
120
121         /// The pointer never changes although *preview_'s contents may.
122         boost::scoped_ptr<RenderMonitoredPreview> const preview_;
123
124         /// 
125         mutable bool failedtoload_;
126         /// cache
127         mutable bool set_label_;
128         mutable RenderButton button_;
129         mutable docstring listings_label_;
130         InsetLabel * label_;
131         mutable Buffer * child_buffer_;
132 };
133
134
135 } // namespace lyx
136
137 #endif // INSET_INCLUDE_H