]> git.lyx.org Git - lyx.git/blob - src/Buffer.h
Remove LyXToolBox
[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 "OutputEnums.h"
16
17 #include "support/unique_ptr.h"
18 #include "support/strfwd.h"
19 #include "support/types.h"
20
21 #include <map>
22 #include <list>
23 #include <set>
24 #include <string>
25 #include <vector>
26
27
28 namespace lyx {
29
30 class BiblioInfo;
31 class BibTeXInfo;
32 class BufferParams;
33 class DispatchResult;
34 class DocIterator;
35 class docstring_list;
36 class ErrorList;
37 class FuncRequest;
38 class FuncStatus;
39 class Inset;
40 class InsetLabel;
41 class InsetRef;
42 class Font;
43 class Format;
44 class Lexer;
45 class Text;
46 class LyXVC;
47 class LaTeXFeatures;
48 class Language;
49 class MacroData;
50 class MacroNameSet;
51 class MacroSet;
52 class OutputParams;
53 class otexstream;
54 class Paragraph;
55 class ParConstIterator;
56 class ParIterator;
57 class ParagraphList;
58 class TeXErrors;
59 class TexRow;
60 class TocBackend;
61 class Undo;
62 class WordLangTuple;
63
64 namespace frontend {
65 class GuiBufferDelegate;
66 class WorkAreaManager;
67 }
68
69 namespace support {
70 class DocFileName;
71 class FileName;
72 class FileNamePairList;
73 }
74
75 namespace graphics {
76 class PreviewLoader;
77 class Cache;
78 }
79
80
81 class Buffer;
82 typedef std::list<Buffer *> ListOfBuffers;
83 /// a list of Buffers we cloned
84 typedef std::set<Buffer *> CloneList;
85
86
87 /** The buffer object.
88  * This is the buffer object. It contains all the information about
89  * a document loaded into LyX.
90  * The buffer object owns the Text (wrapped in an InsetText), which
91  * contains the individual paragraphs of the document.
92  *
93  *
94  * I am not sure if the class is complete or
95  * minimal, probably not.
96  * \author Lars Gullik Bjønnes
97  */
98
99 class MarkAsExporting;
100
101 class Buffer {
102 public:
103         /// What type of log will \c getLogName() return?
104         enum LogType {
105                 latexlog, ///< LaTeX log
106                 buildlog  ///< Literate build log
107         };
108
109         /// Result of \c readFile()
110         enum ReadStatus {
111                 ReadSuccess,
112                 ReadCancel,
113                 // failures
114                 ReadFailure,
115                 ReadWrongVersion,
116                 ReadFileNotFound,
117                 ReadVCError,
118                 ReadAutosaveFailure,
119                 ReadEmergencyFailure,
120                 ReadNoLyXFormat,
121                 ReadDocumentFailure,
122                 // lyx2lyx
123                 LyX2LyXNoTempFile,
124                 LyX2LyXNotFound,
125                 LyX2LyXOlderFormat,
126                 LyX2LyXNewerFormat,
127                 // other
128                 ReadOriginal
129         };
130
131         enum ExportStatus {
132                 // export
133                 ExportSuccess,
134                 ExportCancel,
135                 ExportError,
136                 ExportNoPathToFormat,
137                 ExportTexPathHasSpaces,
138                 ExportConverterError,
139                 // preview
140                 // Implies ExportSuccess.
141                 PreviewSuccess,
142                 // The exported file exists but there was an error when opening
143                 // it in a viewer.
144                 PreviewError
145         };
146
147         /// Method to check if a file is externally modified, used by
148         /// isExternallyModified()
149         /**
150          * timestamp is fast but inaccurate. For example, the granularity
151          * of timestamp on a FAT filesystem is 2 seconds. Also, various operations
152          * may touch the timestamp of a file even when its content is unchanged.
153          *
154          * checksum is accurate but slow, which can be a problem when it is
155          * frequently used, or used for a large file on a slow (network) file
156          * system.
157          *
158          * FIXME: replace this method with support/FileMonitor.
159          */
160         enum CheckMethod {
161                 checksum_method, ///< Use file checksum
162                 timestamp_method ///< Use timestamp, and checksum if timestamp has changed
163         };
164
165         ///
166         enum UpdateScope {
167                 UpdateMaster,
168                 UpdateChildOnly
169         };
170
171         /// Constructor
172         explicit Buffer(std::string const & file, bool readonly = false,
173                 Buffer const * cloned_buffer = 0);
174
175         /// Destructor
176         ~Buffer();
177
178         /// Clones the entire structure of which this Buffer is part, starting
179         /// with the master and cloning all the children, too.
180         Buffer * cloneFromMaster() const;
181         /// Just clones this single Buffer. For autosave.
182         Buffer * cloneBufferOnly() const;
183         ///
184         bool isClone() const;
185
186         /** High-level interface to buffer functionality.
187             This function parses a command string and executes it.
188         */
189         void dispatch(std::string const & command, DispatchResult & result);
190
191         /// Maybe we know the function already by number...
192         void dispatch(FuncRequest const & func, DispatchResult & result);
193
194         /// Can this function be exectued?
195         /// \return true if we made a decision
196         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
197
198         ///
199         DocIterator getParFromID(int id) const;
200         /// do we have a paragraph with this id?
201         bool hasParWithID(int id) const;
202
203         ///
204         frontend::WorkAreaManager & workAreaManager() const;
205
206         /** Save file.
207             Takes care of auto-save files and backup file if requested.
208             Returns \c true if the save is successful, \c false otherwise.
209         */
210         bool save() const;
211         /// Renames and saves the buffer
212         bool saveAs(support::FileName const & fn);
213
214         /// Write document to stream. Returns \c false if unsuccessful.
215         bool write(std::ostream &) const;
216         /// Write file. Returns \c false if unsuccessful.
217         bool writeFile(support::FileName const &) const;
218
219         /// \name Functions involved in reading files/strings.
220         //@{
221         /// Loads the LyX file into the buffer. This function
222         /// tries to extract the file from version control if it
223         /// cannot be found. If it can be found, it will try to
224         /// read an emergency save file or an autosave file.
225         /// \sa loadThisLyXFile
226         ReadStatus loadLyXFile();
227         /// Loads the LyX file \c fn into the buffer. If you want
228         /// to check for files in a version control container,
229         /// emergency or autosave files, one should use \c loadLyXFile.
230         /// /sa loadLyXFile
231         ReadStatus loadThisLyXFile(support::FileName const & fn);
232         /// import a new document from a string
233         bool importString(std::string const &, docstring const &, ErrorList &);
234         /// import a new file
235         bool importFile(std::string const &, support::FileName const &, ErrorList &);
236         /// read a new document from a string
237         bool readString(std::string const &);
238         /// Reloads the LyX file
239         ReadStatus reload();
240 //FIXME: The following function should be private
241 //private:
242         /// read the header, returns number of unknown tokens
243         int readHeader(Lexer & lex);
244
245         double fontScalingFactor() const;
246
247 private:
248         ///
249         typedef std::map<Buffer const *, Buffer *> BufferMap;
250         ///
251         void cloneWithChildren(BufferMap &, CloneList *) const;
252         /// save timestamp and checksum of the given file.
253         void saveCheckSum() const;
254         /// read a new file
255         ReadStatus readFile(support::FileName const & fn);
256         /// Reads a file without header.
257         /// \param par if != 0 insert the file.
258         /// \return \c true if file is not completely read.
259         bool readDocument(Lexer &);
260         /// Try to extract the file from a version control container
261         /// before reading if the file cannot be found.
262         /// \sa LyXVC::file_not_found_hook
263         ReadStatus extractFromVC();
264         /// Reads the first tag of a LyX File and
265         /// returns the file format number.
266         ReadStatus parseLyXFormat(Lexer & lex, support::FileName const & fn,
267                 int & file_format) const;
268         /// Convert the LyX file to the LYX_FORMAT using
269         /// the lyx2lyx script and returns the filename
270         /// of the temporary file to be read
271         ReadStatus convertLyXFormat(support::FileName const & fn,
272                 support::FileName & tmpfile, int from_format);
273         /// get appropriate name for backing up files from older versions
274         support::FileName getBackupName() const;
275         //@}
276
277 public:
278         /// \name Functions involved in autosave and emergency files.
279         //@{
280         /// Save an autosave file to #filename.lyx#
281         bool autoSave() const;
282         /// save emergency file
283         /// \return a status message towards the user.
284         docstring emergencyWrite();
285
286 //FIXME:The following function should be private
287 //private:
288         ///
289         void removeAutosaveFile() const;
290
291 private:
292         /// Try to load an autosave file associated to \c fn.
293         ReadStatus loadAutosave();
294         /// Try to load an emergency file associated to \c fn.
295         ReadStatus loadEmergency();
296         /// Get the filename of the emergency file associated with the Buffer
297         support::FileName getEmergencyFileName() const;
298         /// Get the filename of the autosave file associated with the Buffer
299         support::FileName getAutosaveFileName() const;
300         ///
301         void moveAutosaveFile(support::FileName const & old) const;
302         //@}
303
304 public:
305         /// Fill in the ErrorList with the TeXErrors
306         void bufferErrors(TeXErrors const &, ErrorList &) const;
307
308         enum OutputWhat {
309                 FullSource,
310                 OnlyBody,
311                 IncludedFile,
312                 OnlyPreamble,
313                 CurrentParagraph
314         };
315
316         /// Just a wrapper for writeLaTeXSource, first creating the ofstream.
317         bool makeLaTeXFile(support::FileName const & filename,
318                            std::string const & original_path,
319                            OutputParams const &,
320                            OutputWhat output = FullSource) const;
321         /** Export the buffer to LaTeX.
322             If \p os is a file stream, and params().inputenc is "auto" or
323             "default", and the buffer contains text in different languages
324             with more than one encoding, then this method will change the
325             encoding associated to \p os. Therefore you must not call this
326             method with a string stream if the output is supposed to go to a
327             file. \code
328             ofdocstream ofs;
329             otexstream os(ofs);
330             ofs.open("test.tex");
331             writeLaTeXSource(os, ...);
332             ofs.close();
333             \endcode is NOT equivalent to \code
334             odocstringstream oss;
335             otexstream os(oss);
336             writeLaTeXSource(os, ...);
337             ofdocstream ofs;
338             ofs.open("test.tex");
339             ofs << oss.str();
340             ofs.close();
341             \endcode
342          */
343         void writeLaTeXSource(otexstream & os,
344                            std::string const & original_path,
345                            OutputParams const &,
346                            OutputWhat output = FullSource) const;
347         ///
348         void makeDocBookFile(support::FileName const & filename,
349                              OutputParams const & runparams_in,
350                              OutputWhat output = FullSource) const;
351         ///
352         void writeDocBookSource(odocstream & os, std::string const & filename,
353                              OutputParams const & runparams_in,
354                              OutputWhat output = FullSource) const;
355         ///
356         void makeLyXHTMLFile(support::FileName const & filename,
357                              OutputParams const & runparams_in) const;
358         ///
359         void writeLyXHTMLSource(odocstream & os,
360                              OutputParams const & runparams_in,
361                              OutputWhat output = FullSource) const;
362         /// returns the main language for the buffer (document)
363         Language const * language() const;
364         /// get l10n translated to the buffers language
365         docstring const B_(std::string const & l10n) const;
366
367         ///
368         int runChktex();
369         /// return true if the main lyx file does not need saving
370         bool isClean() const;
371         ///
372         bool isDepClean(std::string const & name) const;
373
374         /// whether or not disk file has been externally modified
375         bool isExternallyModified(CheckMethod method) const;
376
377         /// mark the main lyx file as not needing saving
378         void markClean() const;
379
380         ///
381         void markDepClean(std::string const & name);
382
383         ///
384         void setUnnamed(bool flag = true);
385
386         /// Whether or not a filename has been assigned to this buffer
387         bool isUnnamed() const;
388
389         /// Whether or not this buffer is internal.
390         ///
391         /// An internal buffer does not contain a real document, but some auxiliary text segment.
392         /// It is not associated with a filename, it is never saved, thus it does not need to be
393         /// automatically saved, nor it needs to trigger any "do you want to save ?" question.
394         bool isInternal() const;
395
396         void setInternal(bool flag);
397
398         /// Mark this buffer as dirty.
399         void markDirty();
400
401         /// Returns the buffer's filename. It is always an absolute path.
402         support::FileName fileName() const;
403
404         /// Returns the buffer's filename. It is always an absolute path.
405         std::string absFileName() const;
406
407         /// Returns the path where the buffer lives.
408         /// It is always an absolute path.
409         std::string filePath() const;
410
411         /** Contructs a file name of a referenced file (child doc, included graphics etc).
412          *  Absolute names are returned as is. If the name is relative, it is
413          *  interpreted relative to filePath() if the file exists, otherwise
414          *  relative to the original path where the document was last saved.
415          *  The original path may be different from filePath() if the document was
416          *  later manually moved to a different location.
417          */
418         support::DocFileName getReferencedFileName(std::string const & fn) const;
419
420         /// Format a file name for LaTeX output (absolute or relative or filename only,
421         /// depending on file and context)
422         std::string const prepareFileNameForLaTeX(std::string const &,
423                                         std::string const &, bool nice) const;
424
425         /** Returns a vector of bibliography (*.bib) file paths suitable for the
426          *  output in the respective BibTeX/Biblatex macro
427          */
428         std::vector<docstring> const prepareBibFilePaths(OutputParams const &,
429                                     support::FileNamePairList const bibfilelist,
430                                     bool const extension = true) const;
431
432         /** Returns the path where a local layout file lives.
433          *  An empty string is returned for standard system and user layouts.
434          *  If possible, it is always relative to the buffer path.
435          */
436         std::string layoutPos() const;
437
438         /** Set the path to a local layout file.
439          *  This must be an absolute path but, if possible, it is always
440          *  stored as relative to the buffer path.
441          */
442         void setLayoutPos(std::string const & path);
443
444         /** A transformed version of the file name, adequate for LaTeX.
445             \param no_path optional if \c true then the path is stripped.
446         */
447         std::string latexName(bool no_path = true) const;
448
449         /// Get the name and type of the log.
450         std::string logName(LogType * type = 0) const;
451
452         /// Set document's parent Buffer.
453         void setParent(Buffer const *);
454         Buffer const * parent() const;
455
456         /** Get the document's master (or \c this if this is not a
457             child document)
458          */
459         Buffer const * masterBuffer() const;
460
461         /// \return true if \p child is a child of this \c Buffer.
462         bool isChild(Buffer * child) const;
463
464         /// \return true if this \c Buffer has children
465         bool hasChildren() const;
466
467         /// \return a list of the direct children of this Buffer.
468         /// this list has no duplicates and is in the order in which
469         /// the children appear.
470         ListOfBuffers getChildren() const;
471
472         /// \return a list of all descendents of this Buffer (children,
473         /// grandchildren, etc). this list has no duplicates and is in
474         /// the order in which the children appear.
475         ListOfBuffers getDescendents() const;
476
477         /// Collect all relative buffers, in the order in which they appear.
478         /// I.e., the "root" Buffer is first, then its first child, then any
479         /// of its children, etc. However, there are no duplicates in this
480         /// list.
481         /// This is "stable", too, in the sense that it returns the same
482         /// thing from whichever Buffer it is called.
483         ListOfBuffers allRelatives() const;
484
485         /// Is buffer read-only?
486         bool isReadonly() const;
487
488         /// Set buffer read-only flag
489         void setReadonly(bool flag = true);
490
491         /** Validate a buffer for LaTeX.
492             This validates the buffer, and returns a struct for use by
493             #makeLaTeX# and others. Its main use is to figure out what
494             commands and packages need to be included in the LaTeX file.
495             It (should) also check that the needed constructs are there
496             (i.e. that the \refs points to coresponding \labels). It
497             should perhaps inset "error" insets to help the user correct
498             obvious mistakes.
499         */
500         void validate(LaTeXFeatures &) const;
501
502         /// Reference information is cached in the Buffer, so we do not
503         /// have to check or read things over and over.
504         ///
505         /// There are two caches.
506         ///
507         /// One is a cache of the BibTeX files from which reference info is
508         /// being gathered. This cache is PER BUFFER, and the cache for the
509         /// master essentially includes the cache for its children. This gets
510         /// invalidated when an InsetBibtex is created, deleted, or modified.
511         ///
512         /// The other is a cache of the reference information itself. This
513         /// exists only in the master buffer, and when it needs to be updated,
514         /// the children add their information to the master's cache.
515
516         /// Calling this method invalidates the cache and so requires a
517         /// re-read.
518         void invalidateBibinfoCache() const;
519         /// This invalidates the cache of files we need to check.
520         void invalidateBibfileCache() const;
521         /// Updates the cached bibliography information, checking first to see
522         /// whether the cache is valid. If so, we do nothing. If not, then we
523         /// reload all the BibTeX info.
524         /// Note that this operates on the master document.
525         void reloadBibInfoCache() const;
526         /// \return the bibliography information for this buffer's master,
527         /// or just for it, if it isn't a child.
528         BiblioInfo const & masterBibInfo() const;
529         /// collect bibliography info from the various insets in this buffer.
530         void collectBibKeys() const;
531         /// add some BiblioInfo to our cache
532         void addBiblioInfo(BiblioInfo const & bi) const;
533         /// add a single piece of bibliography info to our cache
534         void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
535         ///
536         void makeCitationLabels() const;
537         ///
538         bool citeLabelsValid() const;
539         ///
540         void getLabelList(std::vector<docstring> &) const;
541
542         /// This removes the .aux and .bbl files from the temp dir.
543         void removeBiblioTempFiles() const;
544
545         ///
546         void changeLanguage(Language const * from, Language const * to);
547
548         ///
549         bool isMultiLingual() const;
550         ///
551         std::set<Language const *> getLanguages() const;
552
553         ///
554         BufferParams & params();
555         BufferParams const & params() const;
556         ///
557         BufferParams const & masterParams() const;
558
559         /** The list of paragraphs.
560             This is a linked list of paragraph, this list holds the
561             whole contents of the document.
562          */
563         ParagraphList & paragraphs();
564         ParagraphList const & paragraphs() const;
565
566         /// LyX version control object.
567         LyXVC & lyxvc();
568         LyXVC const & lyxvc() const;
569
570         /// Where to put temporary files.
571         std::string const temppath() const;
572
573         /// Used when typesetting to place errorboxes.
574         TexRow const & texrow() const;
575         TexRow & texrow();
576
577         ///
578         ParIterator par_iterator_begin();
579         ///
580         ParConstIterator par_iterator_begin() const;
581         ///
582         ParIterator par_iterator_end();
583         ///
584         ParConstIterator par_iterator_end() const;
585
586         // Position of the child buffer where it appears first in the master.
587         DocIterator firstChildPosition(Buffer const * child);
588
589         /** \returns true only when the file is fully loaded.
590          *  Used to prevent the premature generation of previews
591          *  and by the citation inset.
592          */
593         bool isFullyLoaded() const;
594         /// Set by buffer_funcs' newFile.
595         void setFullyLoaded(bool);
596
597         /// FIXME: Needed by RenderPreview.
598         graphics::PreviewLoader * loader() const;
599         /// Update the LaTeX preview snippets associated with this buffer
600         void updatePreviews() const;
601         /// Remove any previewed LaTeX snippets associated with this buffer
602         void removePreviews() const;
603         ///
604         graphics::Cache & graphicsCache() const;
605
606         /// Our main text (inside the top InsetText)
607         Text & text() const;
608
609         /// Our top InsetText
610         Inset & inset() const;
611
612         //
613         // Macro handling
614         //
615         /// Collect macro definitions in paragraphs
616         void updateMacros() const;
617         /// Iterate through the whole buffer and try to resolve macros
618         void updateMacroInstances(UpdateType) const;
619
620         /// List macro names of this buffer, the parent and the children
621         void listMacroNames(MacroNameSet & macros) const;
622         /// Collect macros of the parent and its children in front of this buffer.
623         void listParentMacros(MacroSet & macros, LaTeXFeatures & features) const;
624
625         /// Return macro defined before pos (or in the master buffer)
626         MacroData const * getMacro(docstring const & name, DocIterator const & pos, bool global = true) const;
627         /// Return macro defined anywhere in the buffer (or in the master buffer)
628         MacroData const * getMacro(docstring const & name, bool global = true) const;
629         /// Return macro defined before the inclusion of the child
630         MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const;
631
632         /// Collect user macro names at loading time
633         typedef std::set<docstring> UserMacroSet;
634         mutable UserMacroSet usermacros;
635
636         /// Replace the inset contents for insets which InsetCode is equal
637         /// to the passed \p inset_code.
638         void changeRefsIfUnique(docstring const & from, docstring const & to);
639
640         /// get source code (latex/docbook) for some paragraphs, or all paragraphs
641         /// including preamble
642         /// returns nullptr if Id to Row conversion is unsupported
643         unique_ptr<TexRow> getSourceCode(odocstream & os,
644                         std::string const & format, pit_type par_begin,
645                         pit_type par_end, OutputWhat output, bool master) const;
646
647         /// Access to error list.
648         /// This method is used only for GUI visualisation of Buffer related
649         /// errors (like parsing or LateX compilation). This method is const
650         /// because modifying the returned ErrorList does not touch the document
651         /// contents.
652         ErrorList & errorList(std::string const & type) const;
653
654         /// The Toc backend.
655         /// This is useful only for screen visualisation of the Buffer. This
656         /// method is const because modifying this backend does not touch
657         /// the document contents.
658         TocBackend & tocBackend() const;
659
660         ///
661         Undo & undo();
662
663         /// This function is called when the buffer is changed.
664         void changed(bool update_metrics) const;
665         ///
666         void setChild(DocIterator const & dit, Buffer * child);
667         ///
668         void updateTocItem(std::string const &, DocIterator const &) const;
669         /// This function is called when the buffer structure is changed.
670         void structureChanged() const;
671         /// This function is called when some parsing error shows up.
672         void errors(std::string const & err, bool from_master = false) const;
673         /// This function is called when the buffer busy status change.
674         void setBusy(bool on) const;
675         /// Update window titles of all users.
676         void updateTitles() const;
677         /// Reset autosave timers for all users.
678         void resetAutosaveTimers() const;
679         ///
680         void message(docstring const & msg) const;
681
682         ///
683         void setGuiDelegate(frontend::GuiBufferDelegate * gui);
684         ///
685         bool hasGuiDelegate() const;
686
687         ///
688         ExportStatus doExport(std::string const & target, bool put_in_tempdir) const;
689         /// Export buffer to format \p format and open the result in a suitable viewer.
690         /// Note: This has nothing to do with preview of graphics or math formulas.
691         ExportStatus preview(std::string const & format) const;
692         /// true if there was a previous preview this session of this buffer and
693         /// there was an error on the previous preview of this buffer.
694         bool lastPreviewError() const;
695
696 private:
697         ///
698         ExportStatus doExport(std::string const & target, bool put_in_tempdir,
699                 std::string & result_file) const;
700         /// target is a format name optionally followed by a space
701         /// and a destination file-name
702         ExportStatus doExport(std::string const & target, bool put_in_tempdir,
703                 bool includeall, std::string & result_file) const;
704         ///
705         ExportStatus preview(std::string const & format, bool includeall) const;
706         ///
707         void setMathFlavor(OutputParams & op) const;
708
709 public:
710         ///
711         bool isExporting() const;
712
713         ///
714         typedef std::vector<std::pair<Inset *, ParIterator> > References;
715         ///
716         References const & references(docstring const & label) const;
717         ///
718         void addReference(docstring const & label, Inset * inset, ParIterator it);
719         ///
720         void clearReferenceCache() const;
721         ///
722         void setInsetLabel(docstring const & label, InsetLabel const * il);
723         ///
724         InsetLabel const * insetLabel(docstring const & label) const;
725
726         /// return a list of all used branches (also in children)
727         void getUsedBranches(std::list<docstring> &, bool const from_master = false) const;
728
729         /// sets the buffer_ member for every inset in this buffer.
730         // FIXME This really shouldn't be needed, but at the moment it's not
731         // clear how to do it just for the individual pieces we need.
732         void setBuffersForInsets() const;
733         /// Updates screen labels and some other information associated with
734         /// insets and paragraphs. Actually, it's more like a general "recurse
735         /// through the Buffer" routine, that visits all the insets and paragraphs.
736         void updateBuffer() const { updateBuffer(UpdateMaster, InternalUpdate); }
737         /// \param scope: whether to start with the master document or just
738         /// do this one.
739         /// \param output: whether we are preparing for output.
740         void updateBuffer(UpdateScope scope, UpdateType utype) const;
741         ///
742         void updateBuffer(ParIterator & parit, UpdateType utype) const;
743
744         /// Spellcheck starting from \p from.
745         /// \p from initial position, will then points to the next misspelled
746         ///    word.
747         /// \p to will points to the end of the next misspelled word.
748         /// \p word_lang will contain the found misspelled word.
749         /// \return progress if a new word was found.
750         int spellCheck(DocIterator & from, DocIterator & to,
751                 WordLangTuple & word_lang, docstring_list & suggestions) const;
752         ///
753         void checkChildBuffers();
754         ///
755         void checkMasterBuffer();
756
757         /// If the document is being saved to a new location and the named file
758         /// exists at the old location, return its updated path relative to the
759         /// new buffer path if possible, otherwise return its absolute path.
760         /// In all other cases, this is a no-op and name is returned unchanged.
761         /// If a non-empty ext is given, the existence of name.ext is checked
762         /// but the returned path will not contain this extension.
763         /// Similarly, when loading a document that was moved from the location
764         /// where it was saved, return the correct path relative to the new
765         /// location.
766         std::string includedFilePath(std::string const & name,
767                                 std::string const & ext = empty_string()) const;
768
769         /// compute statistics between \p from and \p to
770         /// \p from initial position
771         /// \p to points to the end position
772         /// \p skipNoOutput if notes etc. should be ignored
773         void updateStatistics(DocIterator & from, DocIterator & to,
774                                                   bool skipNoOutput = true) const;
775         /// statistics accessor functions
776         int wordCount() const;
777         int charCount(bool with_blanks) const;
778
779         // this is const because it does not modify the buffer's real contents,
780         // only the mutable flag.
781         void setChangesPresent(bool) const;
782         bool areChangesPresent() const;
783         void updateChangesPresent() const;
784
785 private:
786         friend class MarkAsExporting;
787         /// mark the buffer as busy exporting something, or not
788         void setExportStatus(bool e) const;
789
790         ///
791         References & getReferenceCache(docstring const & label);
792         /// Change name of buffer. Updates "read-only" flag.
793         void setFileName(support::FileName const & fname);
794         ///
795         void getLanguages(std::set<Language const *> &) const;
796         /// Checks whether any of the referenced bibfiles have changed since the
797         /// last time we loaded the cache. Note that this does NOT update the
798         /// cached information.
799         void checkIfBibInfoCacheIsValid() const;
800         /// Update the list of all bibfiles in use (including bibfiles
801         /// of loaded child documents).
802         void updateBibfilesCache(UpdateScope scope = UpdateMaster) const;
803         /// Return the list with all bibfiles in use (including bibfiles
804         /// of loaded child documents).
805         support::FileNamePairList const &
806                 getBibfilesCache(UpdateScope scope = UpdateMaster) const;
807         ///
808         void collectChildren(ListOfBuffers & children, bool grand_children) const;
809
810         /// noncopyable
811         Buffer(Buffer const &);
812         void operator=(Buffer const &);
813
814         /// Use the Pimpl idiom to hide the internals.
815         class Impl;
816         /// The pointer never changes although *pimpl_'s contents may.
817         Impl * const d;
818 };
819
820
821 /// Helper class, to guarantee that the export status
822 /// gets reset properly. To use, simply create a local variable:
823 ///    MarkAsExporting mex(bufptr);
824 /// and leave the rest to us.
825 class MarkAsExporting {
826 public:
827         MarkAsExporting(Buffer const * buf) : buf_(buf)
828         {
829                 buf_->setExportStatus(true);
830         }
831         ~MarkAsExporting()
832         {
833                 buf_->setExportStatus(false);
834         }
835 private:
836         Buffer const * const buf_;
837 };
838
839
840 } // namespace lyx
841
842 #endif