1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-10-07 18:44:17 +00:00
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1995-2001 The LyX Team
|
1999-10-07 18:44:17 +00:00
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* This file is Copyright 1996-2001
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#ifndef BUFFER_LIST_H
|
|
|
|
|
#define BUFFER_LIST_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma interface
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2000-10-02 00:55:02 +00:00
|
|
|
|
#include <boost/utility.hpp>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/** A class to hold all the buffers in a structure
|
|
|
|
|
The point of this class is to hide from bufferlist what kind
|
|
|
|
|
of structure the buffers are stored in. Should be no concern for
|
|
|
|
|
bufferlist if the buffers is in a array or in a linked list.
|
|
|
|
|
|
|
|
|
|
This class should ideally be enclosed inside class BufferList, but that
|
|
|
|
|
gave me an "internal gcc error".
|
|
|
|
|
*/
|
2001-04-17 15:15:59 +00:00
|
|
|
|
class BufferStorage : boost::noncopyable {
|
1999-11-05 06:02:34 +00:00
|
|
|
|
public:
|
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
|
typedef std::vector<Buffer *> Container;
|
1999-11-05 06:02:34 +00:00
|
|
|
|
///
|
|
|
|
|
typedef Container::iterator iterator;
|
|
|
|
|
///
|
2000-01-20 01:41:55 +00:00
|
|
|
|
typedef Container::const_iterator const_iterator;
|
|
|
|
|
///
|
2000-09-27 17:07:33 +00:00
|
|
|
|
typedef Container::size_type size_type;
|
|
|
|
|
///
|
1999-11-05 06:02:34 +00:00
|
|
|
|
bool empty() const { return container.empty(); }
|
|
|
|
|
///
|
|
|
|
|
void release(Buffer * buf);
|
|
|
|
|
///
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Buffer * newBuffer(string const & s, bool = false);
|
1999-11-05 06:02:34 +00:00
|
|
|
|
///
|
|
|
|
|
Container::iterator begin() { return container.begin(); }
|
|
|
|
|
///
|
|
|
|
|
Container::iterator end() { return container.end(); }
|
|
|
|
|
///
|
2000-01-20 01:41:55 +00:00
|
|
|
|
Container::const_iterator begin() const { return container.begin(); }
|
|
|
|
|
///
|
|
|
|
|
Container::const_iterator end() const { return container.end(); }
|
|
|
|
|
///
|
1999-11-05 06:02:34 +00:00
|
|
|
|
Buffer * front() { return container.front(); }
|
|
|
|
|
///
|
|
|
|
|
Buffer * operator[](int c) { return container[c]; }
|
|
|
|
|
///
|
2000-09-27 17:07:33 +00:00
|
|
|
|
size_type size() const { return container.size(); }
|
1999-11-05 06:02:34 +00:00
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
Container container;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-11-05 06:02:34 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** The class govern all open buffers.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
2001-04-17 15:15:59 +00:00
|
|
|
|
class BufferList : boost::noncopyable {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
BufferList();
|
|
|
|
|
|
|
|
|
|
/// state info
|
|
|
|
|
enum list_state {
|
|
|
|
|
///
|
|
|
|
|
OK,
|
|
|
|
|
///
|
|
|
|
|
CLOSING
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// returns the state of the bufferlist
|
2000-02-03 17:09:33 +00:00
|
|
|
|
list_state getState() const { return state_; }
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/** loads a LyX file or...
|
1999-11-15 12:27:25 +00:00
|
|
|
|
If the optional argument tolastfiles is false (default is
|
1999-09-27 18:44:28 +00:00
|
|
|
|
true), the file name will not be added to the last opened
|
|
|
|
|
files list
|
1999-11-15 12:27:25 +00:00
|
|
|
|
*/
|
1999-11-05 06:02:34 +00:00
|
|
|
|
Buffer * loadLyXFile(string const & filename,
|
|
|
|
|
bool tolastfiles = true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
2000-02-03 17:09:33 +00:00
|
|
|
|
bool empty() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
bool QwriteAll();
|
|
|
|
|
|
|
|
|
|
/// Close all open buffers.
|
|
|
|
|
void closeAll();
|
|
|
|
|
|
|
|
|
|
/// Read a file into a buffer readonly or not.
|
1999-11-05 06:02:34 +00:00
|
|
|
|
Buffer * readFile(string const &, bool ro);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// Make a new file (buffer) using a template
|
2001-04-24 15:25:26 +00:00
|
|
|
|
Buffer * newFile(string const &, string, bool isNamed = false);
|
2000-01-20 01:41:55 +00:00
|
|
|
|
/// returns a vector with all the buffers filenames
|
2000-09-14 17:53:12 +00:00
|
|
|
|
std::vector<string> const getFileNames() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
1999-11-05 06:02:34 +00:00
|
|
|
|
int unlockInset(UpdatableInset *);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void updateIncludedTeXfiles(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void emergencyWriteAll();
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** Close buffer.
|
|
|
|
|
@param buf the buffer that should be closed
|
|
|
|
|
@return #false# if operation was canceled
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
2000-08-07 20:58:24 +00:00
|
|
|
|
bool close(Buffer * buf);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
1999-11-05 06:02:34 +00:00
|
|
|
|
Buffer * first();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// returns true if the buffer exists already
|
2000-02-03 17:09:33 +00:00
|
|
|
|
bool exists(string const &) const;
|
|
|
|
|
|
|
|
|
|
/// returns true if the buffer is loaded
|
|
|
|
|
bool isLoaded(Buffer const * b) const;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// returns a pointer to the buffer with the given name.
|
1999-11-05 06:02:34 +00:00
|
|
|
|
Buffer * getBuffer(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// returns a pointer to the buffer with the given number.
|
2000-10-11 21:06:43 +00:00
|
|
|
|
Buffer * getBuffer(unsigned int);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
BufferStorage bstore;
|
|
|
|
|
|
|
|
|
|
///
|
2000-01-20 01:41:55 +00:00
|
|
|
|
list_state state_;
|
2000-10-11 21:06:43 +00:00
|
|
|
|
///
|
|
|
|
|
void emergencyWrite(Buffer * buf);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|