]> git.lyx.org Git - lyx.git/blob - src/BufferList.h
pimpl not needed here
[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/docstring.h"
16
17 #include <boost/noncopyable.hpp>
18
19 #include <vector>
20
21
22 namespace lyx {
23
24 class Buffer;
25 class OutputParams;
26
27 /**
28  * The class holds all all open buffers, and handles construction
29  * and deletions of new ones.
30  */
31 class BufferList : boost::noncopyable {
32 public:
33         typedef std::vector<Buffer *>::iterator iterator;
34         typedef std::vector<Buffer *>::const_iterator const_iterator;
35
36 public:
37         BufferList();
38
39         iterator begin();
40         const_iterator begin() const;
41
42         iterator end();
43         const_iterator end() const;
44
45         /// write all buffers, asking the user, returns false if cancelled
46         bool quitWriteAll();
47
48         /// create a new buffer
49         Buffer * newBuffer(std::string const & s, bool ronly = false);
50
51         /// delete a buffer
52         void release(Buffer * b);
53
54         /// Close all open buffers.
55         void closeAll();
56
57         /// returns a vector with all the buffers filenames
58         std::vector<std::string> const getFileNames() const;
59
60         /// FIXME
61         void updateIncludedTeXfiles(std::string const &, OutputParams const &);
62
63         /// emergency save for all buffers
64         void emergencyWriteAll();
65
66         /// close buffer. Returns false if cancelled by user
67         bool close(Buffer * buf, bool ask);
68
69         /// return true if no buffers loaded
70         bool empty() const;
71
72         /// return head of buffer list if any
73         Buffer * first();
74
75         /// return back of buffer list if any
76         Buffer * last();
77
78         /// returns true if the buffer exists already
79         bool exists(std::string const &) const;
80
81         /// returns true if the buffer is loaded
82         bool isLoaded(Buffer const * b) const;
83
84         /// return index of named buffer in buffer list
85         int bufferNum(std::string const & name) const;
86         /// returns a pointer to the buffer with the given name.
87         Buffer * getBuffer(std::string const &);
88         /// returns a pointer to the buffer with the given number.
89         Buffer * getBuffer(unsigned int);
90         /// returns a pointer to the buffer whose temppath matches the string
91         Buffer * getBufferFromTmp(std::string const &);
92
93         /** returns a pointer to the buffer that follows argument in
94          * buffer list. The buffer following the last in list is the
95          * first one.
96          */
97         Buffer * next(Buffer const *) const;
98
99         /** returns a pointer to the buffer that precedes argument in
100          * buffer list. The buffer preceding the first in list is the
101          * last one.
102          */
103         Buffer * previous(Buffer const *) const;
104
105         /// reset current author for all buffers
106         void setCurrentAuthor(docstring const & name, docstring const & email);
107
108 private:
109         /// ask to save a buffer on quit, returns false if should cancel
110         bool quitWriteBuffer(Buffer * buf);
111
112         typedef std::vector<Buffer *> BufferStorage;
113
114         /// storage of all buffers
115         BufferStorage bstore;
116
117         /// save emergency file for the given buffer
118         void emergencyWrite(Buffer * buf);
119 };
120
121 /// Implementation is in LyX.cpp
122 extern BufferList & theBufferList();
123
124
125 } // namespace lyx
126
127 #endif // BUFFERLIST_H