]> git.lyx.org Git - lyx.git/blob - src/buffer.h
remove paragraph::autoBreakRows
[lyx.git] / src / buffer.h
1 // -*- C++ -*-
2 /**
3  * \file buffer.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  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BUFFER_H
13 #define BUFFER_H
14
15 #include "InsetList.h"
16
17 #include "support/limited_stack.h"
18 #include "support/types.h"
19
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signal.hpp>
22
23 #include <iosfwd>
24 #include <map>
25 #include <utility>
26 #include <vector>
27
28
29 class BufferParams;
30 class ErrorItem;
31 class FuncRequest;
32 class InsetBase;
33 class InsetText;
34 class LyXFont;
35 class LyXLex;
36 class LyXRC;
37 class LyXText;
38 class LyXVC;
39 class LaTeXFeatures;
40 class Language;
41 class MacroData;
42 class OutputParams;
43 class ParagraphList;
44 class ParConstIterator;
45 class ParIterator;
46 class TeXErrors;
47 class TexRow;
48 class Undo;
49
50
51 /** The buffer object.
52   This is the buffer object. It contains all the informations about
53   a document loaded into LyX. I am not sure if the class is complete or
54   minimal, probably not.
55   \author Lars Gullik Bjønnes
56   */
57 class Buffer {
58 public:
59         /// What type of log will \c getLogName() return?
60         enum LogType {
61                 latexlog, ///< LaTeX log
62                 buildlog  ///< Literate build log
63         };
64
65         /** Constructor
66             \param file
67             \param b  optional \c false by default
68         */
69         explicit Buffer(std::string const & file, bool b = false);
70
71         /// Destructor
72         ~Buffer();
73
74         /** High-level interface to buffer functionality.
75             This function parses a command string and executes it
76         */
77         bool dispatch(std::string const & command, bool * result = 0);
78
79         /// Maybe we know the function already by number...
80         bool dispatch(FuncRequest const & func, bool * result = 0);
81
82         /// Load the autosaved file.
83         void loadAutoSaveFile();
84
85         /// load a new file
86         bool readFile(std::string const & filename);
87
88         bool readFile(std::string const & filename, lyx::pit_type pit);
89
90         /// read the header, returns number of unknown tokens
91         int readHeader(LyXLex & lex);
92
93         /** Reads a file without header.
94             \param par if != 0 insert the file.
95             \return \c false if file is not completely read.
96         */
97         bool readDocument(LyXLex &);
98
99         ///
100         void insertStringAsLines(ParagraphList & plist,
101                 lyx::pit_type &, lyx::pos_type &,
102                 LyXFont const &, std::string const &, bool);
103         ///
104         ParIterator getParFromID(int id) const;
105         /// do we have a paragraph with this id?
106         bool hasParWithID(int id) const;
107
108         /// This signal is emitted when a parsing error shows up.
109         boost::signal<void(ErrorItem)> error;
110         /// This signal is emitted when some message shows up.
111         boost::signal<void(std::string)> message;
112         /// This signal is emitted when the buffer busy status change.
113         boost::signal<void(bool)> busy;
114         /// This signal is emitted when the buffer readonly status change.
115         boost::signal<void(bool)> readonly;
116         /// Update window titles of all users.
117         boost::signal<void()> updateTitles;
118         /// Reset autosave timers for all users.
119         boost::signal<void()> resetAutosaveTimers;
120         /// This signal is emitting if the buffer is being closed.
121         boost::signal<void()> closing;
122
123
124         /** Save file.
125             Takes care of auto-save files and backup file if requested.
126             Returns \c true if the save is successful, \c false otherwise.
127         */
128         bool save() const;
129
130         /// Write file. Returns \c false if unsuccesful.
131         bool writeFile(std::string const &) const;
132
133         ///
134         void writeFileAscii(std::string const &, OutputParams const &);
135         ///
136         void writeFileAscii(std::ostream &, OutputParams const &);
137         /// Just a wrapper for the method below, first creating the ofstream.
138         void makeLaTeXFile(std::string const & filename,
139                            std::string const & original_path,
140                            OutputParams const &,
141                            bool output_preamble = true,
142                            bool output_body = true);
143         ///
144         void makeLaTeXFile(std::ostream & os,
145                            std::string const & original_path,
146                            OutputParams const &,
147                            bool output_preamble = true,
148                            bool output_body = true);
149         ///
150         void makeLinuxDocFile(std::string const & filename,
151                               OutputParams const & runparams_in,
152                               bool only_body = false);
153         ///
154         void makeDocBookFile(std::string const & filename,
155                              OutputParams const & runparams_in,
156                              bool only_body = false);
157         /// returns the main language for the buffer (document)
158         Language const * getLanguage() const;
159         /// get l10n translated to the buffers language
160         std::string const B_(std::string const & l10n) const;
161
162         ///
163         int runChktex();
164         /// return true if the main lyx file does not need saving
165         bool isClean() const;
166         ///
167         bool isBakClean() const;
168         ///
169         bool isDepClean(std::string const & name) const;
170
171         /// mark the main lyx file as not needing saving
172         void markClean() const;
173
174         ///
175         void markBakClean();
176
177         ///
178         void markDepClean(std::string const & name);
179
180         ///
181         void setUnnamed(bool flag = true);
182
183         ///
184         bool isUnnamed() const;
185
186         /// Mark this buffer as dirty.
187         void markDirty();
188
189         /// Returns the buffer's filename. It is always an absolute path.
190         std::string const & fileName() const;
191
192         /// Returns the the path where the buffer lives.
193         /// It is always an absolute path.
194         std::string const & filePath() const;
195
196         /** A transformed version of the file name, adequate for LaTeX.
197             \param no_path optional if \c true then the path is stripped.
198         */
199         std::string const getLatexName(bool no_path = true) const;
200
201         /// Get the name and type of the log.
202         std::pair<LogType, std::string> const getLogName() const;
203
204         /// Change name of buffer. Updates "read-only" flag.
205         void setFileName(std::string const & newfile);
206
207         /// Name of the document's parent
208         void setParentName(std::string const &);
209
210         /** Get the document's master (or \c this if this is not a
211             child document)
212          */
213         Buffer const * getMasterBuffer() const;
214
215         /// Is buffer read-only?
216         bool isReadonly() const;
217
218         /// Set buffer read-only flag
219         void setReadonly(bool flag = true);
220
221         /// returns \c true if the buffer contains a LaTeX document
222         bool isLatex() const;
223         /// returns \c true if the buffer contains a LinuxDoc document
224         bool isLinuxDoc() const;
225         /// returns \c true if the buffer contains a DocBook document
226         bool isDocBook() const;
227         /** returns \c true if the buffer contains either a LinuxDoc
228             or DocBook document */
229         bool isSGML() const;
230         /// returns \c true if the buffer contains a Wed document
231         bool isLiterate() const;
232
233         /** Validate a buffer for LaTeX.
234             This validates the buffer, and returns a struct for use by
235             #makeLaTeX# and others. Its main use is to figure out what
236             commands and packages need to be included in the LaTeX file.
237             It (should) also check that the needed constructs are there
238             (i.e. that the \refs points to coresponding \labels). It
239             should perhaps inset "error" insets to help the user correct
240             obvious mistakes.
241         */
242         void validate(LaTeXFeatures &) const;
243
244         /// return all bibkeys from buffer and its childs
245         void fillWithBibKeys(std::vector<std::pair<std::string, std::string> > & keys) const;
246         ///
247         void getLabelList(std::vector<std::string> &) const;
248
249         ///
250         void changeLanguage(Language const * from, Language const * to);
251
252         ///
253         void updateDocLang(Language const * nlang);
254
255         ///
256         bool isMultiLingual() const;
257
258         /// Does this mean that this is buffer local?
259         limited_stack<Undo> & undostack();
260         limited_stack<Undo> const & undostack() const;
261
262         /// Does this mean that this is buffer local?
263         limited_stack<Undo> & redostack();
264         limited_stack<Undo> const & redostack() const;
265
266         ///
267         BufferParams & params();
268         BufferParams const & params() const;
269
270         /** The list of paragraphs.
271             This is a linked list of paragraph, this list holds the
272             whole contents of the document.
273          */
274         ParagraphList & paragraphs();
275         ParagraphList const & paragraphs() const;
276
277         /// LyX version control object.
278         LyXVC & lyxvc();
279         LyXVC const & lyxvc() const;
280
281         /// Where to put temporary files.
282         std::string const & temppath() const;
283
284         /// Used when typesetting to place errorboxes.
285         TexRow & texrow();
286         TexRow const & texrow() const;
287
288         ///
289         ParIterator par_iterator_begin();
290         ///
291         ParConstIterator par_iterator_begin() const;
292         ///
293         ParIterator par_iterator_end();
294         ///
295         ParConstIterator par_iterator_end() const;
296
297         /** \returns true only when the file is fully loaded.
298          *  Used to prevent the premature generation of previews
299          *  and by the citation inset.
300          */
301         bool fully_loaded() const;
302         /// Set by buffer_funcs' newFile.
303         void fully_loaded(bool);
304
305         ///
306         LyXText & text() const;
307         ///
308         InsetBase & inset() const;
309
310         //
311         // Macro handling
312         //
313         ///
314         void buildMacros();
315         ///
316         bool hasMacro(std::string const & name) const;
317         ///
318         MacroData const & getMacro(std::string const & name) const;
319         ///
320         void insertMacro(std::string const & name, MacroData const & data);
321
322 private:
323         /** Inserts a file into a document
324             \param par if != 0 insert the file.
325             \return \c false if method fails.
326         */
327         bool readFile(LyXLex &, std::string const & filename,
328                       lyx::pit_type pit);
329
330         bool do_writeFile(std::ostream & ofs) const;
331
332         /// Use the Pimpl idiom to hide the internals.
333         class Impl;
334         /// The pointer never changes although *pimpl_'s contents may.
335         boost::scoped_ptr<Impl> const pimpl_;
336 };
337
338 #endif