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.
15 #include "InsetList.h"
16 #include "ParagraphList_fwd.h"
18 #include "support/limited_stack.h"
19 #include "support/types.h"
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/signals/signal0.hpp>
23 #include <boost/signals/signal1.hpp>
45 class ParConstIterator;
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
59 /// What type of log will \c getLogName() return?
61 latexlog, ///< LaTeX log
62 buildlog ///< Literate build log
67 \param b optional \c false by default
69 explicit Buffer(std::string const & file, bool b = false);
74 /** High-level interface to buffer functionality.
75 This function parses a command string and executes it
77 bool dispatch(std::string const & command, bool * result = 0);
79 /// Maybe we know the function already by number...
80 bool dispatch(FuncRequest const & func, bool * result = 0);
82 /// Load the autosaved file.
83 void loadAutoSaveFile();
86 bool readFile(std::string const & filename);
88 bool readFile(std::string const & filename, ParagraphList::iterator pit);
90 /// read the header, returns number of unknown tokens
91 int readHeader(LyXLex & lex);
93 /** Reads a file without header.
94 \param par if != 0 insert the file.
95 \return \c false if file is not completely read.
97 bool readBody(LyXLex &);
100 void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
101 LyXFont const &, std::string const &);
103 ParIterator getParFromID(int id) const;
104 /// do we have a paragraph with this id?
105 bool hasParWithID(int id) const;
107 /// This signal is emitted when a parsing error shows up.
108 boost::signal1<void, ErrorItem> error;
109 /// This signal is emitted when some message shows up.
110 boost::signal1<void, std::string> message;
111 /// This signal is emitted when the buffer busy status change.
112 boost::signal1<void, bool> busy;
113 /// This signal is emitted when the buffer readonly status change.
114 boost::signal1<void, bool> readonly;
115 /// Update window titles of all users.
116 boost::signal0<void> updateTitles;
117 /// Reset autosave timers for all users.
118 boost::signal0<void> resetAutosaveTimers;
119 /// This signal is emitting if the buffer is being closed.
120 boost::signal0<void> closing;
124 Takes care of auto-save files and backup file if requested.
125 Returns \c true if the save is successful, \c false otherwise.
129 /// Write file. Returns \c false if unsuccesful.
130 bool writeFile(std::string const &) const;
133 void writeFileAscii(std::string const &, OutputParams const &);
135 void writeFileAscii(std::ostream &, OutputParams const &);
136 /// Just a wrapper for the method below, first creating the ofstream.
137 void makeLaTeXFile(std::string const & filename,
138 std::string const & original_path,
139 OutputParams const &,
140 bool output_preamble = true,
141 bool output_body = true);
143 void makeLaTeXFile(std::ostream & os,
144 std::string const & original_path,
145 OutputParams const &,
146 bool output_preamble = true,
147 bool output_body = true);
149 void makeLinuxDocFile(std::string const & filename,
150 OutputParams const & runparams_in,
151 bool only_body = false);
153 void makeDocBookFile(std::string const & filename,
154 OutputParams const & runparams_in,
155 bool only_body = false);
156 /// returns the main language for the buffer (document)
157 Language const * getLanguage() const;
158 /// get l10n translated to the buffers language
159 std::string const B_(std::string const & l10n) const;
163 /// return true if the main lyx file does not need saving
164 bool isClean() const;
166 bool isBakClean() const;
168 bool isDepClean(std::string const & name) const;
170 /// mark the main lyx file as not needing saving
171 void markClean() const;
177 void markDepClean(std::string const & name);
180 void setUnnamed(bool flag = true);
185 /// Mark this buffer as dirty.
188 /// Returns the buffer's filename. It is always an absolute path.
189 std::string const & fileName() const;
191 /// Returns the the path where the buffer lives.
192 /// It is always an absolute path.
193 std::string const & filePath() const;
195 /** A transformed version of the file name, adequate for LaTeX.
196 \param no_path optional if \c true then the path is stripped.
198 std::string const getLatexName(bool no_path = true) const;
200 /// Get the name and type of the log.
201 std::pair<LogType, std::string> const getLogName() const;
203 /// Change name of buffer. Updates "read-only" flag.
204 void setFileName(std::string const & newfile);
206 /// Name of the document's parent
207 void setParentName(std::string const &);
209 /// Is buffer read-only?
210 bool isReadonly() const;
212 /// Set buffer read-only flag
213 void setReadonly(bool flag = true);
215 /// returns \c true if the buffer contains a LaTeX document
216 bool isLatex() const;
217 /// returns \c true if the buffer contains a LinuxDoc document
218 bool isLinuxDoc() const;
219 /// returns \c true if the buffer contains a DocBook document
220 bool isDocBook() const;
221 /** returns \c true if the buffer contains either a LinuxDoc
222 or DocBook document */
224 /// returns \c true if the buffer contains a Wed document
225 bool isLiterate() const;
227 /** Validate a buffer for LaTeX.
228 This validates the buffer, and returns a struct for use by
229 #makeLaTeX# and others. Its main use is to figure out what
230 commands and packages need to be included in the LaTeX file.
231 It (should) also check that the needed constructs are there
232 (i.e. that the \refs points to coresponding \labels). It
233 should perhaps inset "error" insets to help the user correct
236 void validate(LaTeXFeatures &) const;
238 /// return all bibkeys from buffer and its childs
239 void fillWithBibKeys(std::vector<std::pair<std::string, std::string> > & keys) const;
241 void getLabelList(std::vector<std::string> &) const;
244 void changeLanguage(Language const * from, Language const * to);
247 void updateDocLang(Language const * nlang);
250 bool isMultiLingual();
252 /// Does this mean that this is buffer local?
253 limited_stack<Undo> & undostack();
254 limited_stack<Undo> const & undostack() const;
256 /// Does this mean that this is buffer local?
257 limited_stack<Undo> & redostack();
258 limited_stack<Undo> const & redostack() const;
261 BufferParams & params();
262 BufferParams const & params() const;
264 /** The list of paragraphs.
265 This is a linked list of paragraph, this list holds the
266 whole contents of the document.
268 ParagraphList & paragraphs();
269 ParagraphList const & paragraphs() const;
271 /// LyX version control object.
273 LyXVC const & lyxvc() const;
275 /// Where to put temporary files.
276 std::string const & temppath() const;
278 /** If we are writing a nice LaTeX file or not.
279 While writing as LaTeX, tells whether we are
280 doing a 'nice' LaTeX file */
282 bool niceFile() const;
284 /// Used when typesetting to place errorboxes.
286 TexRow const & texrow() const;
288 class inset_iterator {
290 typedef std::input_iterator_tag iterator_category;
291 typedef InsetOld value_type;
292 typedef ptrdiff_t difference_type;
293 typedef InsetOld * pointer;
294 typedef InsetOld & reference;
295 typedef ParagraphList::iterator base_type;
300 inset_iterator(base_type p, base_type e);
302 inset_iterator(base_type p, lyx::pos_type pos, base_type e);
305 inset_iterator & operator++();
307 inset_iterator operator++(int);
309 reference operator*();
311 pointer operator->();
314 ParagraphList::iterator getPar() const;
316 lyx::pos_type getPos() const;
319 bool operator==(inset_iterator const & iter1,
320 inset_iterator const & iter2);
325 ParagraphList::iterator pit;
327 ParagraphList::iterator pend;
329 InsetList::iterator it;
332 /// return an iterator to all *top-level* insets in the buffer
333 inset_iterator inset_iterator_begin();
335 /// return the end of all *top-level* insets in the buffer
336 inset_iterator inset_iterator_end();
338 /// return a const iterator to all *top-level* insets in the buffer
339 inset_iterator inset_const_iterator_begin() const;
341 /// return the const end of all *top-level* insets in the buffer
342 inset_iterator inset_const_iterator_end() const;
345 PosIterator pos_iterator_begin();
347 PosIterator pos_iterator_end();
349 ParIterator par_iterator_begin();
351 ParConstIterator par_iterator_begin() const;
353 ParIterator par_iterator_end();
355 ParConstIterator par_iterator_end() const;
357 /** \returns true only when the file is fully loaded.
358 * Used to prevent the premature generation of previews
359 * and by the citation inset.
361 bool fully_loaded() const;
362 /// Set by buffer_funcs' newFile.
363 void fully_loaded(bool);
366 LyXText & text() const;
369 /** Inserts a file into a document
370 \param par if != 0 insert the file.
371 \return \c false if method fails.
373 bool readFile(LyXLex &, std::string const & filename,
374 ParagraphList::iterator pit);
376 bool do_writeFile(std::ostream & ofs) const;
378 /// Use the Pimpl idiom to hide the internals.
380 /// The pointer never changes although *pimpl_'s contents may.
381 boost::scoped_ptr<Impl> const pimpl_;
384 bool operator==(Buffer::inset_iterator const & iter1,
385 Buffer::inset_iterator const & iter2);
387 bool operator!=(Buffer::inset_iterator const & iter1,
388 Buffer::inset_iterator const & iter2);