2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
8 * This file is Copyleft 1996
11 * ====================================================== */
22 #include "support/limited_stack.h"
25 #include "bufferparams.h"
27 #include "ParagraphList.h"
28 #include "paragraph.h"
30 #include <boost/shared_ptr.hpp>
50 /** The buffer object.
51 This is the buffer object. It contains all the informations about
52 a document loaded into LyX. I am not sure if the class is complete or
53 minimal, probably not.
54 \author Lars Gullik Bjønnes
58 /// What type of log will \c getLogName() return?
60 latexlog, ///< LaTeX log
61 buildlog ///< Literate build log
66 \param b optional \c false by default
68 explicit Buffer(string const & file, bool b = false);
73 /** High-level interface to buffer functionality.
74 This function parses a command string and executes it
76 bool dispatch(string const & command, bool * result = 0);
78 /// Maybe we know the function already by number...
79 bool dispatch(int ac, string const & argument, bool * result = 0);
82 void resizeInsets(BufferView *);
84 /// Update window titles of all users.
85 void updateTitles() const;
87 /// Reset autosave timers for all users.
88 void resetAutosaveTimers() const;
90 /** Adds the BufferView to the users list.
91 Later this func will insert the \c BufferView into a real list,
92 not just setting a pointer.
94 void addUser(BufferView * u);
96 /** Removes the #BufferView# from the users list.
97 Since we only can have one at the moment, we just reset it.
99 void delUser(BufferView *);
104 /// Load the autosaved file.
105 void loadAutoSaveFile();
108 \param par if != 0 insert the file.
109 \return \c false if method fails.
111 bool readFile(LyXLex &, string const &, Paragraph * par = 0);
113 /** Reads a file without header.
114 \param par if != 0 insert the file.
115 \return \c false if file is not completely read.
117 bool readLyXformat2(LyXLex &, Paragraph * par = 0);
119 /// This parses a single LyXformat-Token.
120 bool parseSingleLyXformat2Token(LyXLex &, Paragraph *& par,
121 Paragraph *& return_par,
122 string const & token, int & pos,
123 Paragraph::depth_type & depth,
126 void insertStringAsLines(Paragraph *&, lyx::pos_type &,
127 LyXFont const &, string const &) const;
129 Paragraph * getParFromID(int id) const;
131 /// Parse a single inset.
132 void readInset(LyXLex &, Paragraph *& par, int & pos, LyXFont &);
135 Takes care of auto-save files and backup file if requested.
136 Returns \c true if the save is successful, \c false otherwise.
140 /// Write file. Returns \c false if unsuccesful.
141 bool writeFile(string const &) const;
144 void writeFileAscii(string const & , int);
146 void writeFileAscii(std::ostream &, int);
148 string const asciiParagraph(Paragraph const &, unsigned int linelen,
149 bool noparbreak = false) const;
150 /// Just a wrapper for the method below, first creating the ofstream.
151 void makeLaTeXFile(string const & filename,
152 string const & original_path,
154 bool only_body = false,
155 bool only_preamble = false);
157 void makeLaTeXFile(std::ostream & os,
158 string const & original_path,
160 bool only_body = false,
161 bool only_preamble = false);
162 /** LaTeX all paragraphs from par to endpar.
163 \param \a endpar if == 0 then to the end
165 void latexParagraphs(std::ostream & os, Paragraph * par,
166 Paragraph * endpar, TexRow & texrow, bool moving_arg = false) const;
168 void simpleDocBookOnePar(std::ostream &,
169 Paragraph * par, int & desc_on,
170 Paragraph::depth_type depth) const ;
172 void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par,
173 Paragraph::depth_type depth);
175 void makeLinuxDocFile(string const & filename,
176 bool nice, bool only_body = false);
178 void makeDocBookFile(string const & filename,
179 bool nice, bool only_body = false);
181 void sgmlError(Paragraph * par, int pos, string const & message) const;
183 /// returns the main language for the buffer (document)
184 Language const * getLanguage() const;
187 /// return true if the main lyx file does not need saving
188 bool isClean() const;
190 bool isBakClean() const;
192 bool isDepClean(string const & name) const;
194 /// mark the main lyx file as not needing saving
195 void markClean() const;
201 void markDepClean(string const & name);
204 void setUnnamed(bool flag = true);
209 /// Mark this buffer as dirty.
212 /// Returns the buffer's filename. It is always an absolute path.
213 string const & fileName() const;
215 /// Returns the the path where the buffer lives.
216 /// It is always an absolute path.
217 string const & filePath() const;
219 /** A transformed version of the file name, adequate for LaTeX.
220 \param no_path optional if \c true then the path is stripped.
222 string const getLatexName(bool no_path = true) const;
224 /// Get the name and type of the log.
225 std::pair<LogType, string> const getLogName() const;
227 /// Change name of buffer. Updates "read-only" flag.
228 void setFileName(string const & newfile);
230 /// Name of the document's parent
231 void setParentName(string const &);
233 /// Is buffer read-only?
234 bool isReadonly() const;
236 /// Set buffer read-only flag
237 void setReadonly(bool flag = true);
239 /// returns \c true if the buffer contains a LaTeX document
240 bool isLatex() const;
241 /// returns \c true if the buffer contains a LinuxDoc document
242 bool isLinuxDoc() const;
243 /// returns \c true if the buffer contains a DocBook document
244 bool isDocBook() const;
245 /** returns \c true if the buffer contains either a LinuxDoc
246 or DocBook document */
248 /// returns \c true if the buffer contains a Wed document
249 bool isLiterate() const;
251 /** Validate a buffer for LaTeX.
252 This validates the buffer, and returns a struct for use by
253 #makeLaTeX# and others. Its main use is to figure out what
254 commands and packages need to be included in the LaTeX file.
255 It (should) also check that the needed constructs are there
256 (i.e. that the \refs points to coresponding \labels). It
257 should perhaps inset "error" insets to help the user correct
260 void validate(LaTeXFeatures &) const;
263 std::vector<std::pair<string, string> > const getBibkeyList() const;
265 std::vector<string> const getLabelList() const;
267 /** This will clearly have to change later. Later we can have more
268 than one user per buffer. */
269 BufferView * getUser() const;
272 void changeLanguage(Language const * from, Language const * to);
274 bool isMultiLingual();
276 /// Does this mean that this is buffer local?
277 limited_stack<boost::shared_ptr<Undo> > undostack;
279 /// Does this mean that this is buffer local?
280 limited_stack<boost::shared_ptr<Undo> > redostack;
285 /** The list of paragraphs.
286 This is a linked list of paragraph, this list holds the
287 whole contents of the document.
289 ParagraphList paragraphs;
291 /// LyX version control object.
294 /// Where to put temporary files.
297 /** If we are writing a nice LaTeX file or not.
298 While writing as LaTeX, tells whether we are
299 doing a 'nice' LaTeX file */
302 /// Used when typesetting to place errorboxes.
306 mutable bool lyx_clean;
308 /// is autosave needed
309 mutable bool bak_clean;
311 /// is this a unnamed file (New...)
314 /// is regenerating #.tex# necessary
315 DEPCLEAN * dep_clean;
320 /// name of the file the buffer is associated with.
323 /// The path to the document file.
326 /// Format number of buffer
328 /** A list of views using this buffer.
329 Why not keep a list of the BufferViews that use this buffer?
331 At least then we don't have to do a lot of magic like:
332 #buffer->lyx_gui->bufferview->updateLayoutChoice#. Just ask each
333 of the buffers in the list of users to do a #updateLayoutChoice#.
338 class inset_iterator {
340 typedef std::input_iterator_tag iterator_category;
341 typedef Inset value_type;
342 typedef ptrdiff_t difference_type;
343 typedef Inset * pointer;
344 typedef Inset & reference;
345 typedef ParagraphList::iterator base_type;
350 inset_iterator(base_type p, base_type e);
352 inset_iterator(base_type p, lyx::pos_type pos, base_type e);
355 inset_iterator & operator++();
357 inset_iterator operator++(int);
359 reference operator*();
361 pointer operator->();
364 Paragraph * getPar();
366 lyx::pos_type getPos() const;
369 bool operator==(inset_iterator const & iter1,
370 inset_iterator const & iter2);
375 ParagraphList::iterator pit;
377 ParagraphList::iterator pend;
379 InsetList::iterator it;
383 inset_iterator inset_iterator_begin() {
384 return inset_iterator(paragraphs.begin(), paragraphs.end());
388 inset_iterator inset_iterator_end() {
389 return inset_iterator();
393 inset_iterator inset_const_iterator_begin() const {
394 return inset_iterator(paragraphs.begin(), paragraphs.end());
398 inset_iterator inset_const_iterator_end() const {
399 return inset_iterator();
403 ParIterator par_iterator_begin();
405 ParIterator par_iterator_end();
408 Inset * getInsetFromID(int id_arg) const;
411 bool operator==(Buffer::inset_iterator const & iter1,
412 Buffer::inset_iterator const & iter2);
414 bool operator!=(Buffer::inset_iterator const & iter1,
415 Buffer::inset_iterator const & iter2);