4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS
17 #include "support/limited_stack.h"
20 #include "bufferparams.h"
22 #include "ParagraphList.h"
23 #include "paragraph.h"
25 #include "iterators.h"
27 #include <boost/shared_ptr.hpp>
28 #include <boost/scoped_ptr.hpp>
37 class ParConstIterator;
41 /** The buffer object.
42 This is the buffer object. It contains all the informations about
43 a document loaded into LyX. I am not sure if the class is complete or
44 minimal, probably not.
45 \author Lars Gullik Bjønnes
49 /// What type of log will \c getLogName() return?
51 latexlog, ///< LaTeX log
52 buildlog ///< Literate build log
57 \param b optional \c false by default
59 explicit Buffer(string const & file, bool b = false);
64 /** High-level interface to buffer functionality.
65 This function parses a command string and executes it
67 bool dispatch(string const & command, bool * result = 0);
69 /// Maybe we know the function already by number...
70 bool dispatch(int ac, string const & argument, bool * result = 0);
73 void resizeInsets(BufferView *);
75 /// Update window titles of all users.
76 void updateTitles() const;
78 /// Reset autosave timers for all users.
79 void resetAutosaveTimers() const;
81 /** Adds the BufferView to the users list.
82 Later this func will insert the \c BufferView into a real list,
83 not just setting a pointer.
85 void addUser(BufferView * u);
87 /** Removes the #BufferView# from the users list.
88 Since we only can have one at the moment, we just reset it.
90 void delUser(BufferView *);
95 /// Load the autosaved file.
96 void loadAutoSaveFile();
98 /** Inserts a file into a document
99 \param par if != 0 insert the file.
100 \return \c false if method fails.
102 bool readFile(LyXLex &, string const &, ParagraphList::iterator pit);
104 // FIXME: it's very silly to pass a lex in here
106 bool readFile(LyXLex &, string const &);
108 /// read the header, returns number of unknown tokens
109 int readHeader(LyXLex & lex);
111 /** Reads a file without header.
112 \param par if != 0 insert the file.
113 \return \c false if file is not completely read.
115 bool readBody(LyXLex &, ParagraphList::iterator pit);
117 /// This parses a single token
118 int readParagraph(LyXLex &, string const & token,
119 ParagraphList & pars, ParagraphList::iterator & pit,
120 Paragraph::depth_type & depth);
123 void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
124 LyXFont const &, string const &);
126 ParIterator getParFromID(int id) const;
127 /// do we have a paragraph with this id?
128 bool hasParWithID(int id) const;
132 Takes care of auto-save files and backup file if requested.
133 Returns \c true if the save is successful, \c false otherwise.
137 /// Write file. Returns \c false if unsuccesful.
138 bool writeFile(string const &) const;
141 void writeFileAscii(string const & , int);
143 void writeFileAscii(std::ostream &, int);
145 string const asciiParagraph(Paragraph const &, unsigned int linelen,
146 bool noparbreak = false) const;
147 /// Just a wrapper for the method below, first creating the ofstream.
148 void makeLaTeXFile(string const & filename,
149 string const & original_path,
150 LatexRunParams const &,
152 bool only_body = false,
153 bool only_preamble = false);
155 void makeLaTeXFile(std::ostream & os,
156 string const & original_path,
157 LatexRunParams const &,
159 bool only_body = false,
160 bool only_preamble = false);
162 void simpleDocBookOnePar(std::ostream &,
163 ParagraphList::iterator par, int & desc_on,
164 Paragraph::depth_type depth) const;
166 void simpleLinuxDocOnePar(std::ostream & os,
167 ParagraphList::iterator par,
168 Paragraph::depth_type depth) const;
170 void makeLinuxDocFile(string const & filename,
171 bool nice, bool only_body = false);
173 void makeDocBookFile(string const & filename,
174 bool nice, bool only_body = false);
176 void sgmlError(ParagraphList::iterator par, int pos, string const & message) const;
178 /// returns the main language for the buffer (document)
179 Language const * getLanguage() const;
180 /// get l10n translated to the buffers language
181 string const B_(string const & l10n) const;
185 /// return true if the main lyx file does not need saving
186 bool isClean() const;
188 bool isBakClean() const;
190 bool isDepClean(string const & name) const;
192 /// mark the main lyx file as not needing saving
193 void markClean() const;
199 void markDepClean(string const & name);
202 void setUnnamed(bool flag = true);
207 /// Mark this buffer as dirty.
210 /// Returns the buffer's filename. It is always an absolute path.
211 string const & fileName() const;
213 /// Returns the the path where the buffer lives.
214 /// It is always an absolute path.
215 string const & filePath() const;
217 /** A transformed version of the file name, adequate for LaTeX.
218 \param no_path optional if \c true then the path is stripped.
220 string const getLatexName(bool no_path = true) const;
222 /// Get the name and type of the log.
223 std::pair<LogType, string> const getLogName() const;
225 /// Change name of buffer. Updates "read-only" flag.
226 void setFileName(string const & newfile);
228 /// Name of the document's parent
229 void setParentName(string const &);
231 /// Is buffer read-only?
232 bool isReadonly() const;
234 /// Set buffer read-only flag
235 void setReadonly(bool flag = true);
237 /// returns \c true if the buffer contains a LaTeX document
238 bool isLatex() const;
239 /// returns \c true if the buffer contains a LinuxDoc document
240 bool isLinuxDoc() const;
241 /// returns \c true if the buffer contains a DocBook document
242 bool isDocBook() const;
243 /** returns \c true if the buffer contains either a LinuxDoc
244 or DocBook document */
246 /// returns \c true if the buffer contains a Wed document
247 bool isLiterate() const;
249 /** Validate a buffer for LaTeX.
250 This validates the buffer, and returns a struct for use by
251 #makeLaTeX# and others. Its main use is to figure out what
252 commands and packages need to be included in the LaTeX file.
253 It (should) also check that the needed constructs are there
254 (i.e. that the \refs points to coresponding \labels). It
255 should perhaps inset "error" insets to help the user correct
258 void validate(LaTeXFeatures &) const;
260 /// return all bibkeys from buffer and its childs
261 void fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const;
263 std::vector<string> const getLabelList() const;
265 /** This will clearly have to change later. Later we can have more
266 than one user per buffer. */
267 BufferView * getUser() const;
270 void changeLanguage(Language const * from, Language const * to);
273 void updateDocLang(Language const * nlang);
276 bool isMultiLingual();
278 /// Does this mean that this is buffer local?
279 limited_stack<boost::shared_ptr<Undo> > undostack;
281 /// Does this mean that this is buffer local?
282 limited_stack<boost::shared_ptr<Undo> > redostack;
287 /** The list of paragraphs.
288 This is a linked list of paragraph, this list holds the
289 whole contents of the document.
291 ParagraphList paragraphs;
293 /// LyX version control object.
296 /// Where to put temporary files.
299 /** If we are writing a nice LaTeX file or not.
300 While writing as LaTeX, tells whether we are
301 doing a 'nice' LaTeX file */
304 /// Used when typesetting to place errorboxes.
307 /// the author list for the document
308 AuthorList & authors();
311 typedef std::map<string, bool> DepClean;
313 /// need to regenerate .tex ?
317 mutable bool lyx_clean;
319 /// is autosave needed
320 mutable bool bak_clean;
322 /// is this a unnamed file (New...)
328 /// name of the file the buffer is associated with.
331 /// The path to the document file.
334 /// Format number of buffer
336 /** A list of views using this buffer.
337 Why not keep a list of the BufferViews that use this buffer?
339 At least then we don't have to do a lot of magic like:
340 #buffer->lyx_gui->bufferview->updateLayoutChoice#. Just ask each
341 of the buffers in the list of users to do a #updateLayoutChoice#.
345 boost::scoped_ptr<Messages> messages_;
348 class inset_iterator {
350 typedef std::input_iterator_tag iterator_category;
351 typedef Inset value_type;
352 typedef ptrdiff_t difference_type;
353 typedef Inset * pointer;
354 typedef Inset & reference;
355 typedef ParagraphList::iterator base_type;
360 inset_iterator(base_type p, base_type e);
362 inset_iterator(base_type p, lyx::pos_type pos, base_type e);
365 inset_iterator & operator++();
367 inset_iterator operator++(int);
369 reference operator*();
371 pointer operator->();
374 ParagraphList::iterator getPar() const;
376 lyx::pos_type getPos() const;
379 bool operator==(inset_iterator const & iter1,
380 inset_iterator const & iter2);
385 ParagraphList::iterator pit;
387 ParagraphList::iterator pend;
389 InsetList::iterator it;
393 inset_iterator inset_iterator_begin() {
394 return inset_iterator(paragraphs.begin(), paragraphs.end());
398 inset_iterator inset_iterator_end() {
399 return inset_iterator();
403 inset_iterator inset_const_iterator_begin() const {
404 return inset_iterator(paragraphs.begin(), paragraphs.end());
408 inset_iterator inset_const_iterator_end() const {
409 return inset_iterator();
413 ParIterator par_iterator_begin();
415 ParConstIterator par_iterator_begin() const;
417 ParIterator par_iterator_end();
419 ParConstIterator par_iterator_end() const;
422 Inset * getInsetFromID(int id_arg) const;
425 bool operator==(Buffer::inset_iterator const & iter1,
426 Buffer::inset_iterator const & iter2);
428 bool operator!=(Buffer::inset_iterator const & iter1,
429 Buffer::inset_iterator const & iter2);