1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lastfiles.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
#ifndef LASTFILES_H
|
|
|
|
|
#define LASTFILES_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
#include <boost/utility.hpp>
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
#include <deque>
|
2003-10-07 06:45:25 +00:00
|
|
|
|
#include <string>
|
1999-11-08 13:54:04 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** The latest documents loaded.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
This class takes care of the last .lyx files used by the LyX user. It
|
|
|
|
|
both reads and writes this information to a file. The number of files
|
|
|
|
|
kept are user defined, but defaults to four.
|
2000-08-07 20:58:24 +00:00
|
|
|
|
@author Lars Gullik Bj<EFBFBD>nnes
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
2001-04-17 14:00:20 +00:00
|
|
|
|
class LastFiles : boost::noncopyable {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
public:
|
1999-11-04 01:40:20 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
typedef std::deque<std::string> Files;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2000-05-22 16:56:05 +00:00
|
|
|
|
///
|
|
|
|
|
typedef Files::const_iterator const_iterator;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** Read the lastfiles file.
|
2000-09-14 17:53:12 +00:00
|
|
|
|
@param file The file to read the lastfiles form.
|
|
|
|
|
@param dostat Whether to check for file existance.
|
|
|
|
|
@param num number of files to remember.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
*/
|
2000-08-05 05:17:18 +00:00
|
|
|
|
explicit
|
2003-10-06 15:43:21 +00:00
|
|
|
|
LastFiles(std::string const & file,
|
2000-08-05 05:17:18 +00:00
|
|
|
|
bool dostat = true, unsigned int num = 4);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
/** Insert #file# into the list.
|
|
|
|
|
This funtion inserts #file# into the last files list. If the file
|
|
|
|
|
already exist it is moved to the top of the list, else exist it
|
|
|
|
|
is placed on the top of the list. If the list is full the last
|
|
|
|
|
file in the list is popped from the end.
|
|
|
|
|
@param file the file to insert in the list.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void newFile(std::string const & file);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
/** Writes the lastfiles table to disk.
|
|
|
|
|
Writes one file on each line, this way we can at least have
|
|
|
|
|
some special chars (e.g. space), but newline in filenames
|
|
|
|
|
are thus not allowed.
|
|
|
|
|
@param file the file we write the lastfiles list to.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void writeFile(std::string const & file) const;
|
2000-09-14 17:53:12 +00:00
|
|
|
|
/** Return file #n# in the lastfiles list.
|
|
|
|
|
@param n number in the list to get
|
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const operator[](unsigned int n) const;
|
2000-09-14 17:53:12 +00:00
|
|
|
|
/// Iterator to the beginning of the list.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Files::const_iterator begin() const { return files.begin(); }
|
2000-09-14 17:53:12 +00:00
|
|
|
|
/// Iterator to the end of the list.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Files::const_iterator end() const { return files.end(); }
|
1999-09-27 18:44:28 +00:00
|
|
|
|
private:
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** Local constants.
|
|
|
|
|
It is more portable among different C++ compilers to use
|
|
|
|
|
an enum instead of #int const XXX#
|
|
|
|
|
*/
|
|
|
|
|
enum local_constants {
|
|
|
|
|
/// Default number of lastfiles.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
DEFAULTFILES = 4,
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** Max number of lastfiles.
|
|
|
|
|
There is no point in keeping more than this number
|
1999-11-04 01:40:20 +00:00
|
|
|
|
of files at the same time. However perhaps someday
|
|
|
|
|
someone finds use for more files and wants to
|
|
|
|
|
change it. Please do. But don't show the files in
|
|
|
|
|
a menu...
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
ABSOLUTEMAXLASTFILES = 20
|
|
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
/// a list of lastfiles
|
|
|
|
|
Files files;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// number of files in the lastfiles list.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
unsigned int num_files;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// check for file existance or not.
|
|
|
|
|
bool dostat;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
/** Read the lastfiles file.
|
2000-09-14 17:53:12 +00:00
|
|
|
|
Reads the #.lyx_lastfiles# at the beginning of the LyX session.
|
|
|
|
|
This will read the lastfiles file (usually #.lyx_lastfiles#). It
|
1999-11-04 01:40:20 +00:00
|
|
|
|
will normally discard files that don't exist anymore, unless
|
2000-09-14 17:53:12 +00:00
|
|
|
|
LastFiles has been initialized with #dostat = false#.
|
|
|
|
|
@param file the file containing the lastfiles.
|
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void readFile(std::string const & file);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
/** Used by the constructor to set the number of stored last files.
|
|
|
|
|
@param num the number of lastfiles to set.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
*/
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void setNumberOfFiles(unsigned int num);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
#endif
|