1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
15 #pragma implementation
20 #include "support/FileInfo.h"
21 #include "lastfiles.h"
24 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
27 setNumberOfFiles(num);
32 void LastFiles::setNumberOfFiles(unsigned int no)
34 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
37 lyxerr << "LyX: lastfiles: too many files\n"
38 "\tdefault (=" << int(DEFAULTFILES)
40 num_files = DEFAULTFILES;
45 void LastFiles::readFile(string const & filename)
47 // we will not complain if we can't find filename nor will
48 // we issue a warning. (Lgb)
49 ifstream ifs(filename.c_str());
53 while(getline(ifs, tmp) && files.size() < num_files) {
55 if (!(fileInfo.newFile(tmp).exist() &&
56 fileInfo.isRegular()))
64 void LastFiles::writeFile(string const & filename) const
66 ofstream ofs(filename.c_str());
68 for (Files::const_iterator cit = files.begin();
71 ofs << (*cit) << '\n';
74 lyxerr << "LyX: Warning: unable to save LastFiles: "
79 void LastFiles::newFile(string const & file)
81 // If file already exist, delete it and reinsert at front.
82 Files::iterator it = find(files.begin(), files.end(), file);
83 if (it != files.end())
85 files.push_front(file);
86 if (files.size() > num_files)
91 string LastFiles::operator[](unsigned int i) const