]> git.lyx.org Git - features.git/blob - src/insets/insetinclude.h
read the Changelog
[features.git] / src / insets / insetinclude.h
1 // -*- C++ -*-
2 /* This file is part of*
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *       
7  *          Copyright 1997 LyX Team (this file was created this year)
8  * 
9  * ====================================================== */
10
11 #ifndef INSET_INCLUDE_H
12 #define INSET_INCLUDE_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include "insetcommand.h"
19 #include "buffer.h"
20 #include "support/filetools.h"
21
22 struct LaTeXFeatures;
23
24 // Created by AAS 970521
25
26 /**  Used to include files
27  */
28 class InsetInclude: public InsetCommand {
29 public:
30 #if 0
31         ///
32         InsetInclude(): InsetCommand("include")
33         {
34                 flag = InsetInclude::INCLUDE;
35         }
36 #endif
37         ///
38         InsetInclude(string const &,  Buffer *);
39         ///
40         ~InsetInclude();
41         ///
42         Inset * Clone() const;
43         ///
44         Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; }
45         /// This returns the list of labels on the child buffer
46         std::vector<string> getLabelList() const;
47         /// This returns the list of bibkeys on the child buffer
48         std::vector< std::pair<string,string> > getKeys() const;
49         ///
50         void Edit(BufferView *, int x, int y, unsigned int button);
51         ///
52         EDITABLE Editable() const
53         {
54                 return IS_EDITABLE;
55         }
56         /// With lyx3 we won't overload these 3 methods
57         void Write(Buffer const *, std::ostream &) const;
58         ///
59         void Read(Buffer const *, LyXLex &);
60         /// 
61         int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
62         ///
63         int Linuxdoc(Buffer const *, std::ostream &) const;
64         ///
65         int DocBook(Buffer const *, std::ostream &) const;
66         ///
67         void Validate(LaTeXFeatures &) const;
68         
69         /** Input inserts anything inside a paragraph.
70             Display can give some visual feedback
71         */
72         bool display() const;
73         ///
74         string getScreenLabel() const;
75         ///
76         void setContents(string const & c);
77         ///
78         void setFilename(string const & n) { setContents(n); }
79         ///
80         string getMasterFilename() const { return master->fileName(); }
81         ///
82         string getFileName() const { 
83                 return filename;
84         }
85         ///  In "input" mode uses \input instead of \include.
86         bool isInput() const { return flag == InsetInclude::INPUT; }
87         ///  If this is true, the child file shouldn't be loaded by lyx
88         bool isNoLoad() const { return noload; }
89
90         /**  A verbatim file shouldn't be loaded by LyX
91          *  No need to generate LaTeX code of a verbatim file
92          */ 
93         bool isVerb() const;
94         ///
95         bool isVerbVisibleSpace() const {
96                 return flag == InsetInclude::VERBAST;
97         }
98         ///  
99         bool isInclude() const { return flag == InsetInclude::INCLUDE;}
100         ///  
101         void setInput();
102         ///  
103         void setNoLoad(bool);
104         ///  
105         void setInclude();
106         ///  
107         void setVerb();
108         ///
109         void setVisibleSpace(bool b);
110         /// return true if the file is or got loaded.
111         bool loadIfNeeded() const;
112 private:
113         ///
114         enum Include_Flags {
115                 ///
116                 INCLUDE= 0,
117                 ///
118                 VERB = 1,
119                 ///
120                 INPUT = 2,
121                 ///
122                 VERBAST = 3
123         };
124         
125         ///
126         bool noload;
127         ///
128         int flag;
129         ///
130         Buffer * master;
131         ///
132         string filename;
133         ///
134         mutable string include_label;
135 };
136
137
138 inline 
139 bool InsetInclude::isVerb() const
140 {
141         return flag == InsetInclude::VERB || flag == InsetInclude::VERBAST; 
142 }
143
144
145 inline
146 void InsetInclude::setInput()
147 {
148         if (!isInput()) {
149             flag = InsetInclude::INPUT;
150             setCmdName("input");
151         }
152 }
153
154
155 inline
156 void InsetInclude::setNoLoad(bool b)
157
158                 noload = b;
159 }
160
161
162 inline
163 void InsetInclude::setInclude()
164 {
165         if (!isInclude()) {
166             flag = InsetInclude::INCLUDE;
167             setCmdName("include");
168         }
169 }
170
171
172 inline
173 void InsetInclude::setVerb()
174
175         if (!isVerb()) {
176             flag = InsetInclude::VERB;
177             setCmdName("verbatiminput");
178         }
179 }
180
181
182 inline
183 void InsetInclude::setVisibleSpace(bool b)
184 {
185         if (b && flag == InsetInclude::VERB) {
186             setCmdName("verbatiminput*");
187             flag = InsetInclude::VERBAST;
188         } else if (!b && flag == InsetInclude::VERBAST) {
189             setCmdName("verbatiminput");
190             flag = InsetInclude::VERB;
191         }
192 }
193 #endif