]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
Alfredo's second patch
[lyx.git] / src / bufferlist.h
1 // -*- C++ -*-
2 /**
3  * \file bufferlist.C
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 "LString.h"
16
17 #include <boost/utility.hpp>
18
19 #include <vector>
20
21 class Buffer;
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         /**
32            Loads a LyX file or...
33
34            \param filename The filename to read from.
35            \param tolastfiles Wether the file should be put in the
36            last opened files list or not.
37            \return The newly loaded LyX file.
38         */
39         Buffer * loadLyXFile(string const & filename,
40                              bool tolastfiles = true);
41
42         /// write all buffers, asking the user, returns false if cancelled
43         bool quitWriteAll();
44
45         /// create a new buffer
46         Buffer * newBuffer(string const & s, bool ronly = false);
47
48         /// delete a buffer
49         void release(Buffer * b);
50
51         /// Close all open buffers.
52         void closeAll();
53
54         /// read the given file
55         Buffer * readFile(string const &, bool ro);
56
57         /// Make a new file (buffer) using a template
58         Buffer * newFile(string const &, string, bool isNamed = false);
59         /// returns a vector with all the buffers filenames
60         std::vector<string> const getFileNames() const;
61
62         /// FIXME
63         void updateIncludedTeXfiles(string const &);
64
65         /// emergency save for all buffers
66         void emergencyWriteAll();
67
68         /// close buffer. Returns false if cancelled by user
69         bool close(Buffer * buf, bool ask);
70
71         /// return true if no buffers loaded
72         bool empty() const;
73
74         /// return head of buffer list if any
75         Buffer * first();
76
77         /// returns true if the buffer exists already
78         bool exists(string const &) const;
79
80         /// returns true if the buffer is loaded
81         bool isLoaded(Buffer const * b) const;
82
83         /// returns a pointer to the buffer with the given name.
84         Buffer * getBuffer(string const &);
85         /// returns a pointer to the buffer with the given number.
86         Buffer * getBuffer(unsigned int);
87
88         /// reset current author for all buffers
89         void setCurrentAuthor(string const & name, string const & email);
90
91 private:
92         /// ask to save a buffer on quit, returns false if should cancel
93         bool quitWriteBuffer(Buffer * buf);
94
95         typedef std::vector<Buffer *> BufferStorage;
96
97         /// storage of all buffers
98         BufferStorage bstore;
99
100         /// save emergency file for the given buffer
101         void emergencyWrite(Buffer * buf);
102 };
103
104 #endif // BUFFERLIST_H