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"
31 #include <boost/shared_ptr.hpp>
39 class ParConstIterator;
52 /** The buffer object.
53 This is the buffer object. It contains all the informations about
54 a document loaded into LyX. I am not sure if the class is complete or
55 minimal, probably not.
56 \author Lars Gullik Bjønnes
60 /// What type of log will \c getLogName() return?
62 latexlog, ///< LaTeX log
63 buildlog ///< Literate build log
68 \param b optional \c false by default
70 explicit Buffer(string const & file, bool b = false);
75 /** High-level interface to buffer functionality.
76 This function parses a command string and executes it
78 bool dispatch(string const & command, bool * result = 0);
80 /// Maybe we know the function already by number...
81 bool dispatch(int ac, string const & argument, bool * result = 0);
84 void resizeInsets(BufferView *);
86 /// Update window titles of all users.
87 void updateTitles() const;
89 /// Reset autosave timers for all users.
90 void resetAutosaveTimers() const;
92 /** Adds the BufferView to the users list.
93 Later this func will insert the \c BufferView into a real list,
94 not just setting a pointer.
96 void addUser(BufferView * u);
98 /** Removes the #BufferView# from the users list.
99 Since we only can have one at the moment, we just reset it.
101 void delUser(BufferView *);
106 /// Load the autosaved file.
107 void loadAutoSaveFile();
110 \param par if != 0 insert the file.
111 \return \c false if method fails.
113 bool readFile(LyXLex &, string const &, Paragraph * par = 0);
115 /** Reads a file without header.
116 \param par if != 0 insert the file.
117 \return \c false if file is not completely read.
119 bool readLyXformat2(LyXLex &, Paragraph * par = 0);
121 /// This parses a single LyXformat-Token.
122 bool parseSingleLyXformat2Token(LyXLex &, Paragraph *& par,
123 Paragraph *& return_par,
124 string const & token, int & pos,
125 Paragraph::depth_type & depth,
128 void insertStringAsLines(Paragraph *&, lyx::pos_type &,
129 LyXFont const &, string const &) const;
131 Paragraph * getParFromID(int id) const;
133 /// Parse a single inset.
134 void readInset(LyXLex &, Paragraph *& par, int & pos, LyXFont &);
137 Takes care of auto-save files and backup file if requested.
138 Returns \c true if the save is successful, \c false otherwise.
142 /// Write file. Returns \c false if unsuccesful.
143 bool writeFile(string const &) const;
146 void writeFileAscii(string const & , int);
148 void writeFileAscii(std::ostream &, int);
150 string const asciiParagraph(Paragraph const &, unsigned int linelen,
151 bool noparbreak = false) const;
152 /// Just a wrapper for the method below, first creating the ofstream.
153 void makeLaTeXFile(string const & filename,
154 string const & original_path,
156 bool only_body = false,
157 bool only_preamble = false);
159 void makeLaTeXFile(std::ostream & os,
160 string const & original_path,
162 bool only_body = false,
163 bool only_preamble = false);
164 /** LaTeX all paragraphs from par to endpar.
165 \param \a endpar if == 0 then to the end
167 void latexParagraphs(std::ostream & os, Paragraph * par,
168 Paragraph * endpar, TexRow & texrow, bool moving_arg = false) const;
170 void simpleDocBookOnePar(std::ostream &,
171 Paragraph * par, int & desc_on,
172 Paragraph::depth_type depth) const ;
174 void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par,
175 Paragraph::depth_type depth);
177 void makeLinuxDocFile(string const & filename,
178 bool nice, bool only_body = false);
180 void makeDocBookFile(string const & filename,
181 bool nice, bool only_body = false);
183 void sgmlError(Paragraph * par, int pos, string const & message) const;
185 /// returns the main language for the buffer (document)
186 Language const * getLanguage() const;
189 /// return true if the main lyx file does not need saving
190 bool isClean() const;
192 bool isBakClean() const;
194 bool isDepClean(string const & name) const;
196 /// mark the main lyx file as not needing saving
197 void markClean() const;
203 void markDepClean(string const & name);
206 void setUnnamed(bool flag = true);
211 /// Mark this buffer as dirty.
214 /// Returns the buffer's filename. It is always an absolute path.
215 string const & fileName() const;
217 /// Returns the the path where the buffer lives.
218 /// It is always an absolute path.
219 string const & filePath() const;
221 /** A transformed version of the file name, adequate for LaTeX.
222 \param no_path optional if \c true then the path is stripped.
224 string const getLatexName(bool no_path = true) const;
226 /// Get the name and type of the log.
227 std::pair<LogType, string> const getLogName() const;
229 /// Change name of buffer. Updates "read-only" flag.
230 void setFileName(string const & newfile);
232 /// Name of the document's parent
233 void setParentName(string const &);
235 /// Is buffer read-only?
236 bool isReadonly() const;
238 /// Set buffer read-only flag
239 void setReadonly(bool flag = true);
241 /// returns \c true if the buffer contains a LaTeX document
242 bool isLatex() const;
243 /// returns \c true if the buffer contains a LinuxDoc document
244 bool isLinuxDoc() const;
245 /// returns \c true if the buffer contains a DocBook document
246 bool isDocBook() const;
247 /** returns \c true if the buffer contains either a LinuxDoc
248 or DocBook document */
250 /// returns \c true if the buffer contains a Wed document
251 bool isLiterate() const;
253 /** Validate a buffer for LaTeX.
254 This validates the buffer, and returns a struct for use by
255 #makeLaTeX# and others. Its main use is to figure out what
256 commands and packages need to be included in the LaTeX file.
257 It (should) also check that the needed constructs are there
258 (i.e. that the \refs points to coresponding \labels). It
259 should perhaps inset "error" insets to help the user correct
262 void validate(LaTeXFeatures &) const;
265 std::vector<std::pair<string, string> > const getBibkeyList() const;
267 std::vector<string> const getLabelList() const;
269 /** This will clearly have to change later. Later we can have more
270 than one user per buffer. */
271 BufferView * getUser() const;
274 void changeLanguage(Language const * from, Language const * to);
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();
312 AuthorList authorlist;
315 mutable bool lyx_clean;
317 /// is autosave needed
318 mutable bool bak_clean;
320 /// is this a unnamed file (New...)
323 /// is regenerating #.tex# necessary
324 DEPCLEAN * dep_clean;
329 /// name of the file the buffer is associated with.
332 /// The path to the document file.
335 /// Format number of buffer
337 /** A list of views using this buffer.
338 Why not keep a list of the BufferViews that use this buffer?
340 At least then we don't have to do a lot of magic like:
341 #buffer->lyx_gui->bufferview->updateLayoutChoice#. Just ask each
342 of the buffers in the list of users to do a #updateLayoutChoice#.
347 class inset_iterator {
349 typedef std::input_iterator_tag iterator_category;
350 typedef Inset value_type;
351 typedef ptrdiff_t difference_type;
352 typedef Inset * pointer;
353 typedef Inset & reference;
354 typedef ParagraphList::iterator base_type;
359 inset_iterator(base_type p, base_type e);
361 inset_iterator(base_type p, lyx::pos_type pos, base_type e);
364 inset_iterator & operator++();
366 inset_iterator operator++(int);
368 reference operator*();
370 pointer operator->();
373 Paragraph * getPar();
375 lyx::pos_type getPos() const;
378 bool operator==(inset_iterator const & iter1,
379 inset_iterator const & iter2);
384 ParagraphList::iterator pit;
386 ParagraphList::iterator pend;
388 InsetList::iterator it;
392 inset_iterator inset_iterator_begin() {
393 return inset_iterator(paragraphs.begin(), paragraphs.end());
397 inset_iterator inset_iterator_end() {
398 return inset_iterator();
402 inset_iterator inset_const_iterator_begin() const {
403 return inset_iterator(paragraphs.begin(), paragraphs.end());
407 inset_iterator inset_const_iterator_end() const {
408 return inset_iterator();
412 ParIterator par_iterator_begin();
414 ParConstIterator par_iterator_begin() const;
416 ParIterator par_iterator_end();
418 ParConstIterator par_iterator_end() const;
421 Inset * getInsetFromID(int id_arg) const;
424 bool operator==(Buffer::inset_iterator const & iter1,
425 Buffer::inset_iterator const & iter2);
427 bool operator!=(Buffer::inset_iterator const & iter1,
428 Buffer::inset_iterator const & iter2);