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
21 #include "support/FileInfo.h"
22 #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 std::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 std::ofstream ofs(filename.c_str());
73 std::copy(files.begin(), files.end(),
74 std::ostream_iterator<string>(ofs, "\n"));
76 lyxerr << "LyX: Warning: unable to save LastFiles: "
81 void LastFiles::newFile(string const & file)
83 // If file already exist, delete it and reinsert at front.
84 Files::iterator it = std::find(files.begin(), files.end(), file);
85 if (it != files.end())
87 files.push_front(file);
88 if (files.size() > num_files)
93 string const LastFiles::operator[](unsigned int i) const