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 &, ParagraphList::iterator pit);
99 /// This parses a single token
100 int readParagraph(LyXLex &, std::string const & token,
101 ParagraphList & pars,
102 ParagraphList::iterator & pit,
103 lyx::depth_type & depth);
106 void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
107 LyXFont const &, std::string const &);
109 ParIterator getParFromID(int id) const;
110 /// do we have a paragraph with this id?
111 bool hasParWithID(int id) const;
113 /// This signal is emitted when a parsing error shows up.
114 boost::signal1<void, ErrorItem> error;
115 /// This signal is emitted when some message shows up.
116 boost::signal1<void, std::string> message;
117 /// This signal is emitted when the buffer busy status change.
118 boost::signal1<void, bool> busy;
119 /// This signal is emitted when the buffer readonly status change.
120 boost::signal1<void, bool> readonly;
121 /// Update window titles of all users.
122 boost::signal0<void> updateTitles;
123 /// Reset autosave timers for all users.
124 boost::signal0<void> resetAutosaveTimers;
125 /// This signal is emitting if the buffer is being closed.
126 boost::signal0<void> closing;
130 Takes care of auto-save files and backup file if requested.
131 Returns \c true if the save is successful, \c false otherwise.
135 /// Write file. Returns \c false if unsuccesful.
136 bool writeFile(std::string const &) const;
139 void writeFileAscii(std::string const &, OutputParams const &);
141 void writeFileAscii(std::ostream &, OutputParams const &);
142 /// Just a wrapper for the method below, first creating the ofstream.
143 void makeLaTeXFile(std::string const & filename,
144 std::string const & original_path,
145 OutputParams const &,
146 bool output_preamble = true,
147 bool output_body = true);
149 void makeLaTeXFile(std::ostream & os,
150 std::string const & original_path,
151 OutputParams const &,
152 bool output_preamble = true,
153 bool output_body = true);
155 void makeLinuxDocFile(std::string const & filename,
156 OutputParams const & runparams_in,
157 bool only_body = false);
159 void makeDocBookFile(std::string const & filename,
160 OutputParams const & runparams_in,
161 bool only_body = false);
162 /// returns the main language for the buffer (document)
163 Language const * getLanguage() const;
164 /// get l10n translated to the buffers language
165 std::string const B_(std::string const & l10n) const;
169 /// return true if the main lyx file does not need saving
170 bool isClean() const;
172 bool isBakClean() const;
174 bool isDepClean(std::string const & name) const;
176 /// mark the main lyx file as not needing saving
177 void markClean() const;
183 void markDepClean(std::string const & name);
186 void setUnnamed(bool flag = true);
191 /// Mark this buffer as dirty.
194 /// Returns the buffer's filename. It is always an absolute path.
195 std::string const & fileName() const;
197 /// Returns the the path where the buffer lives.
198 /// It is always an absolute path.
199 std::string const & filePath() const;
201 /** A transformed version of the file name, adequate for LaTeX.
202 \param no_path optional if \c true then the path is stripped.
204 std::string const getLatexName(bool no_path = true) const;
206 /// Get the name and type of the log.
207 std::pair<LogType, std::string> const getLogName() const;
209 /// Change name of buffer. Updates "read-only" flag.
210 void setFileName(std::string const & newfile);
212 /// Name of the document's parent
213 void setParentName(std::string const &);
215 /// Is buffer read-only?
216 bool isReadonly() const;
218 /// Set buffer read-only flag
219 void setReadonly(bool flag = true);
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 */
230 /// returns \c true if the buffer contains a Wed document
231 bool isLiterate() const;
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
242 void validate(LaTeXFeatures &) const;
244 /// return all bibkeys from buffer and its childs
245 void fillWithBibKeys(std::vector<std::pair<std::string, std::string> > & keys) const;
247 void getLabelList(std::vector<std::string> &) const;
250 void changeLanguage(Language const * from, Language const * to);
253 void updateDocLang(Language const * nlang);
256 bool isMultiLingual();
258 /// Does this mean that this is buffer local?
259 limited_stack<Undo> & undostack();
260 limited_stack<Undo> const & undostack() const;
262 /// Does this mean that this is buffer local?
263 limited_stack<Undo> & redostack();
264 limited_stack<Undo> const & redostack() const;
267 BufferParams & params();
268 BufferParams const & params() const;
270 /** The list of paragraphs.
271 This is a linked list of paragraph, this list holds the
272 whole contents of the document.
274 ParagraphList & paragraphs();
275 ParagraphList const & paragraphs() const;
277 /// LyX version control object.
279 LyXVC const & lyxvc() const;
281 /// Where to put temporary files.
282 std::string const & temppath() const;
284 /** If we are writing a nice LaTeX file or not.
285 While writing as LaTeX, tells whether we are
286 doing a 'nice' LaTeX file */
288 bool niceFile() const;
290 /// Used when typesetting to place errorboxes.
292 TexRow const & texrow() const;
294 class inset_iterator {
296 typedef std::input_iterator_tag iterator_category;
297 typedef InsetOld value_type;
298 typedef ptrdiff_t difference_type;
299 typedef InsetOld * pointer;
300 typedef InsetOld & reference;
301 typedef ParagraphList::iterator base_type;
306 inset_iterator(base_type p, base_type e);
308 inset_iterator(base_type p, lyx::pos_type pos, base_type e);
311 inset_iterator & operator++();
313 inset_iterator operator++(int);
315 reference operator*();
317 pointer operator->();
320 ParagraphList::iterator getPar() const;
322 lyx::pos_type getPos() const;
325 bool operator==(inset_iterator const & iter1,
326 inset_iterator const & iter2);
331 ParagraphList::iterator pit;
333 ParagraphList::iterator pend;
335 InsetList::iterator it;
338 /// return an iterator to all *top-level* insets in the buffer
339 inset_iterator inset_iterator_begin();
341 /// return the end of all *top-level* insets in the buffer
342 inset_iterator inset_iterator_end();
344 /// return a const iterator to all *top-level* insets in the buffer
345 inset_iterator inset_const_iterator_begin() const;
347 /// return the const end of all *top-level* insets in the buffer
348 inset_iterator inset_const_iterator_end() const;
351 PosIterator pos_iterator_begin();
353 PosIterator pos_iterator_end();
355 ParIterator par_iterator_begin();
357 ParConstIterator par_iterator_begin() const;
359 ParIterator par_iterator_end();
361 ParConstIterator par_iterator_end() const;
363 /** \returns true only when the file is fully loaded.
364 * Used to prevent the premature generation of previews
365 * and by the citation inset.
367 bool fully_loaded() const;
368 /// Set by buffer_funcs' newFile.
369 void fully_loaded(bool);
372 LyXText & text() const;
375 /** Inserts a file into a document
376 \param par if != 0 insert the file.
377 \return \c false if method fails.
379 bool readFile(LyXLex &, std::string const & filename,
380 ParagraphList::iterator pit);
382 bool do_writeFile(std::ostream & ofs) const;
384 /// Use the Pimpl idiom to hide the internals.
386 /// The pointer never changes although *pimpl_'s contents may.
387 boost::scoped_ptr<Impl> const pimpl_;
390 bool operator==(Buffer::inset_iterator const & iter1,
391 Buffer::inset_iterator const & iter2);
393 bool operator!=(Buffer::inset_iterator const & iter1,
394 Buffer::inset_iterator const & iter2);