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
25 #include "support/FileInfo.h"
26 #include "lastfiles.h"
29 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
32 setNumberOfFiles(num);
37 void LastFiles::setNumberOfFiles(unsigned int no)
39 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
42 lyxerr << "LyX: lastfiles: too many files\n"
43 "\tdefault (=" << int(DEFAULTFILES)
45 num_files = DEFAULTFILES;
50 void LastFiles::readFile(string const & filename)
52 // we will not complain if we can't find filename nor will
53 // we issue a warning. (Lgb)
54 ifstream ifs(filename.c_str());
58 while(getline(ifs, tmp) && files.size() < num_files) {
60 if (!(fileInfo.newFile(tmp).exist() &&
61 fileInfo.isRegular()))
69 void LastFiles::writeFile(string const & filename) const
71 ofstream ofs(filename.c_str());
73 for (Files::const_iterator cit = files.begin();
76 ofs << (*cit) << '\n';
79 lyxerr << "LyX: Warning: unable to save LastFiles: "
84 void LastFiles::newFile(string const & file)
86 // If file already exist, delete it and reinsert at front.
87 Files::iterator it = find(files.begin(), files.end(), file);
88 if (it != files.end())
90 files.push_front(file);
91 if (files.size() > num_files)
96 string LastFiles::operator[](unsigned int i) const