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>
46 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(std::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(std::string const & command, bool * result = 0);
80 /// Maybe we know the function already by number...
81 bool dispatch(FuncRequest const & func, bool * result = 0);
83 /// Load the autosaved file.
84 void loadAutoSaveFile();
87 bool readFile(std::string const & filename);
89 bool readFile(std::string const & filename, ParagraphList::iterator pit);
91 /// read the header, returns number of unknown tokens
92 int readHeader(LyXLex & lex);
94 /** Reads a file without header.
95 \param par if != 0 insert the file.
96 \return \c false if file is not completely read.
98 bool readBody(LyXLex &);
101 void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
102 LyXFont const &, std::string const &);
104 ParIterator getParFromID(int id) const;
105 /// do we have a paragraph with this id?
106 bool hasParWithID(int id) const;
108 /// This signal is emitted when a parsing error shows up.
109 boost::signal1<void, ErrorItem> error;
110 /// This signal is emitted when some message shows up.
111 boost::signal1<void, std::string> message;
112 /// This signal is emitted when the buffer busy status change.
113 boost::signal1<void, bool> busy;
114 /// This signal is emitted when the buffer readonly status change.
115 boost::signal1<void, bool> readonly;
116 /// Update window titles of all users.
117 boost::signal0<void> updateTitles;
118 /// Reset autosave timers for all users.
119 boost::signal0<void> resetAutosaveTimers;
120 /// This signal is emitting if the buffer is being closed.
121 boost::signal0<void> closing;
125 Takes care of auto-save files and backup file if requested.
126 Returns \c true if the save is successful, \c false otherwise.
130 /// Write file. Returns \c false if unsuccesful.
131 bool writeFile(std::string const &) const;
134 void writeFileAscii(std::string const &, OutputParams const &);
136 void writeFileAscii(std::ostream &, OutputParams const &);
137 /// Just a wrapper for the method below, first creating the ofstream.
138 void makeLaTeXFile(std::string const & filename,
139 std::string const & original_path,
140 OutputParams const &,
141 bool output_preamble = true,
142 bool output_body = true);
144 void makeLaTeXFile(std::ostream & os,
145 std::string const & original_path,
146 OutputParams const &,
147 bool output_preamble = true,
148 bool output_body = true);
150 void makeLinuxDocFile(std::string const & filename,
151 OutputParams const & runparams_in,
152 bool only_body = false);
154 void makeDocBookFile(std::string const & filename,
155 OutputParams const & runparams_in,
156 bool only_body = false);
157 /// returns the main language for the buffer (document)
158 Language const * getLanguage() const;
159 /// get l10n translated to the buffers language
160 std::string const B_(std::string const & l10n) const;
164 /// return true if the main lyx file does not need saving
165 bool isClean() const;
167 bool isBakClean() const;
169 bool isDepClean(std::string const & name) const;
171 /// mark the main lyx file as not needing saving
172 void markClean() const;
178 void markDepClean(std::string const & name);
181 void setUnnamed(bool flag = true);
186 /// Mark this buffer as dirty.
189 /// Returns the buffer's filename. It is always an absolute path.
190 std::string const & fileName() const;
192 /// Returns the the path where the buffer lives.
193 /// It is always an absolute path.
194 std::string const & filePath() const;
196 /** A transformed version of the file name, adequate for LaTeX.
197 \param no_path optional if \c true then the path is stripped.
199 std::string const getLatexName(bool no_path = true) const;
201 /// Get the name and type of the log.
202 std::pair<LogType, std::string> const getLogName() const;
204 /// Change name of buffer. Updates "read-only" flag.
205 void setFileName(std::string const & newfile);
207 /// Name of the document's parent
208 void setParentName(std::string const &);
210 /// Is buffer read-only?
211 bool isReadonly() const;
213 /// Set buffer read-only flag
214 void setReadonly(bool flag = true);
216 /// returns \c true if the buffer contains a LaTeX document
217 bool isLatex() const;
218 /// returns \c true if the buffer contains a LinuxDoc document
219 bool isLinuxDoc() const;
220 /// returns \c true if the buffer contains a DocBook document
221 bool isDocBook() const;
222 /** returns \c true if the buffer contains either a LinuxDoc
223 or DocBook document */
225 /// returns \c true if the buffer contains a Wed document
226 bool isLiterate() const;
228 /** Validate a buffer for LaTeX.
229 This validates the buffer, and returns a struct for use by
230 #makeLaTeX# and others. Its main use is to figure out what
231 commands and packages need to be included in the LaTeX file.
232 It (should) also check that the needed constructs are there
233 (i.e. that the \refs points to coresponding \labels). It
234 should perhaps inset "error" insets to help the user correct
237 void validate(LaTeXFeatures &) const;
239 /// return all bibkeys from buffer and its childs
240 void fillWithBibKeys(std::vector<std::pair<std::string, std::string> > & keys) const;
242 void getLabelList(std::vector<std::string> &) const;
245 void changeLanguage(Language const * from, Language const * to);
248 void updateDocLang(Language const * nlang);
251 bool isMultiLingual();
253 /// Does this mean that this is buffer local?
254 limited_stack<Undo> & undostack();
255 limited_stack<Undo> const & undostack() const;
257 /// Does this mean that this is buffer local?
258 limited_stack<Undo> & redostack();
259 limited_stack<Undo> const & redostack() const;
262 BufferParams & params();
263 BufferParams const & params() const;
265 /** The list of paragraphs.
266 This is a linked list of paragraph, this list holds the
267 whole contents of the document.
269 ParagraphList & paragraphs();
270 ParagraphList const & paragraphs() const;
272 /// LyX version control object.
274 LyXVC const & lyxvc() const;
276 /// Where to put temporary files.
277 std::string const & temppath() const;
279 /// Used when typesetting to place errorboxes.
281 TexRow const & texrow() const;
283 class inset_iterator {
285 typedef std::input_iterator_tag iterator_category;
286 typedef InsetBase value_type;
287 typedef ptrdiff_t difference_type;
288 typedef InsetBase * pointer;
289 typedef InsetBase & reference;
290 typedef ParagraphList::iterator base_type;
295 inset_iterator(base_type p, base_type e);
297 inset_iterator(base_type p, lyx::pos_type pos, base_type e);
300 inset_iterator & operator++();
302 inset_iterator operator++(int);
304 reference operator*();
306 pointer operator->();
309 ParagraphList::iterator getPar() const;
311 lyx::pos_type getPos() const;
314 bool operator==(inset_iterator const & iter1,
315 inset_iterator const & iter2);
320 ParagraphList::iterator pit;
322 ParagraphList::iterator pend;
324 InsetList::iterator it;
327 /// return an iterator to all *top-level* insets in the buffer
328 inset_iterator inset_iterator_begin();
330 /// return the end of all *top-level* insets in the buffer
331 inset_iterator inset_iterator_end();
333 /// return a const iterator to all *top-level* insets in the buffer
334 inset_iterator inset_const_iterator_begin() const;
336 /// return the const end of all *top-level* insets in the buffer
337 inset_iterator inset_const_iterator_end() const;
340 PosIterator pos_iterator_begin();
342 PosIterator pos_iterator_end();
344 ParIterator par_iterator_begin();
346 ParConstIterator par_iterator_begin() const;
348 ParIterator par_iterator_end();
350 ParConstIterator par_iterator_end() const;
352 /** \returns true only when the file is fully loaded.
353 * Used to prevent the premature generation of previews
354 * and by the citation inset.
356 bool fully_loaded() const;
357 /// Set by buffer_funcs' newFile.
358 void fully_loaded(bool);
361 LyXText & text() const;
364 /** Inserts a file into a document
365 \param par if != 0 insert the file.
366 \return \c false if method fails.
368 bool readFile(LyXLex &, std::string const & filename,
369 ParagraphList::iterator pit);
371 bool do_writeFile(std::ostream & ofs) const;
373 /// Use the Pimpl idiom to hide the internals.
375 /// The pointer never changes although *pimpl_'s contents may.
376 boost::scoped_ptr<Impl> const pimpl_;
379 bool operator==(Buffer::inset_iterator const & iter1,
380 Buffer::inset_iterator const & iter2);
382 bool operator!=(Buffer::inset_iterator const & iter1,
383 Buffer::inset_iterator const & iter2);