Consider the case where there is not any layout name.
[lyx.git] / src / lastfiles.h
blobefe657e7854ef8ddeb9f5cac4d45dea35afbeebd
1 // -*- C++ -*-
2 /**
3 * \file lastfiles.h
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.
12 #ifndef LASTFILES_H
13 #define LASTFILES_H
15 #include <boost/utility.hpp>
17 #include <deque>
18 #include <string>
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 {
28 public:
29 ///
30 typedef std::deque<std::string> Files;
32 ///
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.
40 explicit
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
55 are thus not allowed.
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(); }
67 private:
68 /** Local constants.
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.
74 DEFAULTFILES = 4,
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
80 a menu...
82 ABSOLUTEMAXLASTFILES = 20
85 /// a list of lastfiles
86 Files files;
87 /// number of files in the lastfiles list.
88 unsigned int num_files;
89 /// check for file existance or not.
90 bool dostat;
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);
105 #endif