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