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