4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
15 #include <boost/utility.hpp>
20 const long maxlastfiles
= 20;
22 /** The latest documents loaded.
23 * This class takes care of the last .lyx files used by the LyX user. It
24 * both reads and writes this information to a file. The number of files
25 * kept are user defined, but defaults to four.
27 class LastFiles
: boost::noncopyable
{
30 typedef std::deque
<std::string
> Files
;
33 typedef Files::const_iterator const_iterator
;
35 /** Read the lastfiles file.
36 @param file The file to read the lastfiles form.
37 @param dostat Whether to check for file existance.
38 @param num number of files to remember.
41 LastFiles(std::string
const & file
,
42 bool dostat
= true, unsigned int num
= 4);
44 /** Insert #file# into the list.
45 This funtion inserts #file# into the last files list. If the file
46 already exist it is moved to the top of the list, else exist it
47 is placed on the top of the list. If the list is full the last
48 file in the list is popped from the end.
49 @param file the file to insert in the list.
51 void newFile(std::string
const & file
);
52 /** Writes the lastfiles table to disk.
53 Writes one file on each line, this way we can at least have
54 some special chars (e.g. space), but newline in filenames
56 @param file the file we write the lastfiles list to.
58 void writeFile(std::string
const & file
) const;
59 /** Return file #n# in the lastfiles list.
60 @param n number in the list to get
62 std::string
const operator[](unsigned int n
) const;
63 /// Iterator to the beginning of the list.
64 Files::const_iterator
begin() const { return files
.begin(); }
65 /// Iterator to the end of the list.
66 Files::const_iterator
end() const { return files
.end(); }
69 It is more portable among different C++ compilers to use
70 an enum instead of #int const XXX#
72 enum local_constants
{
73 /// Default number of lastfiles.
75 /** Max number of lastfiles.
76 There is no point in keeping more than this number
77 of files at the same time. However perhaps someday
78 someone finds use for more files and wants to
79 change it. Please do. But don't show the files in
82 ABSOLUTEMAXLASTFILES
= 20
85 /// a list of lastfiles
87 /// number of files in the lastfiles list.
88 unsigned int num_files
;
89 /// check for file existance or not.
92 /** Read the lastfiles file.
93 Reads the #.lyx_lastfiles# at the beginning of the LyX session.
94 This will read the lastfiles file (usually #.lyx_lastfiles#). It
95 will normally discard files that don't exist anymore, unless
96 LastFiles has been initialized with #dostat = false#.
97 @param file the file containing the lastfiles.
99 void readFile(std::string
const & file
);
100 /** Used by the constructor to set the number of stored last files.
101 @param num the number of lastfiles to set.
103 void setNumberOfFiles(unsigned int num
);