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