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"
31 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
34 setNumberOfFiles(num);
39 void LastFiles::setNumberOfFiles(unsigned int no)
41 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
44 lyxerr << "LyX: lastfiles: too many files\n"
45 "\tdefault (=" << int(DEFAULTFILES)
47 num_files = DEFAULTFILES;
52 void LastFiles::readFile(string const & filename)
54 // we will not complain if we can't find filename nor will
55 // we issue a warning. (Lgb)
56 std::ifstream ifs(filename.c_str());
60 while (getline(ifs, tmp) && files.size() < num_files) {
62 if (!(fileInfo.newFile(tmp).exist() &&
63 fileInfo.isRegular()))
71 void LastFiles::writeFile(string const & filename) const
73 std::ofstream ofs(filename.c_str());
75 std::copy(files.begin(), files.end(),
76 std::ostream_iterator<string>(ofs, "\n"));
78 lyxerr << "LyX: Warning: unable to save LastFiles: "
83 void LastFiles::newFile(string const & file)
85 // If file already exist, delete it and reinsert at front.
86 Files::iterator it = std::find(files.begin(), files.end(), file);
87 if (it != files.end())
89 files.push_front(file);
90 if (files.size() > num_files)
95 string const LastFiles::operator[](unsigned int i) const