]> git.lyx.org Git - lyx.git/blob - src/insets/insetinclude.h
Insetcite updates from Angus
[lyx.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         ///
31         InsetInclude(): InsetCommand("include")
32         {
33                 flag = InsetInclude::INCLUDE;
34         }
35         ///
36         InsetInclude(string const &,  Buffer *);
37         ///
38         ~InsetInclude();
39         ///
40         Inset * Clone() const;
41         ///
42         Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; }
43         /// This returns the list of labels on the child buffer
44         std::vector<string> getLabelList() const;
45         /// This returns the list of bibkeys on the child buffer
46         std::vector< std::pair<string,string> > getKeys() const;
47         ///
48         void Edit(BufferView *, int x, int y, unsigned int button);
49         ///
50         EDITABLE Editable() const
51         {
52                 return IS_EDITABLE;
53         }
54         /// With lyx3 we won't overload these 3 methods
55         void Write(Buffer const *, std::ostream &) const;
56         ///
57         void Read(Buffer const *, LyXLex &);
58         /// 
59         int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
60         ///
61         void Validate(LaTeXFeatures &) const;
62         
63         /// Input inserts anything inside a paragraph, Display can give some visual feedback 
64         bool display() const;
65         ///
66         string getScreenLabel() const;
67         ///
68         void setContents(string const & c);
69         ///
70         void setFilename(string const & n) { setContents(n); }
71         ///
72         string getMasterFilename() const { return master->fileName(); }
73         ///
74         string getFileName() const { 
75                 return filename;
76         }
77         ///  In "input" mode uses \input instead of \include.
78         bool isInput() const { return flag == InsetInclude::INPUT; }
79         ///  If this is true, the child file shouldn't be loaded by lyx
80         bool isNoLoad() const { return noload; }
81
82         /**  A verbatim file shouldn't be loaded by LyX
83          *  No need to generate LaTeX code of a verbatim file
84          */ 
85         bool isVerb() const;
86         ///
87         bool isVerbVisibleSpace() const { return flag == InsetInclude::VERBAST;}
88         ///  
89         bool isInclude() const { return flag == InsetInclude::INCLUDE;}
90         ///  
91         void setInput();
92         ///  
93         void setNoLoad(bool);
94         ///  
95         void setInclude();
96         ///  
97         void setVerb();
98         ///
99         void setVisibleSpace(bool b);
100         /// return true if the file is or got loaded.
101         bool loadIfNeeded() const;
102 private:
103         ///
104         enum Include_Flags {
105                 ///
106                 INCLUDE= 0,
107                 ///
108                 VERB = 1,
109                 ///
110                 INPUT = 2,
111                 ///
112                 VERBAST = 3
113         };
114         
115         ///
116         bool noload;
117         ///
118         int flag;
119         ///
120         Buffer * master;
121         ///
122         string filename;
123 };
124
125
126 inline 
127 bool InsetInclude::isVerb() const
128 {
129         return flag == InsetInclude::VERB || flag == InsetInclude::VERBAST; 
130 }
131
132
133 inline
134 void InsetInclude::setInput()
135 {
136         if (!isInput()) {
137             flag = InsetInclude::INPUT;
138             setCmdName("input");
139         }
140 }
141
142
143 inline
144 void InsetInclude::setNoLoad(bool b)
145
146                 noload = b;
147 }
148
149
150 inline
151 void InsetInclude::setInclude()
152 {
153         if (!isInclude()) {
154             flag = InsetInclude::INCLUDE;
155             setCmdName("include");
156         }
157 }
158
159
160 inline
161 void InsetInclude::setVerb()
162
163         if (!isVerb()) {
164             flag = InsetInclude::VERB;
165             setCmdName("verbatiminput");
166         }
167 }
168
169
170 inline
171 void InsetInclude::setVisibleSpace(bool b)
172 {
173         if (b && flag == InsetInclude::VERB) {
174             setCmdName("verbatiminput*");
175             flag = InsetInclude::VERBAST;
176         } else if (!b && flag == InsetInclude::VERBAST) {
177             setCmdName("verbatiminput");
178             flag = InsetInclude::VERB;
179         }
180 }
181 #endif