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