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"
17 #include "support/limited_stack.h"
18 #include "support/types.h"
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signal.hpp>
44 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, lyx::pit_type 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 readDocument(LyXLex &);
100 void insertStringAsLines(ParagraphList & plist,
101 lyx::pit_type &, lyx::pos_type &,
102 LyXFont const &, std::string const &, bool);
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::signal<void(ErrorItem)> error;
110 /// This signal is emitted when some message shows up.
111 boost::signal<void(std::string)> message;
112 /// This signal is emitted when the buffer busy status change.
113 boost::signal<void(bool)> busy;
114 /// This signal is emitted when the buffer readonly status change.
115 boost::signal<void(bool)> readonly;
116 /// Update window titles of all users.
117 boost::signal<void()> updateTitles;
118 /// Reset autosave timers for all users.
119 boost::signal<void()> resetAutosaveTimers;
120 /// This signal is emitting if the buffer is being closed.
121 boost::signal<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);
184 bool isUnnamed() const;
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 /** Get the document's master (or \c this if this is not a
213 Buffer const * getMasterBuffer() 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() const;
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 /// Used when typesetting to place errorboxes.
286 TexRow const & texrow() const;
289 ParIterator par_iterator_begin();
291 ParConstIterator par_iterator_begin() const;
293 ParIterator par_iterator_end();
295 ParConstIterator par_iterator_end() const;
297 /** \returns true only when the file is fully loaded.
298 * Used to prevent the premature generation of previews
299 * and by the citation inset.
301 bool fully_loaded() const;
302 /// Set by buffer_funcs' newFile.
303 void fully_loaded(bool);
306 LyXText & text() const;
308 InsetBase & inset() const;
316 bool hasMacro(std::string const & name) const;
318 MacroData const & getMacro(std::string const & name) const;
320 void insertMacro(std::string const & name, MacroData const & data);
323 /** Inserts a file into a document
324 \param par if != 0 insert the file.
325 \return \c false if method fails.
327 bool readFile(LyXLex &, std::string const & filename,
330 bool do_writeFile(std::ostream & ofs) const;
332 /// Use the Pimpl idiom to hide the internals.
334 /// The pointer never changes although *pimpl_'s contents may.
335 boost::scoped_ptr<Impl> const pimpl_;