1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <algorithm>
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/FileInfo.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lastfiles.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
|
1999-09-27 18:44:28 +00:00
|
|
|
: dostat(st)
|
|
|
|
{
|
|
|
|
setNumberOfFiles(num);
|
|
|
|
readFile(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void LastFiles::setNumberOfFiles(unsigned int no)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
if (0 < no && no <= ABSOLUTEMAXLASTFILES)
|
1999-09-27 18:44:28 +00:00
|
|
|
num_files = no;
|
|
|
|
else {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyX: lastfiles: too many files\n"
|
1999-11-04 01:40:20 +00:00
|
|
|
"\tdefault (=" << int(DEFAULTFILES)
|
1999-10-07 18:44:17 +00:00
|
|
|
<< ") used." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
num_files = DEFAULTFILES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LastFiles::readFile(string const & filename)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// we will not complain if we can't find filename nor will
|
1999-11-04 01:40:20 +00:00
|
|
|
// we issue a warning. (Lgb)
|
|
|
|
ifstream ifs(filename.c_str());
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp;
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo fileInfo;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
|
|
while(getline(ifs, tmp) && files.size() < num_files) {
|
|
|
|
if (dostat) {
|
|
|
|
if (!(fileInfo.newFile(tmp).exist() &&
|
|
|
|
fileInfo.isRegular()))
|
|
|
|
continue;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
files.push_back(tmp);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LastFiles::writeFile(string const & filename) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
ofstream ofs(filename.c_str());
|
|
|
|
if (ofs) {
|
|
|
|
for (Files::const_iterator cit = files.begin();
|
|
|
|
cit != files.end();
|
|
|
|
++cit) {
|
|
|
|
ofs << (*cit) << '\n';
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
} else
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyX: Warning: unable to save LastFiles: "
|
|
|
|
<< filename << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LastFiles::newFile(string const & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
// If file already exist, delete it and reinsert at front.
|
|
|
|
Files::iterator it = find(files.begin(), files.end(), file);
|
|
|
|
if (it != files.end())
|
|
|
|
files.erase(it);
|
|
|
|
files.push_front(file);
|
|
|
|
if (files.size() > num_files)
|
|
|
|
files.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string LastFiles::operator[](unsigned int i) const
|
|
|
|
{
|
|
|
|
if (i < files.size())
|
|
|
|
return files[i];
|
|
|
|
return string();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|