]> git.lyx.org Git - lyx.git/blob - src/buffer.h
Remove unused declarations of writeFileAscii
[lyx.git] / src / buffer.h
1 // -*- C++ -*-
2 /**
3  * \file buffer.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BUFFER_H
13 #define BUFFER_H
14
15 #include "errorlist.h"
16 #include "InsetList.h"
17
18 #include "dociterator.h"
19 #include "ParagraphList_fwd.h"
20
21 #include "support/limited_stack.h"
22 #include "support/types.h"
23 #include "support/docstring.h"
24
25 #include <boost/scoped_ptr.hpp>
26 #include <boost/signal.hpp>
27
28 #include <iosfwd>
29 #include <string>
30 #include <map>
31 #include <utility>
32 #include <vector>
33
34
35 class BufferParams;
36 class ErrorItem;
37 class FuncRequest;
38 class InsetBase;
39 class InsetText;
40 class LyXFont;
41 class LyXLex;
42 class LyXRC;
43 class LyXText;
44 class LyXVC;
45 class LaTeXFeatures;
46 class Language;
47 class MacroData;
48 class OutputParams;
49 class ParConstIterator;
50 class ParIterator;
51 class TeXErrors;
52 class TexRow;
53 class Undo;
54 class StableDocIterator;
55
56
57 /** The buffer object.
58  * This is the buffer object. It contains all the informations about
59  * a document loaded into LyX.
60  * The buffer object owns the LyXText (wrapped in an InsetText), which
61  * contains the individual paragraphs of the document.
62  *
63  *
64  * I am not sure if the class is complete or
65  * minimal, probably not.
66  * \author Lars Gullik Bjønnes
67   */
68 class Buffer {
69 public:
70         /// What type of log will \c getLogName() return?
71         enum LogType {
72                 latexlog, ///< LaTeX log
73                 buildlog  ///< Literate build log
74         };
75
76         /** Constructor
77             \param file
78             \param b  optional \c false by default
79         */
80         explicit Buffer(std::string const & file, bool b = false);
81
82         /// Destructor
83         ~Buffer();
84
85         /** High-level interface to buffer functionality.
86             This function parses a command string and executes it
87         */
88         bool dispatch(std::string const & command, bool * result = 0);
89
90         /// Maybe we know the function already by number...
91         bool dispatch(FuncRequest const & func, bool * result = 0);
92
93         /// Load the autosaved file.
94         void loadAutoSaveFile();
95
96         /// load a new file
97         bool readFile(std::string const & filename);
98
99         /// read the header, returns number of unknown tokens
100         int readHeader(LyXLex & lex);
101
102         /** Reads a file without header.
103             \param par if != 0 insert the file.
104             \return \c false if file is not completely read.
105         */
106         bool readDocument(LyXLex &);
107
108         ///
109         void insertStringAsLines(ParagraphList & plist,
110                 lyx::pit_type &, lyx::pos_type &,
111                 LyXFont const &, lyx::docstring const &, bool);
112         ///
113         ParIterator getParFromID(int id) const;
114         /// do we have a paragraph with this id?
115         bool hasParWithID(int id) const;
116
117         /// This signal is emitted when some parsing error shows up.
118         boost::signal<void(std::string)> errors;
119         /// This signal is emitted when some message shows up.
120         boost::signal<void(lyx::docstring)> message;
121         /// This signal is emitted when the buffer busy status change.
122         boost::signal<void(bool)> busy;
123         /// This signal is emitted when the buffer readonly status change.
124         boost::signal<void(bool)> readonly;
125         /// Update window titles of all users.
126         boost::signal<void()> updateTitles;
127         /// Reset autosave timers for all users.
128         boost::signal<void()> resetAutosaveTimers;
129         /// This signal is emitting if the buffer is being closed.
130         boost::signal<void()> closing;
131
132
133         /** Save file.
134             Takes care of auto-save files and backup file if requested.
135             Returns \c true if the save is successful, \c false otherwise.
136         */
137         bool save() const;
138
139         /// Write file. Returns \c false if unsuccesful.
140         bool writeFile(std::string const &) const;
141
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);
148         ///
149         void writeLaTeXSource(std::ostream & os,
150                            std::string const & original_path,
151                            OutputParams const &,
152                            bool output_preamble = true,
153                            bool output_body = true);
154         ///
155         void makeDocBookFile(std::string const & filename,
156                              OutputParams const & runparams_in,
157                              bool only_body = false);
158         ///
159         void writeDocBookSource(std::ostream & os, 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         lyx::docstring const B_(std::string const & l10n) const;
166
167         ///
168         int runChktex();
169         /// return true if the main lyx file does not need saving
170         bool isClean() const;
171         ///
172         bool isBakClean() const;
173         ///
174         bool isDepClean(std::string const & name) const;
175
176         /// mark the main lyx file as not needing saving
177         void markClean() const;
178
179         ///
180         void markBakClean();
181
182         ///
183         void markDepClean(std::string const & name);
184
185         ///
186         void setUnnamed(bool flag = true);
187
188         ///
189         bool isUnnamed() const;
190
191         /// Mark this buffer as dirty.
192         void markDirty();
193
194         /// Returns the buffer's filename. It is always an absolute path.
195         std::string const & fileName() const;
196
197         /// Returns the the path where the buffer lives.
198         /// It is always an absolute path.
199         std::string const & filePath() const;
200
201         /** A transformed version of the file name, adequate for LaTeX.
202             \param no_path optional if \c true then the path is stripped.
203         */
204         std::string const getLatexName(bool no_path = true) const;
205
206         /// Get the name and type of the log.
207         std::pair<LogType, std::string> const getLogName() const;
208
209         /// Change name of buffer. Updates "read-only" flag.
210         void setFileName(std::string const & newfile);
211
212         /// Name of the document's parent
213         void setParentName(std::string const &);
214
215         /** Get the document's master (or \c this if this is not a
216             child document)
217          */
218         Buffer const * getMasterBuffer() const;
219         /** Get the document's master (or \c this if this is not a
220             child document)
221          */
222         Buffer * getMasterBuffer();
223
224         /// Is buffer read-only?
225         bool isReadonly() const;
226
227         /// Set buffer read-only flag
228         void setReadonly(bool flag = true);
229
230         /// returns \c true if the buffer contains a LaTeX document
231         bool isLatex() const;
232         /// returns \c true if the buffer contains a DocBook document
233         bool isDocBook() const;
234         /// returns \c true if the buffer contains a Wed document
235         bool isLiterate() const;
236
237         /** Validate a buffer for LaTeX.
238             This validates the buffer, and returns a struct for use by
239             #makeLaTeX# and others. Its main use is to figure out what
240             commands and packages need to be included in the LaTeX file.
241             It (should) also check that the needed constructs are there
242             (i.e. that the \refs points to coresponding \labels). It
243             should perhaps inset "error" insets to help the user correct
244             obvious mistakes.
245         */
246         void validate(LaTeXFeatures &) const;
247
248         /// return all bibkeys from buffer and its childs
249         void fillWithBibKeys(std::vector<std::pair<std::string, std::string> > & keys) const;
250         /// Update the cache with all bibfiles in use (including bibfiles
251         /// of loaded child documents).
252         void updateBibfilesCache();
253         /// Return the cache with all bibfiles in use (including bibfiles
254         /// of loaded child documents).
255         std::vector<std::string> const & getBibfilesCache() const;
256         ///
257         void getLabelList(std::vector<std::string> &) const;
258
259         ///
260         void changeLanguage(Language const * from, Language const * to);
261
262         ///
263         void updateDocLang(Language const * nlang);
264
265         ///
266         bool isMultiLingual() const;
267
268         /// Does this mean that this is buffer local?
269         limited_stack<Undo> & undostack();
270         limited_stack<Undo> const & undostack() const;
271
272         /// Does this mean that this is buffer local?
273         limited_stack<Undo> & redostack();
274         limited_stack<Undo> const & redostack() const;
275
276         ///
277         BufferParams & params();
278         BufferParams const & params() const;
279
280         /** The list of paragraphs.
281             This is a linked list of paragraph, this list holds the
282             whole contents of the document.
283          */
284         ParagraphList & paragraphs();
285         ParagraphList const & paragraphs() const;
286
287         /// LyX version control object.
288         LyXVC & lyxvc();
289         LyXVC const & lyxvc() const;
290
291         /// Where to put temporary files.
292         std::string const & temppath() const;
293
294         /// Used when typesetting to place errorboxes.
295         TexRow & texrow();
296         TexRow const & texrow() const;
297
298         ///
299         ParIterator par_iterator_begin();
300         ///
301         ParConstIterator par_iterator_begin() const;
302         ///
303         ParIterator par_iterator_end();
304         ///
305         ParConstIterator par_iterator_end() const;
306
307         /** \returns true only when the file is fully loaded.
308          *  Used to prevent the premature generation of previews
309          *  and by the citation inset.
310          */
311         bool fully_loaded() const;
312         /// Set by buffer_funcs' newFile.
313         void fully_loaded(bool);
314
315         /// Our main text (inside the top InsetText)
316         LyXText & text() const;
317
318         /// Our top InsetText!
319         InsetBase & inset() const;
320
321         //
322         // Macro handling
323         //
324         ///
325         void buildMacros();
326         ///
327         bool hasMacro(std::string const & name) const;
328         ///
329         MacroData const & getMacro(std::string const & name) const;
330         ///
331         void insertMacro(std::string const & name, MacroData const & data);
332         ///
333         void saveCursor(StableDocIterator cursor, StableDocIterator anchor);
334         ///
335         StableDocIterator getCursor() const { return cursor_; }
336         ///
337         StableDocIterator getAnchor() const { return anchor_; }
338         ///
339         void changeRefsIfUnique(std::string const & from, std::string const & to, InsetBase::Code code);
340         /// get source code (latex/docbook) for some paragraphs, or all paragraphs
341         /// including preamble
342         void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source);
343
344         /// errorLists_ accessors.
345         //@{
346         ErrorList const & errorList(std::string const & type) const;
347         ErrorList & errorList(std::string const & type);
348         //@}
349
350 private:
351         /** Inserts a file into a document
352             \return \c false if method fails.
353         */
354         bool readFile(LyXLex &, std::string const & filename);
355
356         bool do_writeFile(std::ostream & ofs) const;
357
358         /// Use the Pimpl idiom to hide the internals.
359         class Impl;
360         /// The pointer never changes although *pimpl_'s contents may.
361         boost::scoped_ptr<Impl> const pimpl_;
362
363         /// Save the cursor Position on Buffer switch
364         /// this would not be needed if every Buffer would have
365         /// it's BufferView, this should be FIXED in future.
366         StableDocIterator cursor_;
367         StableDocIterator anchor_;
368         /// A cache for the bibfiles (including bibfiles of loaded child
369         /// documents), needed for appropriate update of natbib labels.
370         std::vector<std::string> bibfilesCache_;
371
372         /// Container for all sort of Buffer dependant errors.
373         std::map<std::string, ErrorList> errorLists_;
374 };
375
376 #endif