2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
22 #include "support/utility.hpp"
24 /** The latest documents loaded.
25 This class takes care of the last .lyx files used by the LyX user. It
26 both reads and writes this information to a file. The number of files
27 kept are user defined, but defaults to four.
28 @author Lars Gullik Bjønnes
30 class LastFiles : public noncopyable {
33 typedef std::deque<string> Files;
36 typedef Files::const_iterator const_iterator;
38 /** Read the lastfiles file.
39 @param file The file to read the lastfiles form.
40 @param dostat Whether to check for file existance.
41 @param num number of files to remember.
44 LastFiles(string const & file,
45 bool dostat = true, unsigned int num = 4);
48 This funtion inserts #file# into the last files list. If the file
49 already exist it is moved to the top of the list, else exist it
50 is placed on the top of the list. If the list is full the last
51 file in the list is popped from the end.
53 void newFile(string const & file);
54 /** Writes the lastfiles table to disk. One file on each line, this
55 way we can at least have some special chars (e.g. space), but
56 newline in filenames are thus not allowed.
58 void writeFile(string const &) const;
60 string const operator[](unsigned int) const;
62 Files::const_iterator begin() const { return files.begin(); }
64 Files::const_iterator end() const { return files.end(); }
67 It is more portable among different C++ compilers to use
68 an enum instead of #int const XXX#
70 enum local_constants {
71 /// Default number of lastfiles.
73 /** Max number of lastfiles.
74 There is no point in keeping more than this number
75 of files at the same time. However perhaps someday
76 someone finds use for more files and wants to
77 change it. Please do. But don't show the files in
80 ABSOLUTEMAXLASTFILES = 20
83 /// a list of lastfiles
85 /// number of files in the lastfiles list.
86 unsigned int num_files;
87 /// check for file existance or not.
90 /** Read the lastfiles file.
91 Reads the .lyx_lastfiles at the beginning of the LyX session.
92 This will read the lastfiles file (usually .lyx_lastfiles). It
93 will normally discard files that don't exist anymore, unless
94 LastFiles has been initialized with dostat = false.
96 void readFile(string const &);
97 /// used by the constructor to set the number of stored last files.
98 void setNumberOfFiles(unsigned int num);