mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Introducing FileNameList, cleanup some headers and put back dirList() into FileName.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21965 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f4e787e982
commit
e017570aa8
@ -79,6 +79,7 @@
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/ForkedCalls.h"
|
||||
#include "support/gettext.h"
|
||||
@ -129,6 +130,7 @@ using support::changeExtension;
|
||||
using support::cmd_ret;
|
||||
using support::createBufferTmpDir;
|
||||
using support::FileName;
|
||||
using support::FileNameList;
|
||||
using support::libFileSearch;
|
||||
using support::latex_path;
|
||||
using support::ltrim;
|
||||
@ -229,6 +231,10 @@ public:
|
||||
|
||||
///
|
||||
Undo undo_;
|
||||
|
||||
/// A cache for the bibfiles (including bibfiles of loaded child
|
||||
/// documents), needed for appropriate update of natbib labels.
|
||||
mutable FileNameList bibfilesCache_;
|
||||
};
|
||||
|
||||
|
||||
@ -1450,22 +1456,22 @@ void Buffer::updateBibfilesCache() const
|
||||
return;
|
||||
}
|
||||
|
||||
bibfilesCache_.clear();
|
||||
d->bibfilesCache_.clear();
|
||||
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
|
||||
if (it->lyxCode() == BIBTEX_CODE) {
|
||||
InsetBibtex const & inset =
|
||||
static_cast<InsetBibtex const &>(*it);
|
||||
vector<FileName> const bibfiles = inset.getFiles(*this);
|
||||
bibfilesCache_.insert(bibfilesCache_.end(),
|
||||
FileNameList const bibfiles = inset.getFiles(*this);
|
||||
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
|
||||
bibfiles.begin(),
|
||||
bibfiles.end());
|
||||
} else if (it->lyxCode() == INCLUDE_CODE) {
|
||||
InsetInclude & inset =
|
||||
static_cast<InsetInclude &>(*it);
|
||||
inset.updateBibfilesCache(*this);
|
||||
vector<FileName> const & bibfiles =
|
||||
FileNameList const & bibfiles =
|
||||
inset.getBibfilesCache(*this);
|
||||
bibfilesCache_.insert(bibfilesCache_.end(),
|
||||
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
|
||||
bibfiles.begin(),
|
||||
bibfiles.end());
|
||||
}
|
||||
@ -1473,7 +1479,7 @@ void Buffer::updateBibfilesCache() const
|
||||
}
|
||||
|
||||
|
||||
vector<FileName> const & Buffer::getBibfilesCache() const
|
||||
FileNameList const & Buffer::getBibfilesCache() const
|
||||
{
|
||||
// if this is a child document and the parent is already loaded
|
||||
// use the parent's cache instead
|
||||
@ -1483,10 +1489,10 @@ vector<FileName> const & Buffer::getBibfilesCache() const
|
||||
return tmp->getBibfilesCache();
|
||||
|
||||
// We update the cache when first used instead of at loading time.
|
||||
if (bibfilesCache_.empty())
|
||||
if (d->bibfilesCache_.empty())
|
||||
const_cast<Buffer *>(this)->updateBibfilesCache();
|
||||
|
||||
return bibfilesCache_;
|
||||
return d->bibfilesCache_;
|
||||
}
|
||||
|
||||
|
||||
|
12
src/Buffer.h
12
src/Buffer.h
@ -14,7 +14,6 @@
|
||||
|
||||
#include "insets/InsetCode.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
#include "support/strfwd.h"
|
||||
#include "support/types.h"
|
||||
|
||||
@ -54,6 +53,11 @@ class GuiBufferDelegate;
|
||||
class WorkAreaManager;
|
||||
}
|
||||
|
||||
namespace support {
|
||||
class FileName;
|
||||
class FileNameList;
|
||||
}
|
||||
|
||||
/** The buffer object.
|
||||
* This is the buffer object. It contains all the informations about
|
||||
* a document loaded into LyX.
|
||||
@ -298,7 +302,7 @@ public:
|
||||
void updateBibfilesCache() const;
|
||||
/// Return the cache with all bibfiles in use (including bibfiles
|
||||
/// of loaded child documents).
|
||||
std::vector<support::FileName> const & getBibfilesCache() const;
|
||||
support::FileNameList const & getBibfilesCache() const;
|
||||
///
|
||||
void getLabelList(std::vector<docstring> &) const;
|
||||
|
||||
@ -453,10 +457,6 @@ private:
|
||||
/// The pointer never changes although *pimpl_'s contents may.
|
||||
Impl * const d;
|
||||
|
||||
/// A cache for the bibfiles (including bibfiles of loaded child
|
||||
/// documents), needed for appropriate update of natbib labels.
|
||||
mutable std::vector<support::FileName> bibfilesCache_;
|
||||
|
||||
frontend::GuiBufferDelegate * gui_;
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/debug.h"
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/FileZipListDir.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
@ -33,7 +35,6 @@
|
||||
#include "support/Package.h"
|
||||
#include "support/Path.h"
|
||||
#include "support/Systemcall.h"
|
||||
#include "support/FileZipListDir.h"
|
||||
|
||||
using std::find_if;
|
||||
using std::string;
|
||||
@ -49,6 +50,7 @@ using support::changeExtension;
|
||||
using support::compare_ascii_no_case;
|
||||
using support::contains;
|
||||
using support::FileName;
|
||||
using support::FileNameList;
|
||||
using support::getExtension;
|
||||
using support::libFileSearch;
|
||||
using support::libScriptSearch;
|
||||
@ -511,8 +513,6 @@ bool Converters::convert(Buffer const * buffer,
|
||||
bool Converters::move(string const & fmt,
|
||||
FileName const & from, FileName const & to, bool copy)
|
||||
{
|
||||
if (from == to)
|
||||
return true;
|
||||
|
||||
bool no_errors = true;
|
||||
string const path = onlyPath(from.absFilename());
|
||||
@ -520,9 +520,10 @@ bool Converters::move(string const & fmt,
|
||||
string const to_base = removeExtension(to.absFilename());
|
||||
string const to_extension = getExtension(to.absFilename());
|
||||
|
||||
vector<FileName> const files =
|
||||
support::dirList(FileName(path), getExtension(from.absFilename()));
|
||||
for (vector<FileName>::const_iterator it = files.begin();
|
||||
FileNameList const files = FileName(path).dirList(getExtension(from.absFilename()));
|
||||
if (from == to)
|
||||
return true;
|
||||
for (FileNameList::const_iterator it = files.begin();
|
||||
it != files.end(); ++it) {
|
||||
string const from2 = it->absFilename();
|
||||
string const file2 = onlyFilename(from2);
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "support/ExceptionMessage.h"
|
||||
#include "support/docstream.h"
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
@ -48,6 +49,7 @@ using support::contains;
|
||||
using support::copy;
|
||||
using support::DocFileName;
|
||||
using support::FileName;
|
||||
using support::FileNameList;
|
||||
using support::findtexfile;
|
||||
using support::isValidLaTeXFilename;
|
||||
using support::latex_path;
|
||||
@ -333,12 +335,12 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
|
||||
}
|
||||
|
||||
|
||||
vector<FileName> const InsetBibtex::getFiles(Buffer const & buffer) const
|
||||
FileNameList const InsetBibtex::getFiles(Buffer const & buffer) const
|
||||
{
|
||||
FileName path(buffer.filePath());
|
||||
support::PathChanger p(path);
|
||||
|
||||
vector<FileName> vec;
|
||||
FileNameList vec;
|
||||
|
||||
string tmp;
|
||||
// FIXME UNICODE
|
||||
@ -601,7 +603,7 @@ namespace {
|
||||
void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
|
||||
BiblioInfo & keylist, InsetIterator const & /*di*/) const
|
||||
{
|
||||
vector<FileName> const files = getFiles(buffer);
|
||||
FileNameList const files = getFiles(buffer);
|
||||
for (vector<FileName>::const_iterator it = files.begin();
|
||||
it != files.end(); ++ it) {
|
||||
// This bibtex parser is a first step to parse bibtex files
|
||||
|
@ -16,11 +16,13 @@
|
||||
#include "InsetCommand.h"
|
||||
#include "BiblioInfo.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace support {
|
||||
class FileNameList;
|
||||
}
|
||||
|
||||
|
||||
/** Used to insert BibTeX's information
|
||||
*/
|
||||
class InsetBibtex : public InsetCommand {
|
||||
@ -41,7 +43,7 @@ public:
|
||||
virtual void fillWithBibKeys(Buffer const &,
|
||||
BiblioInfo &, InsetIterator const &) const;
|
||||
///
|
||||
std::vector<support::FileName> const getFiles(Buffer const &) const;
|
||||
support::FileNameList const getFiles(Buffer const &) const;
|
||||
///
|
||||
bool addDatabase(std::string const &);
|
||||
///
|
||||
|
@ -22,13 +22,17 @@
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/docstream.h"
|
||||
#include "support/FileNameList.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::FileName;
|
||||
using support::FileNameList;
|
||||
using support::getStringFromVector;
|
||||
using support::getVectorFromString;
|
||||
using support::ltrim;
|
||||
@ -37,9 +41,6 @@ using support::rtrim;
|
||||
using support::split;
|
||||
using support::tokenPos;
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace {
|
||||
|
||||
vector<string> const init_possible_cite_commands()
|
||||
@ -152,10 +153,10 @@ docstring const getNatbibLabel(Buffer const & buffer,
|
||||
|
||||
BiblioInfo biblist;
|
||||
|
||||
vector<FileName> const & bibfilesCache = buffer.getBibfilesCache();
|
||||
FileNameList const & bibfilesCache = buffer.getBibfilesCache();
|
||||
// compare the cached timestamps with the actual ones.
|
||||
bool changed = false;
|
||||
for (vector<FileName>::const_iterator it = bibfilesCache.begin();
|
||||
for (FileNameList::const_iterator it = bibfilesCache.begin();
|
||||
it != bibfilesCache.end(); ++ it) {
|
||||
FileName const f = *it;
|
||||
std::time_t lastw = f.lastModified();
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "insets/InsetListingsParams.h"
|
||||
|
||||
#include "support/docstream.h"
|
||||
#include "support/FileNameList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h" // contains
|
||||
#include "support/lyxalgo.h"
|
||||
@ -63,6 +64,7 @@ using support::contains;
|
||||
using support::copy;
|
||||
using support::DocFileName;
|
||||
using support::FileName;
|
||||
using support::FileNameList;
|
||||
using support::getVectorFromString;
|
||||
using support::isLyXFilename;
|
||||
using support::isValidLaTeXFilename;
|
||||
@ -726,17 +728,17 @@ void InsetInclude::updateBibfilesCache(Buffer const & buffer)
|
||||
}
|
||||
|
||||
|
||||
std::vector<FileName> const &
|
||||
FileNameList const &
|
||||
InsetInclude::getBibfilesCache(Buffer const & buffer) const
|
||||
{
|
||||
Buffer * const tmp = getChildBuffer(buffer, params());
|
||||
if (tmp) {
|
||||
tmp->setParent(0);
|
||||
std::vector<FileName> const & cache = tmp->getBibfilesCache();
|
||||
FileNameList const & cache = tmp->getBibfilesCache();
|
||||
tmp->setParent(&buffer);
|
||||
return cache;
|
||||
}
|
||||
static std::vector<FileName> const empty;
|
||||
static FileNameList const empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include "Counters.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
namespace lyx {
|
||||
@ -32,6 +30,9 @@ class Dimension;
|
||||
class LaTeXFeatures;
|
||||
class RenderMonitoredPreview;
|
||||
|
||||
namespace support {
|
||||
class FileNameList;
|
||||
}
|
||||
|
||||
/// for including tex/lyx files
|
||||
class InsetInclude : public InsetCommand {
|
||||
@ -73,7 +74,7 @@ public:
|
||||
* Return an empty vector if the child doc is not loaded.
|
||||
* \param buffer the Buffer containing this inset.
|
||||
*/
|
||||
std::vector<support::FileName> const &
|
||||
support::FileNameList const &
|
||||
getBibfilesCache(Buffer const & buffer) const;
|
||||
///
|
||||
EDITABLE editable() const { return IS_EDITABLE; }
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "support/FileName.h"
|
||||
#include "support/FileNameList.h"
|
||||
|
||||
#include "support/debug.h"
|
||||
#include "support/filetools.h"
|
||||
@ -230,6 +231,39 @@ bool FileName::isDirWritable() const
|
||||
}
|
||||
|
||||
|
||||
FileNameList FileName::dirList(std::string const & ext) const
|
||||
{
|
||||
FileNameList dirlist;
|
||||
if (!isDirectory()) {
|
||||
LYXERR0("Directory '" << *this << "' does not exist!");
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
QDir dir = d->fi.absoluteDir();
|
||||
|
||||
if (!ext.empty()) {
|
||||
QString filter;
|
||||
switch (ext[0]) {
|
||||
case '.': filter = "*" + toqstr(ext); break;
|
||||
case '*': filter = toqstr(ext); break;
|
||||
default: filter = "*." + toqstr(ext);
|
||||
}
|
||||
dir.setNameFilters(QStringList(filter));
|
||||
LYXERR(Debug::FILES, "filtering on extension "
|
||||
<< fromqstr(filter) << " is requested.");
|
||||
}
|
||||
|
||||
QFileInfoList list = dir.entryInfoList();
|
||||
for (int i = 0; i != list.size(); ++i) {
|
||||
FileName fi(fromqstr(list.at(i).absoluteFilePath()));
|
||||
dirlist.push_back(fi);
|
||||
LYXERR(Debug::FILES, "found file " << fi);
|
||||
}
|
||||
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
|
||||
FileName FileName::tempName(FileName const & dir, std::string const & mask)
|
||||
{
|
||||
return support::tempName(dir, mask);
|
||||
|
@ -20,6 +20,9 @@
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/// Defined in "FileNameList.h".
|
||||
class FileNameList;
|
||||
|
||||
/**
|
||||
* Class for storing file names.
|
||||
* The file name may be empty. If it is not empty it is an absolute path.
|
||||
@ -82,6 +85,8 @@ public:
|
||||
bool isWritable() const;
|
||||
/// return true when file/directory is writable (write test file)
|
||||
bool isDirWritable() const;
|
||||
/// \return list other files in the directory having optional extension 'ext'.
|
||||
FileNameList dirList(std::string const & ext) const;
|
||||
|
||||
/// copy a file
|
||||
/// \return true when file/directory is writable (write test file)
|
||||
@ -226,7 +231,6 @@ private:
|
||||
bool operator==(DocFileName const &, DocFileName const &);
|
||||
bool operator!=(DocFileName const &, DocFileName const &);
|
||||
|
||||
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
||||
|
34
src/support/FileNameList.h
Normal file
34
src/support/FileNameList.h
Normal file
@ -0,0 +1,34 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file FileNameList.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef FILENAMELIST_H
|
||||
#define FILENAMELIST_H
|
||||
|
||||
#include "support/FileName.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/**
|
||||
* Class for storing file name list.
|
||||
* std::vector can not be forward declared in a simple way. Creating a class solves
|
||||
* this problem.
|
||||
*/
|
||||
class FileNameList: public std::vector<FileName>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
||||
#endif // FILENAMELIST_H
|
@ -19,16 +19,6 @@
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
||||
namespace lyx {
|
||||
namespace support {
|
||||
|
||||
/// \return list other files in the directory having optional extension 'ext'.
|
||||
std::vector<FileName> dirList(FileName const & filename, std::string const & ext);
|
||||
|
||||
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
||||
/// The following functions are implemented in minizip/zipunzip.cpp, and are not in
|
||||
/// the lyx::support namespace
|
||||
|
||||
|
@ -938,38 +938,5 @@ int compare_timestamps(FileName const & file1, FileName const & file2)
|
||||
}
|
||||
|
||||
|
||||
std::vector<FileName> dirList(FileName const & filename, std::string const & ext)
|
||||
{
|
||||
std::vector<FileName> dirlist;
|
||||
if (!filename.isDirectory()) {
|
||||
LYXERR0("Directory '" << filename << "' does not exist!");
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
QDir dir(toqstr(filename.absoluteFilePath()));
|
||||
|
||||
if (!ext.empty()) {
|
||||
QString filter;
|
||||
switch (ext[0]) {
|
||||
case '.': filter = "*" + toqstr(ext); break;
|
||||
case '*': filter = toqstr(ext); break;
|
||||
default: filter = "*." + toqstr(ext);
|
||||
}
|
||||
dir.setNameFilters(QStringList(filter));
|
||||
LYXERR(Debug::FILES, "filtering on extension "
|
||||
<< fromqstr(filter) << " is requested.");
|
||||
}
|
||||
|
||||
QFileInfoList list = dir.entryInfoList();
|
||||
for (int i = 0; i != list.size(); ++i) {
|
||||
FileName fi(fromqstr(list.at(i).absoluteFilePath()));
|
||||
dirlist.push_back(fi);
|
||||
LYXERR(Debug::FILES, "found file " << fi);
|
||||
}
|
||||
|
||||
return dirlist;
|
||||
}
|
||||
|
||||
|
||||
} //namespace support
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user