]> git.lyx.org Git - lyx.git/blob - src/BufferList.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / BufferList.h
1 // -*- C++ -*-
2 /**
3  * \file BufferList.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_LIST_H
13 #define BUFFER_LIST_H
14
15 #include "support/strfwd.h"
16
17 #include <vector>
18
19
20 namespace lyx {
21
22 class Author;
23 class Buffer;
24 class OutputParams;
25
26 namespace support {
27 class FileName;
28 class FileNameList;
29 } // namespace support
30
31 /**
32  * The class holds all all open buffers, and handles construction
33  * and deletions of new ones.
34  */
35 class BufferList {
36 public:
37         typedef std::vector<Buffer *>::iterator iterator;
38         typedef std::vector<Buffer *>::const_iterator const_iterator;
39
40 public:
41         BufferList();
42         ~BufferList();
43
44         iterator begin();
45         const_iterator begin() const;
46
47         iterator end();
48         const_iterator end() const;
49
50         /// create a new buffer and add it to the buffer list
51         /// \return 0 if the Buffer creation is not possible for whatever reason.
52         Buffer * newBuffer(std::string const & s);
53
54         /// create an internal buffer and add it to the internal buffer list
55         /// \return 0 if the Buffer creation is not possible for whatever reason.
56         Buffer * newInternalBuffer(std::string const & s);
57
58         /// Is child a child of some Buffer other than parent?
59         /// NOTE: child must be a child of parent, and both must be non-null.
60         /// Otherwise we assert.
61         bool isOthersChild(Buffer * parent, Buffer * child) const;
62
63         /// delete a buffer
64         void release(Buffer * b);
65
66         /// Close all open buffers.
67         void closeAll();
68
69         /// returns a vector with all the buffers filenames
70         support::FileNameList fileNames() const;
71
72         /// return true if no buffers loaded
73         bool empty() const;
74
75         /// return head of buffer list if any
76         Buffer * first();
77
78         /// return back of buffer list if any
79         Buffer * last();
80
81         /// returns true if the buffer exists already
82         bool exists(support::FileName const &) const;
83
84         /// returns true if the buffer is loaded
85         bool isLoaded(Buffer const * b) const;
86
87         /// returns true if the buffer is known as internal buffer
88         bool isInternal(Buffer const * b) const;
89
90         /// \return index of named buffer in buffer list
91         int bufferNum(support::FileName const & name) const;
92
93         /** returns a pointer to the buffer with the given name
94          *
95          *  \param internal
96          *    If true, the buffer is searched also among internal buffers
97          */
98         Buffer * getBuffer(support::FileName const & name, bool internal = false) const;
99
100         /// \return a pointer to the buffer with the given number
101         Buffer * getBuffer(unsigned int);
102
103         /// \return a pointer to the buffer whose temppath matches the given \p path
104         ///  If optional \p realpath is \c true the lookup is done with real path names
105         Buffer * getBufferFromTmp(std::string const & path, bool realpath = false);
106
107         /** returns a pointer to the buffer that follows argument in
108          * buffer list. The buffer following the last in list is the
109          * first one.
110          */
111         Buffer * next(Buffer const *) const;
112
113         /** returns a pointer to the buffer that precedes argument in
114          * buffer list. The buffer preceding the first in list is the
115          * last one.
116          */
117         Buffer * previous(Buffer const *) const;
118
119         /// \name Functions that just operate on all buffers
120         //@{
121         /// reset current author for all buffers
122         void recordCurrentAuthor(Author const & author);
123         /// update previews for all buffers, e.g. for Prefs update
124         void updatePreviews();
125         /// Call changed() on all buffers, internal or not
126         void changed(bool update_metrics) const;
127         /// emergency save for all buffers
128         void emergencyWriteAll();
129         /// FIXME
130         void updateIncludedTeXfiles(std::string const &, OutputParams const &);
131         ///
132         void invalidateConverterCache() const;
133         //@}
134
135 private:
136         /// create a new buffer
137         /// \return 0 if the Buffer creation is not possible for whatever reason.
138         Buffer * createNewBuffer(std::string const & s);
139
140         /// noncopiable
141         BufferList(BufferList const &);
142         void operator=(BufferList const &);
143
144         typedef std::vector<Buffer *> BufferStorage;
145
146         /// storage of all buffers
147         BufferStorage bstore;
148         /// storage of all internal buffers used for cut&paste, etc.
149         BufferStorage binternal;
150 };
151
152 /// Implementation is in LyX.cpp
153 extern BufferList & theBufferList();
154
155
156 } // namespace lyx
157
158 #endif // BUFFERLIST_H