3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "lastfiles.h"
16 #include "support/FileInfo.h"
23 using namespace lyx::support;
31 using std::ostream_iterator;
34 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
37 setNumberOfFiles(num);
42 void LastFiles::setNumberOfFiles(unsigned int no)
44 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
47 lyxerr << "LyX: lastfiles: too many files\n"
48 "\tdefault (=" << int(DEFAULTFILES)
50 num_files = DEFAULTFILES;
55 void LastFiles::readFile(string const & filename)
57 // we will not complain if we can't find filename nor will
58 // we issue a warning. (Lgb)
59 ifstream ifs(filename.c_str());
63 while (getline(ifs, tmp) && files.size() < num_files) {
65 if (!(fileInfo.newFile(tmp).exist() &&
66 fileInfo.isRegular()))
74 void LastFiles::writeFile(string const & filename) const
76 ofstream ofs(filename.c_str());
78 copy(files.begin(), files.end(),
79 ostream_iterator<string>(ofs, "\n"));
81 lyxerr << "LyX: Warning: unable to save LastFiles: "
86 void LastFiles::newFile(string const & file)
88 // If file already exist, delete it and reinsert at front.
89 Files::iterator it = find(files.begin(), files.end(), file);
90 if (it != files.end())
92 files.push_front(file);
93 if (files.size() > num_files)
98 string const LastFiles::operator[](unsigned int i) const
100 if (i < files.size())