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