1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
15 #pragma implementation
18 #include "lastfiles.h"
21 #include "support/FileInfo.h"
34 using std::ostream_iterator;
37 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
40 setNumberOfFiles(num);
45 void LastFiles::setNumberOfFiles(unsigned int no)
47 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
50 lyxerr << "LyX: lastfiles: too many files\n"
51 "\tdefault (=" << int(DEFAULTFILES)
53 num_files = DEFAULTFILES;
58 void LastFiles::readFile(string const & filename)
60 // we will not complain if we can't find filename nor will
61 // we issue a warning. (Lgb)
62 ifstream ifs(filename.c_str());
66 while (getline(ifs, tmp) && files.size() < num_files) {
68 if (!(fileInfo.newFile(tmp).exist() &&
69 fileInfo.isRegular()))
77 void LastFiles::writeFile(string const & filename) const
79 ofstream ofs(filename.c_str());
81 copy(files.begin(), files.end(),
82 ostream_iterator<string>(ofs, "\n"));
84 lyxerr << "LyX: Warning: unable to save LastFiles: "
89 void LastFiles::newFile(string const & file)
91 // If file already exist, delete it and reinsert at front.
92 Files::iterator it = find(files.begin(), files.end(), file);
93 if (it != files.end())
95 files.push_front(file);
96 if (files.size() > num_files)
101 string const LastFiles::operator[](unsigned int i) const
103 if (i < files.size())